//+------------------------------------------------------------------+
//|                                                  TenCandleMA.mq4 |
//|                                                      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;
 extern int                BARCOUNT        = 10;

//--- indicator buffers
double         MABuffer[];
#include <Indicators\Trend.mqh>

CiMA g_ma;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,MABuffer);
   
   if(!g_ma.Create(_Symbol, (ENUM_TIMEFRAMES)_Period,inpMaPeriod, 0, inpMaMethod, inpAppliedPrice))
      return INIT_FAILED;
   
//---
   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)
      for(int i=0;i<limit+10;i++)
         MABuffer[i] = EMPTY_VALUE;
   for(int i=0; i< limit; i++)
      MABuffer[i] = g_ma.Main(i);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


 //+------------------------------------------------------------------
   int deinit() {
      ObjectDelete("MA");
      
      
      
          return (0);
   }