why indicator not draw till the end ?

 

Hi guys  i have this script , but  why with iMAOnArray not  create a chart till the end ? thankz

//+------------------------------------------------------------------+
//|                                                                  |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright " "
#property link      " "
#property version   "1.00"
#property strict
#property indicator_separate_window
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1  Green

//--- input parameter
input int InpDivPeriod=3;
extern int PeriodEMA_1=1500;
extern int PeriodEMA_2=2;
extern int PeriodEMA_3=2;
//--- buffers

double MAGradBuff[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {

//--- indicator buffers mapping
   IndicatorBuffers(1);
   IndicatorDigits(Digits);
//---indicator line

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MAGradBuff);
//--- name for data window and indicator subwindow label

   IndicatorShortName(" ");
   SetIndexLabel(0," ");
//--- check for input parameters
   if(InpDivPeriod<=1)
     {
      Print("Wrong input parameters DIV Period=",InpDivPeriod);
      return(INIT_FAILED);
     }
//---
   SetIndexDrawBegin(0,InpDivPeriod);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Divergence                             |
//+------------------------------------------------------------------+
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 counted_bars = prev_calculated;
   if(counted_bars < 0)
      return(-1);
   if(counted_bars > 0)
      counted_bars--;
   int limit=MathMin(rates_total-counted_bars,rates_total-1);
   for(int i=limit; i>=0; i--)
     {
      // double Diffn=;
      double aDiffn[1];
      ArrayResize(aDiffn,limit+1);
      aDiffn[i]=Close[i]-Open[i];
      double PrimaEMAn= iMAOnArray(aDiffn,0,PeriodEMA_1,0,MODE_SMMA,i);
      //  double SecondaEMAn=iMA(NULL,0,PeriodEMA_2,0,MODE_SMA,PrimaEMAn,i);


      MAGradBuff[i]=PrimaEMAn;

     }



   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
Untitled.jpg  486 kb
 
faustf:

Hi guys  i have this script , but  why with iMAOnArray not  create a chart till the end ? thankz

It actually draws but EMA with period 500 returns 0 value since it has no value in the first 500 bars because of its period

 

but in practice to have the same effect as iMA I have to rewrite the class, I fold better:

I want that when I go back I can still see the graph, for example if I go behind 100 candles, candle 1 will be 100 and 1500 will recalculate it from as iMA does, with iMAonArray it can't be done (because period in my case 1500 is border)so if i use iMA i can't just pass a double number , because Price_close or price_open are enumerator and not mix  Price_close-Price_open , right? therefore i must rewrite a class , i understund good ?


thanks

Reason: