FernandoBorea: the next tick has the conditions too
You are looking at a signal. Act on a change of signal.
MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum
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
Hello all!
I'm working on a project and I have a question, the system I'm working on uses Tenkan-Sen crossover with price, the problem I'm facing is the following:
I want the system to take a trade every time the conditions are met (Bar opens below tenkan and closes above it) when the EA sends the order (buy), the next tick has the conditions too as the candle still has its open price below and the close above, if I use previous candle comparison to take the trade, the same thing will happen, as this situation relies on the "status" of the current bar.
I tough about making a function that sends the EA to sleep X amount of time depending on the time frame, but as Sleep function does not work on the Strategy Tester it will become useless as it would be impossible to optimize the EA.
I found this walk-around on a forum that allow me to run the code just once per bar:
(Full explaination of the code here: http://mql4tradingautomation.com/execute-action-once-per-bar-mql4/)
I'm using this walk-around, but I still want to figure out other ways to avoid opening massive ammount of trades when I have a condition similar to the one I'm facing now. If the EA would only take one trade at the time, it would be very easy, but as this is not that case, I can think on other situations where using this walkaround is just not enough, for example, if I would need some complex conditions to be met, like if X indicator above Y indicator and K indicator below L indicator then send an order when the price crosses a MA regardless if the close price of the current candle ends above or below it.
In that case, I would have to either stick a massive part of the code on one line or waste resourses verifying a lot of conditions and use this walk-around on the OrderSend() part.
Any ideas on how to get the same results but with a more flexible coding?