//+------------------------------------------------------------------+
//|                                                  TenCandleMA.mq5 |
//|                                                      nicholishen |
//|                         https://www.forexfactory.com/nicholishen |
//+------------------------------------------------------------------+
#property copyright "nicholishen"
#property link      "https://www.forexfactory.com/nicholishen"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot MA
#property indicator_label1  "MA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int                  inpMaPeriod     = 13;
input ENUM_MA_METHOD       inpMaMethod     = MODE_EMA;
input ENUM_APPLIED_PRICE   inpAppliedPrice = PRICE_TYPICAL;
int                  BARCOUNT        = 10;

//--- indicator buffers
double         MABuffer[];
int            MAHndl;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,MABuffer,INDICATOR_DATA);
   ArraySetAsSeries(MABuffer,true);
   MAHndl=iMA(_Symbol, (ENUM_TIMEFRAMES)_Period,inpMaPeriod, 0, inpMaMethod, inpAppliedPrice);
   PlotIndexSetInteger(0,0,PLOT_DRAW_BEGIN,inpMaPeriod);
   
//---
   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[])
  {
//---
   int limit = rates_total == prev_calculated ? 1 : BARCOUNT;
   if(limit > 1)
   CopyBuffer(MAHndl,0,0,10,MABuffer);
      for(int i=10;i<Bars(_Symbol,PERIOD_CURRENT);i++)
         MABuffer[i] = EMPTY_VALUE;
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+