/** PriceChannel-LowHigh.mq4 Copyright © 2008, Balidev.com. Developed by Balidev.com Software Development http://www.balidev.com PriceChannel-LowHigh: The PriceChannel-LowHigh indicator is a simple indicator showing the lowest/highest value for a certain period. Using this approach this indicator will construct an envlope base on low/max value for certain period. The famous Turtle Trading System uses this simple indicator. Revision History v.0.1 2008-01-03 Yogi Triana - Initial Coding **/ #property copyright "PriceChannel-LowHigh Copyright © 2008, Balidev.com Software Development." #property link "http://www.balidev.com" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Yellow #property indicator_color2 Magenta //---- indicator parameters extern int ChannelPeriod = 14; extern int ChannelShift = 0; //---- buffers double UpperBuffer[]; double LowerBuffer[]; int init() { //---- indicators SetIndexStyle(0, DRAW_LINE, STYLE_DOT); SetIndexBuffer(0, UpperBuffer); SetIndexStyle(1, DRAW_LINE, STYLE_DOT); SetIndexBuffer(1, LowerBuffer); //---- SetIndexDrawBegin(0, ChannelPeriod + ChannelShift); SetIndexDrawBegin(1, ChannelPeriod + ChannelShift); //---- return(0); } int start() { int i, k, counted_bars = IndicatorCounted(); double highChannel; double lowChannel; if( Bars <= ChannelPeriod ) { // in case the is not enough bar for calculation, just return return(0); } if(counted_bars < 1) { for( i = 1; i <= ChannelPeriod; i++) { UpperBuffer[Bars-i] = EMPTY_VALUE; LowerBuffer[Bars-i] = EMPTY_VALUE; } } int limit = Bars - counted_bars; if (counted_bars > 0) { limit++; } int start = Bars - ChannelPeriod + 1; for(i = start; i >= 0; i--) { int startShifted = i + ChannelShift; lowChannel = Low[startShifted]; highChannel = High[startShifted]; for (k = 0 ; k <= ChannelPeriod; k++) { int shiftedCalc = startShifted + k; if (Low[shiftedCalc] < lowChannel) { lowChannel = Low[shiftedCalc]; } if (High[shiftedCalc] > highChannel) { highChannel = High[shiftedCalc]; } } UpperBuffer[i] = highChannel; LowerBuffer[i] = lowChannel; } return(0); }