- Print out your variables, and find out why. In image one, the Low[0] was below Low[1] at the time it opened the order.
- Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- You must RefreshRates between sleeps and server calls.
- Using OrdersTotal buy itself means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 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
I recently started programming my very first EA. It may look a little confusing at first but i hope it is readable. The reason for this post is that i have encountered a problem. It comes down to this. I want to execute a buy/sell order once 3 requirements are met.
Now, the EA handles assessing the MA and RSI conditions just fine. It also correctly handles the third condition. Where it fails sometimes is at the price where it sends an order. To show the situation where i want to buy/sell i have added a few pictures.
The picture below depicts a (in theory) correct short order: The high of candle 0 does not top the high of candle 1, and the low of candle 0 goes below the low of candle 1. The stoploss is set just above the high of candle 1, and the order is put in just below the low of candle 1. The method for long orders is exactly the opposite of this one.
Now, sometimes the program send in orders that do not follow the algorithm as i desire.
In the picture below the point where an order is sent is not below the low of candle 1. The stoploss is set correctly though.
In the picture below we have a incorrect long order. Again, the StopLoss is set correctly (just below the low of candle 0). However, the order is sent in somewhere in the middle of candle 0, instead of just above the high of candle 0.
My question is: what is going wrong here?
And while we're here: i want my EA to check if there is anyway for the line of code below to check for only orders with the magic numbers defined at the start of the program instead of any order:
I want to be able to send orders manually too while the EA runs. The way it is set up now does not allow that since it considers my manual orders too for OrdersTotal.
For those who got through this long read: thanks! I hope someone can help me out here.
Thanks in advance!