prev_calculated - page 3

 
Alexey Viktorov:

The amazing ability to answer the wrong question...

Now explain to me what would happen if:

1. 100 bars recalculated, entered into buffers from 0 to 99 inclusive (let's consider the direction as time series) the value 1.03

2. Suddenly, history was loaded and prev_calculated became 0.

From which bar in the indicator the value will be 1.03?

  1. In order to calculate the indexing as in the timeseries, we should set the AS_SERIES flag in OnInit() of the indicator buffer - that's why I prefer to use the concept "the rightmost bar" - this way no one will be mistakenly informed.
  2. Here is the answer:
       if(prev_calculated==0)
         {
          //--- инициализация элементов индикаторного буфера при первом запуске или при подкачке истории
          for(int i=0;i<rates_total;i++)
             ExtBuffer[i]=1.01;
          return(rates_total);
         }
    at "prev_calculated==0" absolutely all elements of indicator buffer will be re-initialized with values "1.01" and immediately exit by "return(rates_total);". That is, no trace of previous "1.03" values will remain in the indicator buffer.
 
Alexey Viktorov:

Better explain how to get rid of rubbish theFIRST time the indicator is started.

It's simple - forget prev_calculated, create your own duplicate without the 'hole in the side'. If you want to keep track of previously calculated bars - likefxsaber in the example.
fxsaber:
Not a crutch at all. That's how I do it.
If a simple flag first run / no longer first run is enough, replace prev_calculated by static bool b_First_Run. Or you can put buffer initialization to OnInint
 
Karputov Vladimir:
  1. To consider indexing as in timeseries, we should set AS_SERIES flag in OnInit() of indicator buffer - that's why I prefer to use "rightmost bar" - so no one will be mistakenly informed.
  2. Here's the answer:
       if(prev_calculated==0)
         {
          //--- инициализация элементов индикаторного буфера при первом запуске или при подкачке истории
          for(int i=0;i<rates_total;i++)
             ExtBuffer[i]=1.01;
          return(rates_total);
         }
    at "prev_calculated==0" absolutely all elements of indicator buffer will be re-initialized with values "1.01" and immediately exit by "return(rates_total);". That is, no trace of previous "1.03" values will remain in the indicator buffer.

So, this is the problem that should be solved. I don't need rubbish (not really, but it interferes with displaying), but I need to save the previous calculations of the indicator. When you start the indicator FIRST time the buffer gets rubbish, and when loading history all that was inserted into buffers should be saved ... and preferably without saving it to a file or to GV.


added:

This is intended to estimate the drawdown in real time every minute. The Expert Advisor works for a week without stopping, and instead of the weekly display we'll see only the last value, which is visible even without the indicator.

 
Alexander Puzanov:
If a simple flag first run / no longer first run is enough, replace prev_calculated with static bool b_First_Run. And you can put buffer initialization in OnInint
No, the purposes there are not so primitive.
 
fxsaber:
No, the goals there are not so primitive.
This is not your suggestion,Alexey Viktorov as I understand it only needs to zero the buffers on the first start and do not touch anything in them during any paging
 
Alexey Viktorov:

So this is the problem that needs to be solved. I don't need rubbish (I don't need it, but it interferes with displaying), but I need to save previous calculations of the indicator. When you start the indicator FIRST time the buffer gets rubbish, and when loading history all that was inserted into buffers should be saved ... and preferably without saving it to a file or to GV.


added:

This is intended as a real time estimate of the drawdown every minute. The Expert Advisor works for a week without stopping, and instead of the weekly display we will only see the last value, which is visible even without indicator...

О! Now it makes more sense. I will reply in the evening.
 
Alexander Puzanov:
This is not your suggestion,Alexey Viktorov, as I understand it, you need only this - to zero buffers at the first start and not to touch anything in them during all sorts of paging
Of course, I started with initializing buffers in OnInit(), but something was wrong. I do not remember what and I initialized them in OnCalculate with prev_calculated == 0
 

Re-checked what happens if buffer arrays are initialized in OnInit().

Even when the indicator is removed from the chart and newly set, NOT ALL, but some buffers still have the old values. Not even exactly what they were before, but one of those values extends over several bars.

 
Karputov Vladimir:
Oh! That makes more sense now. I'll get back to you tonight.
Sorry for the delay in replying. The only way to save the calculated values for this timeframe is to save them to a file. That requires synchronization - the data should be distributed on their bars when reading from the file. The most logical way is to synchronize it with the bar open time, but there may be some nuances: for example, the bar open time (saved to a file) was 2016.09.05. 25:02, but now there is a bar on the chart with time equal to 2016.09.05. 25:01.
 
Karputov Vladimir:
Sorry for the delay in replying. The only way to save the calculated values for a given timeframe is to save them to a file. You need to take care of the synchronisation - so that when reading from the file the data are placed on their bars. The most logical solution is synchronization according to the bar open time, but there may be some subtleties: for example, the bar open time (saved to a file) was 2016.09.05. 25:02, but now we have a bar on the chart with the time equal to 2016.09.05. 25:01.

Or maybe it would be better to draw developers' attention to the problem of initialization of indicator buffers? Why is there no such problem in MT4? Maybe again not a complete understanding? The problem is that even after the mandatory initialization of buffers after taking an indicator off a chart in EACH of them, not all buffers contain rubbish, and we can't unload it from there...

Personally I don't mind crutches, but only if these crutches are not too complicated and with positive effect. But writing to a file and then reading it is a crummy crutch.

Reason: