//+------------------------------------------------------------------+ //| Custom Moving Average.mq5 | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2000-2025, MetaQuotes Ltd." #property link "https://www.mql5.com" //--- indicator settings #property indicator_chart_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed //--- input parameters input int InpMAPeriod=13; // Period input int InpMAShift=0; // Shift input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Method //--- indicator buffer double ExtLineBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA); //--- set accuracy IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //--- set first bar from what index will be drawn PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod); //--- line shifts when drawing PlotIndexSetInteger(0,PLOT_SHIFT,InpMAShift); //--- name for DataWindow string short_name; switch(InpMAMethod) { case MODE_EMA : short_name="EMA"; break; case MODE_LWMA : short_name="LWMA"; break; case MODE_SMA : short_name="SMA"; break; case MODE_SMMA : short_name="SMMA"; break; default : short_name="unknown ma"; } IndicatorSetString(INDICATOR_SHORTNAME,short_name+"("+string(InpMAPeriod)+")"); //--- set drawing line empty value PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); } //+------------------------------------------------------------------+ //| Moving Average | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { if(rates_total