The statement looks well-formed. No need to replace the operators. It must be something in your conditions that prevents case 2-4 to fire. Instead of (a+b)<c you could just write a+b<c
It looks like it was another part of the code that was the problem because I didn't change these statements and now it works fine. I guess I'll leave this post here in case someone finds the code useful.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
I'm making a somewhat simple EA that executes trades when a bar closes above the SMA and the next bar breaks that high and vice versa (there's more to it but I still haven't gotten this part to work yet), but I also want it to enter a position in the case the next bar doesn't go above the first bars high but still closes above the SMA. It should then enter a buy if the new bar breaks that high of the second bar that closed above the SMA and so on (I have four iterations because it is enough to cover all cases).
An example, a bar opens below and closes above the SMA, the next bar never breaks the high of that bar but still closes above the SMA. The next bar does the same. Finally, the fourth bar breaks the high of the previous bar and a buy order is executed.
The problem I'm having is that when backtesting, the tester will enter a trade if the first iteration is met, but if any of the other three cases are met it isn't entering a trade; it's only using the first block of conditions and none of the ones after if the first isn't true. So therefore the || function seems to be the problem. Am I using it wrong? Should I use several sequential else if statements instead?