//+------------------------------------------------------------------+ //| MAEA_Indicator.mq5 | //| Moving Average EA | //| Visual indicator for EMA zone breakout | //+------------------------------------------------------------------+ #property copyright "MAEA" #property link "" #property version "1.00" #property strict #property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 3 #property indicator_label1 "EMA High" #property indicator_type1 DRAW_LINE #property indicator_color1 clrLightBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 2 #property indicator_label2 "EMA Low" #property indicator_type2 DRAW_LINE #property indicator_color2 clrOrange #property indicator_style2 STYLE_SOLID #property indicator_width2 2 #property indicator_label3 "EMA Zone" #property indicator_type3 DRAW_FILLING #property indicator_color3 clrYellow #property indicator_style3 STYLE_SOLID #property indicator_width3 1 input int EMAPeriod = 30; input int EMAShift = 0; int handleEMAHigh; int handleEMALow; double BufferEMAHigh[]; double BufferEMALow[]; double BufferZone[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { ArraySetAsSeries(BufferEMAHigh, true); ArraySetAsSeries(BufferEMALow, true); ArraySetAsSeries(BufferZone, true); SetIndexBuffer(0, BufferEMAHigh, INDICATOR_DATA); SetIndexBuffer(1, BufferEMALow, INDICATOR_DATA); SetIndexBuffer(2, BufferZone, INDICATOR_CALCULATIONS); ArraySetAsSeries(BufferEMAHigh, true); ArraySetAsSeries(BufferEMALow, true); ArraySetAsSeries(BufferZone, true); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, EMAPeriod + EMAShift); PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, EMAPeriod + EMAShift); PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, EMAPeriod + EMAShift); handleEMAHigh = iMA(_Symbol, PERIOD_CURRENT, EMAPeriod, EMAShift, MODE_EMA, PRICE_HIGH); handleEMALow = iMA(_Symbol, PERIOD_CURRENT, EMAPeriod, EMAShift, MODE_EMA, PRICE_LOW); if(handleEMAHigh == INVALID_HANDLE || handleEMALow == INVALID_HANDLE) { Print("Failed to create EMA handles"); return INIT_FAILED; } return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { IndicatorRelease(handleEMAHigh); IndicatorRelease(handleEMALow); } //+------------------------------------------------------------------+ //| 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 < EMAPeriod + EMAShift) return 0; int copied = CopyBuffer(handleEMAHigh, 0, 0, rates_total, BufferEMAHigh); if(copied <= 0) return 0; copied = CopyBuffer(handleEMALow, 0, 0, rates_total, BufferEMALow); if(copied <= 0) return 0; return rates_total; } //+------------------------------------------------------------------+