#property copyright "Copyright © 2013, Johannes Hermann" //---- indicator version number #property version "2.00" //---- drawing the indicator in the main window #property indicator_chart_window //---- number of indicator buffers #property indicator_buffers 3 //---- 3 plots are used #property indicator_plots 3 //+-----------------------------------+ //| parameters of indicator drawing | //+-----------------------------------+ //---- drawing of the indicator as a line #property indicator_type1 DRAW_LINE //---- use olive color for the indicator line #property indicator_color1 Yellow //---- indicator line is a solid curve #property indicator_style1 STYLE_SOLID //---- indicator line width is equal to 1 #property indicator_width1 2 //---- indicator label display #property indicator_label1 "Upper Donchian" //---- drawing of the indicator as a line #property indicator_type3 DRAW_LINE //---- use pale violet red color for the indicator line #property indicator_color3 Yellow //---- indicator line is a solid curve #property indicator_style3 STYLE_SOLID //---- indicator line width is equal to 1 #property indicator_width3 2 //---- indicator label display #property indicator_label3 "Lower Donchian" //+-----------------------------------+ //| Enumeration declaration | //+-----------------------------------+ enum Applied_Extrem //Type of extreme points { HIGH_LOW, HIGH_LOW_OPEN, HIGH_LOW_CLOSE, OPEN_HIGH_LOW, CLOSE_HIGH_LOW }; //+-----------------------------------+ //| INPUT PARAMETERS OF THE INDICATOR| //+-----------------------------------+ input int DonchianPeriod=20; //Period of averaging input Applied_Extrem Extremes=HIGH_LOW; //Type of extreme points input int Margins=-2; input int Shift=0; //Horizontal shift of the indicator in bars //+-----------------------------------+ //---- indicator buffers double UpperBuffer[]; double LowerBuffer[]; //+------------------------------------------------------------------+ //| searching index of the highest bar | //+------------------------------------------------------------------+ int iHighest(const double &array[], // array for searching for maximum element index int count, // the number of the array elements (from current bar to the index descending), along which the searching must be performed. int startPos) // the initial bar index (shift relative to a current bar), the search for the greatest value begins from { //---- int index=startPos; //----checking correctness of the initial index if(startPos<0) { Print("Bad value in the function iHighest, startPos = ",startPos); return(0); } //---- checking correctness of startPos value if(startPos-count<0) count=startPos; double max=array[startPos]; //---- searching for an index for(int i=startPos; i>startPos-count; i--) { if(array[i]>max) { index=i; max=array[i]; } } //---- returning of the greatest bar index return(index); } //+------------------------------------------------------------------+ //| searching index of the lowest bar | //+------------------------------------------------------------------+ int iLowest(const double &array[], // array for searching for minimum element index int count, // the number of the array elements (from current bar to the index descending), along which the searching must be performed. int startPos) // the initial bar index (shift relative to a current bar), the search for the lowest value begins from { //---- int index=startPos; //----checking correctness of the initial index if(startPos<0) { Print("Bad value in the function iLowest, startPos = ",startPos); return(0); } //---- checking correctness of startPos value if(startPos-count<0) count=startPos; double min=array[startPos]; //---- searching for an index for(int i=startPos; i>startPos-count; i--) { if(array[i]