You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I have already provided you with an example in my previous post ... #9
As for you not being able to use a loop to update previous values, without an actual detailed explanation of what you are doing, I cannot just "guess" at what should be done for your case specifically.
can I just remove the for-loop from your example and just use the buffer[0] = .... ?
Like this:
Would it be correct?
As per your original post (and code where you DIDN'T use a loop), you stated that ... "Everything works correctly. But after some time the buffer values get either corrupted or mixed."
So, how are you going to resolve that, when for example there is a history update or bars are missed or recalculations are needed?
How are you going to detect which buffer data is valid and which is corrupted?
Unless you give a more clear understanding of what you are doing, we are unable to give you a proper answer.
EDIT: You will probably, need to build a separate internal (or external) database of the data you are collecting and then use that to keep the buffers synchronised properly. However, I don't know what you are doing, so I am only guessing here.
As per your original post (and code where you DIDN'T use a loop), you stated that ... "Everything works correctly. But after some time the buffer values get either corrupted or mixed."
So, how are you going to resolve that, when for example there is a history update or bars are missed or recalculations are needed?
How are you going to detect which buffer data is valid and which is corrupted?
Unless you give a more clear understanding of what you are doing, we are unable to give you a proper answer.
EDIT: You will probably, need to build a separate internal (or external) database of the data you are collecting and then use that to keep the buffers synchronised properly. However, I don't know what you are doing, so I am only guessing here.
My question is why the old buffer data is overwritten by MetaTrader?
I see that I had missing "INDICATOR_DATA" in SetIndexBuffer. I had it just SetIndexBuffer (0, g_dbBufferBarUp); I do not know it that could be the reason...
I'm not sure. The are several possible factors, but since we don't have access to your whole code, we can only guess.
No, that part will not affect it, because "INDICATOR_DATA" is the default anyway.
Here I have done the test with the attached indicator. And as you see the histogram values are corrupted!!! It happens after many hours of running. It was fully correct at beginning. And only after about 10 hours of running the old bars become wrong values. Every bullish candle should have green histogram bar and every bearish candle should have red histrogram bar. After x hours of running the values get mixed! While the "fresh" historgram bars are showing correct. Only old "histogram" bars become chaotic values.
Old bars with chaotic values:
Fresh (new) bars with correct values:
Here is the indicator code:
PLEASE HELP ME TO SORT OUT THIS ISSUE. SEEMS THAT METATRADER HAS A CRITICAL BUG!
THERE IS NO BUG. I've already explained that the buffers sometimes need to be refreshed. This happens when the old bar data is removed or added from the chart or its maximum number bars changes.
Given, that you are only updating the current bar, this can and will happen, that the buffers becomes unsynchronised and need to be refreshed.
So, you have to create a mechanism to cache the external data in an internal or external database, to use as a source to refresh the buffers properly in a loop.
You could for example cache the data in an Offline Chart for example or some other data file of your own format.
Here is a simplistic example of when old data is removed from a chart:
So, as you can see, it is not a bug, it is just as how it works, and why the "rates_total" and "prev_calculated" from OnCalculate() work as they do and you have to use a loop.
can I just remove the for-loop from your example and just use the buffer[0] = .... ?
Like this:
Would it be correct?
i'm more curious if any reason you don't want to use for-loop.