strangeness using prev_calculated vs prev_calculated-1

To add comments, please log in or register
Giovanni
48
Giovanni  

Here there are the differences between Prev_calculated and Prev_calculated-1 in bars loop

using prev_calculated-1

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[])
  {
  ArraySetAsSeries(time,false);
  ArraySetAsSeries(open,false); 
  ArraySetAsSeries(low,false); 
  ArraySetAsSeries(close,false); 
  ArraySetAsSeries(high,false); 
  ArraySetAsSeries(Segnale,false);
  .........
 for (int i=(int)MathMax(prev_calculated-1,1000); i<=rates_total-1; i++) {
 Print("NEW BAR, total bars=",Bars(NULL,0));
 Print("i=",i);
 ......
 }
return(ratestotal)


and the output:

(EURUSD,M1) NEW BAR, total bars=250129
(EURUSD,M1) i=250127
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
(EURUSD,M1) i=250128
......
(EURUSD,M1) i=250128
(EURUSD,M1) NEW BAR, total bars=250130
(EURUSD,M1) i=250128
(EURUSD,M1) i=250129
(EURUSD,M1) i=250129
(EURUSD,M1) i=250129
(EURUSD,M1) i=250129
(EURUSD,M1) i=250129
(EURUSD,M1) i=250129
(EURUSD,M1) i=250129

It seems in this case it calculate value for last bar-1 and then the last bar for every new tick


An here using prev_calculated

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[])
  {
  ArraySetAsSeries(time,false);
  ArraySetAsSeries(open,false); 
  ArraySetAsSeries(low,false); 
  ArraySetAsSeries(close,false); 
  ArraySetAsSeries(high,false); 
  ArraySetAsSeries(Segnale,false);
  .........
 for (int i=(int)MathMax(prev_calculated,1000); i<=rates_total-1; i++) {
 Print("NEW BAR, total bars=",Bars(NULL,0));
 Print("i=",i);
 ......
 }
return(ratestotal)


output:
(EURUSD,M1) NEW BAR, total bars=250126
(EURUSD,M1) i=250125
(EURUSD,M1) NEW BAR, total bars=250127
(EURUSD,M1) i=250126
(EURUSD,M1) NEW BAR, total bars=250128
(EURUSD,M1) i=250127

It seems in this second case it calculate value for the last bar and Doesn't refresh for every new tick

Why in this second case It doesn't update index for every new tick like in the first case?

Ernst Van Der Merwe
5651
Ernst Van Der Merwe  
 {
  ArraySetAsSeries(time,false);
  ArraySetAsSeries(open,false); 
  ArraySetAsSeries(low,false); 
  ArraySetAsSeries(close,false); 
  ArraySetAsSeries(high,false); 
  ArraySetAsSeries(Segnale,false);
  .........
 printf("the for loop won't run when prev_calculated %d > rates_total-1 %d",prev_calculated,rates_total-1); 
 for (int i=(int)MathMax(prev_calculated,1000); i<=rates_total-1; i++) {
 Print("NEW BAR, total bars=",Bars(NULL,0));
 Print("i=",i);
 ......
 }
Minions Labs
667
Minions Labs  
Giovanni:

Here there are the differences between Prev_calculated and Prev_calculated-1 in bars loop

...

Why in this second case It doesn't update index for every new tick like in the first case?

Per your code... your  FOR loop is evaluating always everything starting at the index 1000, or until a new bar is created, when prev_calculated gets into action...

I think your problem is with your evaluation of the previous bars needed to be calculated. Do you really need to start a the index 1000 on every tick?


;)

To add comments, please log in or register