Changing the TF is a problem - page 6

 
Vasyl Nosal:
That's it? It's not going to glitch?
It's not the code that's glitchy. :) Take it and use it.
 
Sergei Vladimirov:

Vladimir, why are you doing this inside OnCalculate()? I mean the last two lines - reinitialization of arrays. You have both buffers calculated on each bar, it's an unnecessary action.

if(prev_calculated==0)
{
   limit=rates_total-1;
   ArrayInitialize(up_arr,EMPTY_VALUE);
   ArrayInitialize(down_arr,EMPTY_VALUE);
}
Why have you decided that initialization will be performed on each tick? The condition prev_calculated==0 is executed once or twice at indicator start. During the operation prev_calculated==0 may become so if the history is changed - but it rarely or never and the change of history requires recalculation of the indicator.
 
Sergei Vladimirov:
It's not the code that's glitchy. :) Take it and use it.

Thank you:))))))))))))))))))))))))))))))))))))))))))))))))))

Who's next?

 
Karputov Vladimir:
Why have you decided that initialisation will take place on every tick? The condition prev_calculated==0 is executed once or twice at indicator start. During the operation prev_calculated==0 may become if the history is changed - but it rarely or even never and the change of history requires recalculation of the indicator.
Can you do without zeroing of buffers during history loading?
 
Karputov Vladimir:
What makes you think that initialisation will take place on every tick?
Where did I write that? I was asking why you re-initialise the buffers in OnCalculate() if you then have both buffers calculated on all bars.
 
Sergei Vladimirov:
Where did I write that? I was asking why you re-initialise the buffers in OnCalculate() if you then have both buffers calculated on all bars.
Incorrect statement. When prev_calculated==0 I subsequently bypass all bars, but it does not guarantee replacement of all values in indicator buffers. Therefore, when prev_calculated==0 you need to clear the indicator buffers.
 
Vasyl Nosal:

Thank you:))))))))))))))))))))))))))))))))))))))))))))))))))

Who's next?

Why lie?

 
Karputov Vladimir:
Incorrect statement. When prev_calculated==0, I subsequentlybypass all bars, butit does not guarantee replacement of all values inindicator buffers. Therefore, at prev_calculated==0 I need to clear indicator buffers.

Yes? Can you give me an example of when in your code some value of some buffer will not be filled? Except maybe the very first bar in the story.

 
Sergei Vladimirov:

Why lie?

Genius.

Have you tried switching to a pair with no history and then switching to another TF?

 
Sergei Vladimirov:

It wasn't a statement, it was a question.

Yes? Maybe you can give us an example, when in your code some value of some buffer will not be filled?

You know, let's do this: take code 1.43 from this post and comment out the lines:

if(prev_calculated==0)
{
   limit=rates_total-1;
//ArrayInitialize(up_arr,EMPTY_VALUE);
//ArrayInitialize(down_arr,EMPTY_VALUE);
}

and look at the result when scrolling the graph to the back of the history and have the history loaded.

Reason: