How to prevent an expert advisor from opening more than one trade at a time
The problem is that your EA is trading the same trade Multiple times on one bar. Every time a new tick happens it is firing off the same trade.
There is a very easy fix for this. This fix simply orders your expert advisor to perform its new calculations the very tick after a bar closes. It is then ordered to wait until the bar closes before it does the calculations again. Otherwise the EA runs itself every tick, so if it is a bar that cause a trade to fire off, then every tick will reopen the trade.
Here is the very simple solution to this problem...
Reference Page: MQL5 COMMUNITY FORUM
How to prevent your EA from sending Multiple buy or Sell orders
Another problem commonly ran into is having a trade open once and then, for example, 30 bars down the line, the same opening criteria is met, so the EA opens another trade. This often result in a loss in profit.
To fix this, you simply need to use your MagicNumber and a Halt function
In simple terms, the following code snippet will tell your Expert Advisor that if there are any open trades with a particular MagicNumber, that it is to NOT continue on with opening another trade
Simply copy and paste this code into your EA and you will not have this problem anymore.
When a buy order is opened with a certain magic number, no more buy orders will open. If you want to make it so that no sell orders open either, when a buy order is open and vice versa, simply apply both halts to both opening conditions.
Here is the code needed... Place it before your section for opening orders...
Here is how you apply the code into a order condition...
This example is simply saying, "If RSI indicator is above 70 and the magicnumber for this trade is not in use, then proceed to opening this trade."
And that's it! That's all you need to solve both of the above problems. Hopefully that helped and made sense. If you are confused, just read it all again slowly, until it does. Coding is very logical and sequential.
NEXT UP --->