You can add something like this to check if new candle is opened:
static datetime currentBarTime = 0; // or Time[0] if you want to skip first candle; if ( currentBarTime == Time[0] ) { return(0); } currentBarTime = Time[0];
This code should be added at the beginning of the start function. It will ensure that rest of the code is executed only when new candle is opened.
Using "BarCount" as you have in your code has problem because it keeps length of "Bars" buffer. This buffer has some maximum value and from that point on it returns the same number.
Near the beginning of the start() function there is this line:
if (EachTickMode && Bars != BarCount) TickCheck = False;
I didn't do detailed analysis, but it looks to me that this is used to limit order opening only to the start of the candle.
After a bit detailed look into your code, thing that I wrote should be modified a bit. If you copy that as I wrote, it will limit code for closing orders only to the opening of the new candle.
Something like this should work:
static datetime currentBarTime = 0; // or Time[0] if you want to skip first candle; if (EachTickMode && currentBarTime == Time[0]) TickCheck = False; currentBarTime = Time[0];
I did not test this code, so you should carefully test if this suits your trading algorithm.
Hi,
I have an ea which performs extremely well in strategy tester when 'open prices only' is selected, but when I test on 'every tick' mode the results are not so good. So my question is..
Is it possible to adjust my ea so that it works on the same open bar principle as the strategy tester? I tried changing the 'eachtick' variable to 'false' but that didn't do it. Anyone know if there is anything I can do?
The ea is very simple and only uses 2 indicators
- 2010.06.02
- MetaQuotes Software Corp.
- 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,
I have an ea which performs extremely well in strategy tester when 'open prices only' is selected, but when I test on 'every tick' mode the results are not so good. So my question is..
Is it possible to adjust my ea so that it works on the same open bar principle as the strategy tester? I tried changing the 'eachtick' variable to 'false' but that didn't do it. Anyone know if there is anything I can do?
The ea is very simple and only uses 2 indicators