calculate new bars dates in my indicator - page 2

 
  1. In MT4, buffers and the predefined arrays are all ordered AsSeries. There is a difference between the arrays passed to OnCalculate (e.g. low[]) and the MT4 predefined variables (e.g. Low[].) The passed arrays have no default direction, just like MT5.

  2. In MT5, you must set the direction.

    To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
              Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
 

i find it guys thanks

#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_minimum    -0.2
#property indicator_maximum    0.2
#property indicator_buffers 2
#property indicator_width1  2
#property indicator_color1  Silver
#property indicator_color2  Red
#property indicator_level1    -0.03
#property indicator_level2     0.03
#property indicator_levelcolor clrRosyBrown
#property indicator_levelstyle STYLE_DASH
 double    ExtNesbatBuffer[];
 double  ExtTanasobBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(0,ExtNesbatBuffer);
    SetIndexBuffer(1,ExtTanasobBuffer);
//---
   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[])
               
                
  {
    //Comment("rotates = "+ IntegerToString(rates_total,0,0) + "prev = "+IntegerToString(prev_calculated,0,0));
   int i,limit;
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated-1;
   if(prev_calculated>0)
    limit=1;
//--- macd counted in the 1-st buffer
   for(i=0; i<limit; i++)
      {
          ExtNesbatBuffer[i]=fabs(iClose(Symbol(),0,i)-iOpen(Symbol(),0,i))*20000/(iVolume(Symbol(),0,i));
           if(ExtNesbatBuffer[i]>0.2)
             {
              ExtNesbatBuffer[i]=0.2;
             }
              if(ExtNesbatBuffer[i]<-0.2)
             {
              ExtNesbatBuffer[i]=-0.2;
             }
          ExtTanasobBuffer[i]=(StringToDouble( IntegerToString(iVolume(Symbol(),0,i)))/StringToDouble( IntegerToString(iVolume(Symbol(),0,i+1)))-1)/3;
             if(ExtTanasobBuffer[i]>0.2)
             {
              ExtTanasobBuffer[i]=0.2;
             }
              if(ExtTanasobBuffer[i]<-0.2)
             {
              ExtTanasobBuffer[i]=-0.2;
             }
       }
       // Comment("rotates = "+ rates_total + "prev = "+prev_calculated);
       
//--- return value of prev_calculated for next call
   return(rates_total);
  }