//+------------------------------------------------------------------+ #property copyright "2012, mql5" #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 4 #property indicator_label1 "UP" #property indicator_type1 DRAW_ARROW #property indicator_color1 clrAqua #property indicator_style1 STYLE_SOLID #property indicator_width1 1 #property indicator_label2 "DN" #property indicator_type2 DRAW_ARROW #property indicator_color2 clrDeepPink #property indicator_style2 STYLE_SOLID #property indicator_width2 1 #property indicator_type3 DRAW_LINE #property indicator_color3 Red #property indicator_type4 DRAW_LINE #property indicator_color4 Blue //------------------------------------ input bool Alerts = true; input int MA2FastPeriod = 1; /*MA2FastPeriod*/ // Период быстрой MA, период 1 - это просто цена как есть input ENUM_MA_METHOD MA2FastMethod = MODE_SMA; /*MA2FastMethod*/ // Метод быстрой MA input ENUM_APPLIED_PRICE MA2FastPrice = PRICE_CLOSE; /*MA2FastPrice*/ // Цена быстрой MA input int MA2SlowPeriod = 33; /*MA2SlowPeriod*/ // Период медленной MA input ENUM_MA_METHOD MA2SlowMethod = MODE_SMA; /*MA2SlowMethod*/ // Метод медленной MA input ENUM_APPLIED_PRICE MA2SlowPrice = PRICE_CLOSE; /*MA2SlowPrice*/ // Цена медленной MA //--- indicator buffers double MA2FastBuf[]; double MA2SlowBuf[]; double BuyBuf[]; double SellBuf[]; int MA2FastHand; int MA2SlowHand; //------------------------------------ int g_i_Window; int OnInit() // Специальная функция init() { g_i_Window=ChartWindowFind(); SetIndexBuffer(0,BuyBuf,INDICATOR_DATA); SetIndexBuffer(1,SellBuf,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_ARROW,233); PlotIndexSetInteger(1,PLOT_ARROW,234); PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,10); PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-10); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0); SetIndexBuffer(2,MA2FastBuf,INDICATOR_DATA); SetIndexBuffer(3,MA2SlowBuf,INDICATOR_DATA); MA2FastHand=iMA(NULL,PERIOD_CURRENT,MA2FastPeriod,0,MA2FastMethod,MA2FastPrice); MA2SlowHand=iMA(NULL,PERIOD_CURRENT,MA2SlowPeriod,0,MA2SlowMethod,MA2SlowPrice); if(MA2FastHand==INVALID_HANDLE || MA2SlowHand==INVALID_HANDLE){ Alert("Неудалось загрузить индикатор, повторите попытку"); return(-1); } return(0); } //-------------------------------------------------------------------- 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[]) { int i; static int st_i_FlagUpDown = 0; //-------------------------------------------------------------------- i = (prev_calculated==0)?1: prev_calculated; i = (prev_calculated==rates_total)?rates_total-1: i; if(CopyBuffer(MA2FastHand,0,0,rates_total-i,MA2FastBuf)==-1 || CopyBuffer(MA2SlowHand,0,0,rates_total-i,MA2SlowBuf)==-1){ return(0); } for (i = i; i < rates_total; i++){ BuyBuf[i]=0; SellBuf[i]=0; if(MA2FastBuf[i]>MA2SlowBuf[i] && MA2FastBuf[i-1]<=MA2SlowBuf[i-1]){ BuyBuf[i]=low[i]; } if(MA2FastBuf[i]=MA2SlowBuf[i-1]){ SellBuf[i]=high[i]; } } if (Alerts == true && prev_calculated > 0){ if (BuyBuf[i-1] != 0 && st_i_FlagUpDown != 1){ st_i_FlagUpDown = 1; Alert(MQL5InfoString(MQL5_PROGRAM_NAME)+"("+_Symbol+","+fNameTimeFrame(Period())+"): UP"); } if (SellBuf[i-1] != 0 && st_i_FlagUpDown != -1){ st_i_FlagUpDown = -1; Alert(MQL5InfoString(MQL5_PROGRAM_NAME)+"("+_Symbol+","+fNameTimeFrame(Period())+"): DOWN"); } } if (prev_calculated==0) ChartRedraw(); return(rates_total); } //------------------------------------------------------------------- string fNameTimeFrame(ENUM_TIMEFRAMES arg){ if(arg==0 || arg==PERIOD_CURRENT){ arg=Period(); } switch(arg){ case PERIOD_M1:return("M1"); case PERIOD_M2:return("M2"); case PERIOD_M3:return("M3"); case PERIOD_M4:return("M4"); case PERIOD_M5:return("M5"); case PERIOD_M6:return("M6"); case PERIOD_M10:return("M10"); case PERIOD_M12:return("M12"); case PERIOD_M15:return("M15"); case PERIOD_M20:return("M20"); case PERIOD_M30:return("M30"); case PERIOD_H1:return("H1"); case PERIOD_H2:return("H2"); case PERIOD_H3:return("H3"); case PERIOD_H4:return("H4"); case PERIOD_H6:return("H6"); case PERIOD_H8:return("H8"); case PERIOD_H12:return("H12"); case PERIOD_D1:return("D1"); case PERIOD_W1:return("W1"); case PERIOD_MN1:return("MN1"); default:return("M"+IntegerToString(arg)); } } //-------------------------------------------------------------------