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).
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.
Stanislav Korotky #: 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.
Test 1 - Random variable different, it seems to be two instances here.
11:20:45.947 B (USTEC,M1) B [757]-> 0/1000681 -> RND: 3103811:20:45.967 B (USTEC,M1) B [758]-> 0/1000681 -> RND: 3109111:20:57.939 B (USTEC,M1) B [11972113]-> 1000681/1000682 -> RND: 2627511:20:57.939 B (USTEC,M1) B [11992491]-> 1000681/1000682 -> RND: 1814011:21:57.946 B (USTEC,M1) B [71979760]-> 1000682/1000683 -> RND: 2233511:21:57.946 B (USTEC,M1) B [72000099]-> 1000682/1000683 -> RND: 31420
Test 2 - Random variable is the same, but double logs....
11:23:25.831 B (DE40,M1) B [1010]-> 0/50394 -> RND: 2888711:23:25.832 B (DE40,M1) B [820]-> 0/50394 -> RND: 2888711:23:59.648 B (DE40,M1) B [33818205]-> 50394/50395 -> RND: 829011:23:59.648 B (DE40,M1) B [33817143]-> 50394/50395 -> RND: 829011:24:58.142 B (DE40,M1) B [92311584]-> 50395/50396 -> RND: 3063511:24:58.142 B (DE40,M1) B [92310522]-> 50395/50396 -> RND: 30635
11:26:10.228 B (EURGBP,M1) B [734]-> 0/107201 -> RND: 866011:26:10.229 B (EURGBP,M1) B [720]-> 0/107201 -> RND: 866011:26:57.931 B (EURGBP,M1) B [47703865]-> 107201/107202 -> RND: 2272011:26:57.931 B (EURGBP,M1) B [47703101]-> 107201/107202 -> RND: 2272011:27:57.924 B (EURGBP,M1) B [107696811]-> 107202/107203 -> RND: 2085411:27:57.924 B (EURGBP,M1) B [107696045]-> 107202/107203 -> RND: 20854
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
Please also provide your Journal log showing the config used.
2026.03.0217:26:52.620 B (USTEC,M1) OnInit: ChartID 134060885355397815. RND=15426981332026.03.0217:26:52.620 B (USTEC,M1) 1542698133: B [1058]-> 0/10010472026.03.0217:26:52.651 B (USTEC,M1) OnInit: ChartID 134060885355397815. RND=2959550882026.03.0217:26:52.651 B (USTEC,M1) 295955088: B [856]-> 0/10010472026.03.0217:27:00.098 B (USTEC,M1) 295955088: B [7446933]-> 1001047/10010482026.03.0217:27:00.098 B (USTEC,M1) 1542698133: B [7478263]-> 1001047/10010482026.03.0217:28:00.080 B (USTEC,M1) 295955088: B [67429691]-> 1001048/10010492026.03.0217:28:00.080 B (USTEC,M1) 1542698133: B [67460999]-> 1001048/1001049
Journal log:
2026.03.0217:25:45.998 Terminal MetaTrader x64 build 5660 started for MetaQuotes Software Corp.
2026.03.0217:25:45.998 Terminal Windows 10 build 19045, 8 x Intel Core i7-8565U @ 1.80GHz, AVX2, 5 / 15 Gb memory, 116 / 475 Gb disk, UAC, GMT+12026.03.0217:25:45.998 Terminal C:\Users\xxxxxxxxx\AppData\Roaming\MetaQuotes\Terminal\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
.....
.....
.....
2026.03.0217:26:51.286 Experts expert EA (USTEC,M1) loaded successfully
2026.03.0217:26:52.610 Indicators custom indicator B (USTEC,M1) loaded succesfully
2026.03.0217:26:52.618 Indicators custom indicator A (USTEC,M1) loaded succesfully
2026.03.0217:26:52.651 Indicators custom indicator B (USTEC,M1) loaded succesfully
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.
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.