![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Ok, I'll wait
After more than 20 hours the indicator works properly. I don't know what to say.
Rosh, Zoom in/Out, scroll to the left/right. Which platform are you testing on 64/32 bit?
Rosh, Zoom in/Out, scroll to the left/right. Which platform are you testing on 64/32 bit?
I can replicate the general issue on 32-bit. The only way in which the O/S seems to be relevant is the question of why your 64-bit system seems to be periodically getting new data at the start or in the middle of its bar history, whereas your 32-bit system (and RaptorUK's 64-bit system) aren't. Regardless, you appear to be intending to give your indicator to other people, and changes to the bar history are issues which you will definitely then come across in real life, if only because of your users suffering broker disconnections which lead to missing bars being inserted into the middle of the history on re-connection.
As I've already tried to explain, it is debatable whether this "bug" is in your code or in MT4. There is an expectation of how indicators will behave in MT4, and your indicator doesn't behave that way. For example, when you create a new indicator using MetaEditor, it inserts for you the line "int counted_bars=IndicatorCounted();". You're removing this and ignoring IndicatorCounted().
I can replicate the general issue using the following indicator which simply draws a line between the last 10 bar-highs when it first starts up:
You can then replicate the same kind of problem by doing the following:
* Open a chart for any symbol
* Add the indicator to the chart
* Turn off "Chart autoscroll" (just to make the following steps easier; not because it has any impact on the issue)
* Go to the start of the chart, by pressing Home
* Press Page Up to force a download of extra data. (N.B. There is no problem unless some extra data is actually added to the chart at this point.)
* Go to the end of the chart, by pressing End. The red line between the highs will now be out of position. It will have been moved backwards in time.
[All this is just fleshing out what RaptorUK has already identified.]
OK, Can you confirm, IndicatorCounted() will return a -ve number, in this case of missing bars / corrupt indicators? Let me try reinitializing the indicator arrays and redrawing the moves from the lookback bar.
OK, Can you confirm, IndicatorCounted() will return a -ve number, in this case of missing bars / corrupt indicators?
The documentation of IndicatorCounted() (https://docs.mql4.com/customind/IndicatorCounted) provides one example of doing this, and there are alternate versions such as https://www.mql5.com/en/forum/132447 which aim for very marginally improved performance because the standard code at https://docs.mql4.com/customind/IndicatorCounted unnecessarily recalculates one bar which is "clean".
Adding IndicatorCounted() checks and reinitializing the indicators when IndicatorCounted() returns value 0, solves the problem of shifting indicators which are caused when history or additional bars are inserted.
However, there is another problem of corruption of indicators, which appears not to be caused by insertion of history bars. Sample code enclosed to reproduce the problem, you need to run it for 10+hrs, till atleast two reinitialization of indicators ie IndicatorCounted() returning 0 (post indicator start).