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
Have you tried putting your calls to indicator handles inside OnCalculate(), conditionally, as suggested by Airton Gomes Finoti in the other thread that you found?
"My work-around way is that EA load indicator A and indicator B in OnInit() process. Indicator A searches the handle of indicator B in the event of OnCalcute() for the first time. it shouldn't be done in the event of OnInit(). This work-around works well" (https://www.mql5.com/en/forum/98373#comment_18353294).
No. Using iCustom alone (Not using ChartIndicatorAdd) doesn't lead to duplicate indicators on a live chart.
I can confirm that i have double logs changing EA code to this:
I get this log when i attach EA to chart:
Also refreshing che chart (right click-> refresh), i have same double logs.
I can confirm that i have double logs changing EA code to this:
I get this log when i attach EA to chart:
Also refreshing che chart (right click-> refresh), i have same double logs.
Your way to detect double instances is not correct.
OnCalculate() can be called twice in a row with prev_calculated = 0.
2026.02.28 08:35:01.574 B (EURAUD,M1) OnInit: ChartID 134160922411012695. RND=13803
2026.02.28 08:35:01.574 B (EURAUD,M1) 13803: B [731]-> 0/100000
--> Refresh
2026.02.28 08:35:12.502 B (EURAUD,M1) 13803: B [10928101]-> 0/100000
2026.02.28 08:35:12.627 B (EURAUD,M1) 13803: B [11053560]-> 0/100000
2026.02.28 08:35:22.038 B (EURAUD,M1) OnDeinit: ChartID 134160922411012695. RND=13803
Your way to detect double instances is not correct.
OnCalculate() can be called twice in a row with prev_calculated = 0.
2026.02.28 08:35:01.574 B (EURAUD,M1) OnInit: ChartID 134160922411012695. RND=13803
2026.02.28 08:35:01.574 B (EURAUD,M1) 13803: B [731]-> 0/100000
--> Refresh
2026.02.28 08:35:12.502 B (EURAUD,M1) 13803: B [10928101]-> 0/100000
2026.02.28 08:35:12.627 B (EURAUD,M1) 13803: B [11053560]-> 0/100000
2026.02.28 08:35:22.038 B (EURAUD,M1) OnDeinit: ChartID 134160922411012695. RND=13803
I did test this by random initialization of a static variable - it's different in the logs, so these are 2 instances, not 2 events in the same instance.
There is a random variable in my code and log, it's from the same instance.
I can't reproduce what you said.
Your way to detect double instances is not correct.
OnCalculate() can be called twice in a row with prev_calculated = 0.
2026.02.28 08:35:01.574 B (EURAUD,M1) OnInit: ChartID 134160922411012695. RND=13803
2026.02.28 08:35:01.574 B (EURAUD,M1) 13803: B [731]-> 0/100000
--> Refresh
2026.02.28 08:35:12.502 B (EURAUD,M1) 13803: B [10928101]-> 0/100000
2026.02.28 08:35:12.627 B (EURAUD,M1) 13803: B [11053560]-> 0/100000
2026.02.28 08:35:22.038 B (EURAUD,M1) OnDeinit: ChartID 134160922411012695. RND=13803
I made these other tests, in Terminal Chart (NO tester).
EA
A
B
I got really weird behaviour.
Test 1 - Random variable different, it seems to be two instances here.
Test 2 - Random variable is the same, but double logs....
I made these other tests, in Terminal Chart (NO tester).
EA
A
B
I got really weird behaviour.
Test 1 - Random variable different, it seems to be two instances here.
Test 2 - Random variable is the same, but double logs....
Try this please as I can't reproduce that behaviour in any way.
The random number should be allocated globally, only once. I used Xoshiro256 library to be sure to get different random number in case there are several instances.
2026.03.02 08:39:06.690 EA505693 (EURUSD,M1) EA: B launched through iCustom, handle 10
2026.03.02 08:39:06.705 A (EURUSD,M1) A: B launched through iCustom, handle 10
2026.03.02 08:39:06.706 B (EURUSD,M1) OnInit: ChartID 134160922411012695. RND=1234155352
2026.03.02 08:39:06.706 B (EURUSD,M1) 1234155352: B [696]-> 0/100003
2026.03.02 08:40:01.315 B (EURUSD,M1) 1234155352: B [54609529]-> 100003/100004
2026.03.02 08:41:01.857 B (EURUSD,M1) 1234155352: B [115151607]-> 100004/100005
2026.03.02 08:42:01.474 B (EURUSD,M1) 1234155352: B [174768490]-> 100005/100006
2026.03.02 08:43:01.310 B (EURUSD,M1) 1234155352: B [234604503]-> 100006/100007
2026.03.02 08:48:57.134 EA505693 (USTEC,M1) EA: B launched through iCustom, handle 10
2026.03.02 08:48:57.140 A (USTEC,M1) A: B launched through iCustom, handle 10
2026.03.02 08:48:57.141 B (USTEC,M1) OnInit: ChartID 134169322501958094. RND=192256192
2026.03.02 08:48:57.141 B (USTEC,M1) 192256192: B [754]-> 0/39848
2026.03.02 08:49:01.332 B (USTEC,M1) 192256192: B [4191697]-> 39848/39849
2026.03.02 08:50:01.314 B (USTEC,M1) 192256192: B [64173855]-> 39849/39850
2026.03.02 08:50:03.027 B (USTEC,M1) 192256192: B [65887322]-> 0/39850
2026.03.02 08:51:01.391 B (USTEC,M1) 192256192: B [124251143]-> 39850/39851
Using your B indicator code:
Experts log:
Journal log:
Can you send me also EA and A code you use?
Using your B indicator code:
Experts log:
Journal log:
Can you send me also EA and A code you use?
Using your B indicator code:
Experts log:
Journal log:
Can you send me also EA and A code you use?
Ok I found the problem and reproduced it.
I moved the indicators in MQL5/Indicators.
2026.03.02 12:03:40.247 EA505693 (USTEC,M1) EA: B launched through iCustom, handle 10
2026.03.02 12:03:40.252 B (USTEC,M1) OnInit: ChartID 134169322501958094. RND=1805330128
2026.03.02 12:03:40.252 B (USTEC,M1) 1805330128: B [748]-> 0/40043
2026.03.02 12:03:40.262 A (USTEC,M1) A: B launched through iCustom, handle 10
2026.03.02 12:03:40.263 B (USTEC,M1) OnInit: ChartID 134169322501958094. RND=821904471
2026.03.02 12:03:40.263 B (USTEC,M1) 821904471: B [763]-> 0/40043
2026.03.02 12:04:01.537 B (USTEC,M1) 821904471: B [21274811]-> 40043/40044
2026.03.02 12:04:01.537 B (USTEC,M1) 1805330128: B [21286213]-> 40043/40044
2026.03.02 12:05:01.411 B (USTEC,M1) 821904471: B [81149159]-> 40044/40045
2026.03.02 12:05:01.411 B (USTEC,M1) 1805330128: B [81160561]-> 40044/40045
Previously I had not the problem because the indicators were in the SAME FOLDER as the EA.
Thanks for your help.