Hello,
I saw it mentioned on the forum that we should initialize all buffers. However, when I look at examples (like CCI or Envelopes) I don't see any initialization happening.
Being precise, should I have the following snippet in my every indicator, in the onCalculate?
{
ArrayInitialize(indicator_data, EMPTY_VALUE);
}
indicator_data is an indicator buffer (SetIndexBuffer(0,indicator_data,INDICATOR_DATA)).
And why would we do it if later we set a value for each index in the buffer?
Cheers!
Don't do that - do you buffers cleanup on loops for each and every element. Otherwise you shall have repainting indicators
Don't do that - do you buffers cleanup on loops for each and every element. Otherwise you shall have repainting indicators
Huh ? Why is that ?
Of course it's not needed to always use ArrayInitialize() but using the above code would not lead to repainting indicators at all.
Hello,
I saw it mentioned on the forum that we should initialize all buffers. However, when I look at examples (like CCI or Envelopes) I don't see any initialization happening.
Being precise, should I have the following snippet in my every indicator, in the onCalculate?
{
ArrayInitialize(indicator_data, EMPTY_VALUE);
}
indicator_data is an indicator buffer (SetIndexBuffer(0,indicator_data,INDICATOR_DATA)).
And why would we do it if later we set a value for each index in the buffer?
Cheers!
Why are you opening a new topic ?
Forum on trading, automated trading systems and testing trading strategies
Indicators' PLOT_EMPTY_VALUE not working properly
Alain Verleyen, 2020.04.19 23:42
Because a value is set explicitly for all indexes of all buffers.You ALWAYS need to understand what you are doing. A buffer is an array automatically managed by MT5, but with uninitialized values. So you NEED to see a value for each index of the array, it can be done in any way provided that all values are set explicitly. Otherwise you will have garbage graphics like explained on the other topic.
Huh ? Why is that ?
Of course it's not needed to always use
ArrayInitialize() but using the above code would not lead to repainting indicators at all.
That is exactly my point : people think that initializing a buffer solves all the stuff that they usually have to do in their code (mainly in loops). I have seen that 100s of times, and then in the code where the job is actually done I have seen a complete disregard to the "clean up" part which lead to heavy repainting (my guess is that they thought : "I have initialized it, no need to do anything else" kind of stuff)
Even if he initializes the buffer, he shall have to write the code correctly to "clean up" the buffers on each and every new calculation loop - hence that initialization is of no actual at all if the rest of the code is written as it should be (initialized buffers or no, does not matter).
That is exactly my point : people think that initializing a buffer solves all the stuff that they usually have to do in their code (mainly in loops). I have seen that 100s of times, and then in the code where the job is actually done I have seen a complete disregard to the "clean up" part which lead to heavy repainting (my guess is that they thought : "I have initialized it, no need to do anything else" kind of stuff)
Even if he initializes the buffer, he shall have to write the code correctly to "clean up" the buffers on each and every new calculation loop - hence that initialization is of no actual at all if the rest of the code is written as it should be (initialized buffers or no, does not matter).
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I saw it mentioned on the forum that we should initialize all buffers. However, when I look at examples (like CCI or Envelopes) I don't see any initialization happening.
Being precise, should I have the following snippet in my every indicator, in the onCalculate?
{
ArrayInitialize(indicator_data, EMPTY_VALUE);
}
indicator_data is an indicator buffer (SetIndexBuffer(0,indicator_data,INDICATOR_DATA)).
And why would we do it if later we set a value for each index in the buffer?
Cheers!