//+------------------------------------------------------------------+ //| LeManTrend Indicator.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_separate_window #property indicator_buffers 2 #property indicator_plots 2 //--- plot Buy #property indicator_label1 "Buy" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Sell #property indicator_label2 "Sell" #property indicator_type2 DRAW_LINE #property indicator_color2 clrLime #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- input parameters input int Min = 13; // LeManTrend: Min input int Midle = 21; // LeManTrend: Midle input int Max = 34; // LeManTrend: Max input int PeriodEMA = 3; // LeManTrend: MA averaging period //--- indicator buffers double BuyBuffer[]; double SellBuffer[]; //--- int m_min_bars=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- check "MA averaging period" parameter if(PeriodEMA<1) { string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")? "Параметр \"MA averaging period\" меньше 1!": "Parameter \"MA averaging period\" is less than 1!"; //--- when testing, we will only output to the log about incorrect input parameters if(MQLInfoInteger(MQL_TESTER)) { Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_FAILED); } else // if the Expert Advisor is run on the chart, tell the user about the error { Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_PARAMETERS_INCORRECT); } } //--- check "Min" parameter if(Min<1) { string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")? "Параметр \"Min\" меньше 1!": "Parameter \"Min\" is less than 1!"; //--- when testing, we will only output to the log about incorrect input parameters if(MQLInfoInteger(MQL_TESTER)) { Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_FAILED); } else // if the Expert Advisor is run on the chart, tell the user about the error { Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_PARAMETERS_INCORRECT); } } //--- check "Midle" parameter if(Midle<1) { string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")? "Параметр \"Midle\" меньше 1!": "Parameter \"Midle\" is less than 1!"; //--- when testing, we will only output to the log about incorrect input parameters if(MQLInfoInteger(MQL_TESTER)) { Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_FAILED); } else // if the Expert Advisor is run on the chart, tell the user about the error { Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_PARAMETERS_INCORRECT); } } //--- check "Max" parameter if(Max<1) { string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")? "Параметр \"Max\" меньше 1!": "Parameter \"Max\" is less than 1!"; //--- when testing, we will only output to the log about incorrect input parameters if(MQLInfoInteger(MQL_TESTER)) { Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_FAILED); } else // if the Expert Advisor is run on the chart, tell the user about the error { Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_PARAMETERS_INCORRECT); } } //--- if(Min>=Midle) { string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")? "Параметр \"Min\" >= \"Midle\"!": "Parameter \"Min\" >= \"Midle\"!"; //--- when testing, we will only output to the log about incorrect input parameters if(MQLInfoInteger(MQL_TESTER)) { Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_FAILED); } else // if the Expert Advisor is run on the chart, tell the user about the error { Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_PARAMETERS_INCORRECT); } } if(Midle>=Max) { string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")? "Параметр \"Midle\" >= \"Max\"!": "Parameter \"Midle\" >= \"Max\"!"; //--- when testing, we will only output to the log about incorrect input parameters if(MQLInfoInteger(MQL_TESTER)) { Print(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_FAILED); } else // if the Expert Advisor is run on the chart, tell the user about the error { Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text); return(INIT_PARAMETERS_INCORRECT); } } //--- indicator buffers mapping SetIndexBuffer(0,BuyBuffer,INDICATOR_DATA); SetIndexBuffer(1,SellBuffer,INDICATOR_DATA); ArraySetAsSeries(BuyBuffer,true); ArraySetAsSeries(SellBuffer,true); //--- an empty value PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); //--- set accuracy IndicatorSetInteger(INDICATOR_DIGITS,Digits()); //--- m_min_bars=0; if(Min>m_min_bars) m_min_bars=Min; if(Midle>m_min_bars) m_min_bars=Midle; if(Max>m_min_bars) m_min_bars=Max; if(PeriodEMA>m_min_bars) m_min_bars=PeriodEMA; //--- sets first bar from what index will be drawn PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,m_min_bars); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,m_min_bars); //--- 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[]) { //--- if(rates_total=0 && !IsStopped(); i--) { double High1=high[ArrayMaximum(high,i+1,Min)]; double High2=high[ArrayMaximum(high,i+1,Midle)]; double High3=high[ArrayMaximum(high,i+1,Max)]; double HH=((high[i]-High1)+(high[i]-High2)+(high[i]-High3)); double Low1=low[ArrayMinimum(low,i+1,Min)]; double Low2=low[ArrayMinimum(low,i+1,Midle)]; double Low3=low[ArrayMinimum(low,i+1,Max)]; double LL=((Low1-low[i])+(Low2-low[i])+(Low3-low[i])); BuyBuffer[i]=LL; SellBuffer[i]=HH; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+