Add the below code, calling the isNewBar() function to detect when a new bar is formed and thus only execute your code when necessary. However, the function should only be called once per tick even, so if you need to check its state more than once per tick event, save it to a variable for the duration of the start() or OnTick() event.
As for your problem of the trades not being opened, you did not provide that logic in your post, so we will not be able to help you there.extern bool Trail_Stop=true; int start() { if( isNewBar() ) { Order_Send(); Order_Close(); } if( Trail_Stop ) TrailingStop(); return(0); } void Order_Send() {}; void Order_Close() {}; void TrailingStop() {}; bool isNewBar() { static datetime last_time = WRONG_VALUE; datetime lastbar_time = (datetime) SeriesInfoInteger( _Symbol, _Period, SERIES_LASTBAR_DATE ); // to be compatible with MQL5 if( last_time != WRONG_VALUE ) { if( last_time != lastbar_time ) { last_time = lastbar_time; return( true ); } } else last_time = lastbar_time; return( false ); }
FMIC:
Add the below code, calling the isNewBar() function to detect when a new bar is formed and thus only execute your code when necessary. However, the function should only be called once per tick even, so if you need to check its state more than once per tick event, save it to a variable for the duration of the start() or OnTick() event.
As for your problem of the trades not being opened, you did not provide that logic in your post, so we will not be able to help you there.
Thank you very much for your help. I will give this a try.
Add the below code, calling the isNewBar() function to detect when a new bar is formed and thus only execute your code when necessary. However, the function should only be called once per tick even, so if you need to check its state more than once per tick event, save it to a variable for the duration of the start() or OnTick() event.
As for your problem of the trades not being opened, you did not provide that logic in your post, so we will not be able to help you there.
Trader3000:
Thank you very much for your help. I will give this a try.
Thank you very much for your help. I will give this a try.
You can also use WHRoeder's method which much more compact than my example:
WHRoeder:
- Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
- I disagree with make a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
FMIC:
Okay thank you again. I will test both methods
You can also use WHRoeder's method which much more compact than my example:
WHRoeder:
- Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
- I disagree with make a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
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
Hi Everyone
I have two related questions:
Question 1.
I have tried a number of different ways to limit my EA from running on every tick for certain void functions, but have not had any success. Some of my void functions only need to get executed when the new candle/bar forms, so it's not necessary to call all the iCustom indicators. My EA looks something like this:
I tried:
The efforts above does not work because no trades are opened.
Question 2.
The reason I am trying to accomplish the above is because my EA calls iCustom indicators. Since I added this to my EA, it became extremely slow in the Strategytester. The iCustom indicators use functions such as IndicatorCounted or rates_total to limit the calculations to only new data, but this seems to be insufficient. So, it is due to this, that I am trying what I asked in question one, but is there perhaps a better way or alternative way to speed up startegy tester when iCustom indicators are used?
Thank you very much in advance