//+------------------------------------------------------------------+ //| Turtle Channel.mq5 | //| Copyright © 2019, Vladimir Karputov | //| http://wmua.ru/slesar/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2019, Vladimir Karputov" #property link "http://wmua.ru/slesar/" #property version "1.000" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 2 //--- plot Upper #property indicator_label1 "Upper" #property indicator_type1 DRAW_LINE #property indicator_color1 clrLawnGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 2 //--- plot Lower #property indicator_label2 "Lower" #property indicator_type2 DRAW_LINE #property indicator_color2 clrDarkGreen #property indicator_style2 STYLE_SOLID #property indicator_width2 2 //--- input parameters input int Inp_Upper_ma_period=20; // Upper band averaging period input int Inp_Lower_ma_period=10; // Lower band averaging period //--- indicator buffers double ExtUpperBuffer[]; double ExtLowerBuffer[]; //--- int ExtBiggest; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ExtUpperBuffer,INDICATOR_DATA); SetIndexBuffer(1,ExtLowerBuffer,INDICATOR_DATA); //--- if(Inp_Upper_ma_period<=0) { string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")? "Параметр \"Upper band averaging period\" не может быть меньше или равен нулю!": "The parameter \"Upper band averaging period\" can not be less than or equal to zero!"; //--- when testing, we will only output to the log about incorrect input parameters if(MQLInfoInteger(MQL_TESTER)) { Print(__FUNCTION__,", ERROR: ",err_text); return(INIT_FAILED); } else // if the Expert Advisor is run on the chart, tell the user about the error { Alert(__FUNCTION__,", ERROR: ",err_text); return(INIT_PARAMETERS_INCORRECT); } } if(Inp_Lower_ma_period<=0) { string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")? "Параметр \"Lower band averaging period\" не может быть меньше или равен нулю!": "The parameter \"Lower band averaging period\" can not be less than or equal to zero!"; //--- when testing, we will only output to the log about incorrect input parameters if(MQLInfoInteger(MQL_TESTER)) { Print(__FUNCTION__,", ERROR: ",err_text); return(INIT_FAILED); } else // if the Expert Advisor is run on the chart, tell the user about the error { Alert(__FUNCTION__,", ERROR: ",err_text); return(INIT_PARAMETERS_INCORRECT); } } if(Inp_Upper_ma_period>Inp_Lower_ma_period) ExtBiggest=Inp_Upper_ma_period; else ExtBiggest=Inp_Lower_ma_period; //--- indicator digits IndicatorSetInteger(INDICATOR_DIGITS,Digits()); //--- sets first bar from what index will be drawn PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBiggest+1); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBiggest+1); //--- PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); //--- name for Dindicator subwindow label IndicatorSetString(INDICATOR_SHORTNAME,"Turtle Channel("+ IntegerToString(Inp_Upper_ma_period)+","+IntegerToString(Inp_Lower_ma_period)+")"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- check for data if(rates_totalmax) max=high[j]; } if(max==DBL_MIN) ExtUpperBuffer[i]=0.0; else ExtUpperBuffer[i]=max; //--- recursion for(int j=i-Inp_Lower_ma_period;j<=i;j++) { if(j<0) { ExtLowerBuffer[i]=0.0; continue; } //--- search for minimum prices if(low[j]