well....I am not sure what exactly your idea is... I looked at your code briefly....
However these loops with iCustom calls are not best idea.For fast speed, call iCustom only in a necessary moment. In general you refer to finished candles...but in loops you also use unfinished candle value since you start loops with 0 and not 1.
If I was suppose to make your code faster, I would definitelly get rid of unnecessary iCustom calls for finished candles on every tick.
I would make for example:
int current_bar; void OnInit() { current_bar=Bars-1; } void OnTick() { if(Bars>current_bar) { current_bar=Bars; //and here all calculations you need } }
And a better option for really perfect and never ending operation till the end of the world (from William Roeder)
datetime bar_open_time; void OnInit() { bar_open_time=Time[0]-1; } void OnTick() { if(Time[0]>bar_open_time) { bar_open_time=Time[0]; //and here all calculations you need } }
I would also change loops start to int=1 instead of 0 if it does not influence your strategy, tactic or however you call it.
I would also not create variables on every tick.
I would declare them first to allocate memory space for them and then use them....
if you need to reset them...just put a zero value there....
I would also get rid of Print functions.
Of course it may be necessary for you to check some part of code....but after checking I would remove it, to get better speed.
Wishing you luck:)
Piotr Latoszynski:
if(Bars>current_bar)
-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019.05.06)
Messages Editor -
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 (2014.04.04)I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011.05.06)
-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019.05.06)
Messages Editor -
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 (2014.04.04)I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011.05.06)
1.Done:)
2. Bars is unreliable (a refresh/reconnect can change number of bars on chart)...Well...same rule applies to time...if you change timeframe...Time{0] also may change unfavourably.
The protective code during OnInit() function does the job I believe in both cases to execute the code only once per bar. ( I skip the issue of the first "initial" bar, because it depends on what we need to do )
I agree with you, that bars will eventually reach the limit of Bars in MT4, so if we talk about a perfect solution, it must be time:)
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011.05.06)
...Here I do not see the relation to the issue:)New bar condition ( not function ) is to ensure executing the code only once - at the start of a new bar. Nothing more nothing less.
- 2011.05.06
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys if I try to do a backtest on my custom Expert Advisor it starts eating diskspace like crazy within 5minutes easily 100GB, I have no idea why maybe the loops inside my code?