calculate new bars dates in my indicator

 
hi guys why this happening in my indicator? i m new, itried to copy some examples from macd, it works for previous times correctly, but see the pic i tagged please!
#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[])
               
                
  {
    
   int i,limit;
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;
//--- macd counted in the 1-st buffer
   for(i=0; i<limit; i++)
     if(iVolume(Symbol(),0,i)-iVolume(Symbol(),0,i+1)!=0)
       {
          ExtNesbatBuffer[i]=fabs(iClose(Symbol(),0,i)-iOpen(Symbol(),0,i))/(iVolume(Symbol(),0,i)-iVolume(Symbol(),0,i+1));
           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;
             }
       }
       
//--- return value of prev_calculated for next call
   return(rates_total);
  }
Files:
indicator.jpg  76 kb
 
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 251);
The value of ExtNesbatBuffer is so small that it looks like a dotted line on the screen.
 
Nagisa Unada:
The value of ExtNesbatBuffer is so small that it looks like a dotted line on the screen.

thanks, its ok, but now i test the program in tester it work but it dont work in demo acount , why?

 
ejmin ejoni:

thanks, its ok, but now i test the program in tester it work but it dont work in demo acount , why?

I don't know. I have confirmed that it works fine on my real account.

p.s.

You should add the following, because you may get an "array out of range" error.

if(prev_calculated == 0)
   limit = rates_total - 2;
 

Why are you using 'iOpen', 'iClose' ...? After all, you ALREADY have this data - OnCalculate gives you all this data.

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[])
 
Nagisa Unada:

I don't know. I have confirmed that it works fine on my real account.

p.s.

You should add the following, because you may get an "array out of range" error.

it works for before run candles,i mean it works because Forex closed
 

Code:

//+------------------------------------------------------------------+
//|                                                  Indicator 1.mq5 |
//|                              Copyright © 2021, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2021, Vladimir Karputov"
#property version   "1.000"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
//#property indicator_minimum -0.2
//#property indicator_maximum 0.2
//--- plot Nesbat
#property indicator_label1  "Nesbat"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  clrSilver
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Tanasob
#property indicator_label2  "Tanasob"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters
input int      Input1=9;
//--- indicator buffers
double   NesbatBuffer[];
double   TanasobBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,NesbatBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,TanasobBuffer,INDICATOR_DATA);
//--- define the symbol code for drawing in PLOT_ARROW
   PlotIndexSetInteger(1,PLOT_ARROW,159);
//--- set the vertical shift of arrows in pixels
   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,5);
//--- set as an empty value 0
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//---
   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[])
  {
   if(rates_total<10)
      return(0);
//---
   int limit=prev_calculated-1;
   if(prev_calculated==0)
     {
      NesbatBuffer[0]=0.0;
      TanasobBuffer[0]=EMPTY_VALUE;
      limit=1;
     }
   for(int i=limit; i<rates_total; i++)
     {
      NesbatBuffer[i]=0.0;
      TanasobBuffer[i]=EMPTY_VALUE;
      if(tick_volume[i]-tick_volume[i-1]!=0.0)
        {
         //--- historgamm
         double fabs_temp=MathAbs(close[i]-open[i])/(tick_volume[i]-tick_volume[i-1]);
         if(fabs_temp>0.2)
            NesbatBuffer[i]=0.2;
         else
            if(fabs_temp<-0.2)
               NesbatBuffer[i]=-0.2;
         //--- arrow
         double tick_temp=(tick_volume[i]/tick_volume[i-1]-1.0)/3.0;
         if(tick_temp>0.2)
            TanasobBuffer[i]=0.2;
         else
            if(tick_temp<-0.2)
               TanasobBuffer[i]=-0.2;
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
 
Nagisa Unada:

I don't know. I have confirmed that it works fine on my real account.

p.s.

You should add the following, because you may get an "array out of range" error.

it seems rate_total don't increase in after run candles
 
Vladimir Karputov:

Code:

thanks but it didnt work

 
ejmin ejoni:
it seems rate_total don't increase in after run candles

What does that mean?

 
ejmin ejoni :

thanks but it didnt work

What do you mean "it doesn't work"? Please describe the exact problem.