Dear all,
I have actively started to develop an EA to complement my discretionary trading. While all the great resources provided by MetaQuotes and this great community of traders have aided me greatly, I have come to a challenge I could not overcome.
The backtesting of my EA provides solid result with a quite satisfactory profit factor, however, paying closer attention to the individual trades executed I realized that the EA performs consecutive loss-making trades at times.
e.g. Condition 1 & 2 are fulfilled it executes a trade, produces a loss, jumps straight in and performs a second trade, produces a lost, and so on.
So I guess I have isolated the issue, and recognize that the EA may not be suitable in certain market environments, so what I am hoping to do is to add another Condition to my code, for it not to enter a trade in the same direction (Long/short) if the previous trade (or 2) in this direction were loss-making.
Alternatively: maybe the EA could be directed to take no trade for X bars if previous was loss-making!
I know all of your time is valuable, but any help would be much appreciated!
Below is an extract of my code:
<CODE REMOVED>
Please edit your post . . .
// Buy order if(Oscillator1 > Oscillator2 && RSI >= 45 && BuyMarketCount(Symbol(),MagicNumber) == 0) { // Close sell orders if(SellMarketCount(Symbol(),MagicNumber) > 0) { CloseAllSellOrders(Symbol(),MagicNumber,Slippage); } // Open buy order BuyTicket = OpenBuyOrder(Symbol(),LotSize,UseSlippage,MagicNumber);@RaptorUK - done! Thanks!
The problem there can be with your code is that when this
CloseAllSellOrders(Symbol(),MagicNumber,Slippage);
is not closing all sell ( see no check if it succeed )
then it can be you open buy with
BuyTicket = OpenBuyOrder(Symbol(),LotSize,UseSlippage,MagicNumber);
and you have buy and sell trade(s)
by the next tick you don't close the remaining selltrades because
BuyMarketCount(Symbol(),MagicNumber) > 0
The problem there can be with your code is that when this
is not closing all sell ( see no check if it succeed )
then it can be you open buy with
and you have buy and sell trade(s)
by the next tick you don't close the remaining selltrades because
@deVries, Hi! Thanks for your quick response. To be honest, I think this is not the problem - the code seems to operate fine in this regard, all remaining get closed when necessary!
Alternatively: maybe the EA could be directed to take no trade for X bars if previous was loss-making!
https://www.mql5.com/en/forum/143565
Take a read there how you can do this
Thanks devries! Much appreciated, I ll have a read now:-)
Hi Raptor,
Thanks for advise but If i will choos close deal in the pool one by one, there should be a problem arise as because I have open position BUY againest SELL So If i will choose any one of them then it should be effect on equity and margin also. So how it is possible.
Thanking You
Md Imran Khan
Hi Raptor,
Thanks for advise but If i will choos close deal in the pool one by one, there should be a problem arise as because I have open position BUY againest SELL So If i will choose any one of them then it should be effect on equity and margin also. So how it is possible.
Thanking You
Md Imran Khan
Hi Raptor,
Thanks for advise but If i will choos close deal in the pool one by one, there should be a problem arise as because I have open position BUY againest SELL So If i will choose any one of them then it should be effect on equity and margin also. So how it is possible.
What advice ? how is what possible ? I don't understand your questions.
Do you mean this ? Loops and Closing or Deleting Orders

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear all,
I have actively started to develop an EA to complement my discretionary trading. While all the great resources provided by MetaQuotes and this great community of traders have aided me greatly, I have come to a challenge I could not overcome.
The backtesting of my EA provides solid result with a quite satisfactory profit factor, however, paying closer attention to the individual trades executed I realized that the EA performs consecutive loss-making trades at times.
e.g. Condition 1 & 2 are fulfilled it executes a trade, produces a loss, jumps straight in and performs a second trade, produces a lost, and so on.
So I guess I have isolated the issue, and recognize that the EA may not be suitable in certain market environments, so what I am hoping to do is to add another Condition to my code, for it not to enter a trade in the same direction (Long/short) if the previous trade (or 2) in this direction were loss-making.
Alternatively: maybe the EA could be directed to take no trade for X bars if previous was loss-making!
I know all of your time is valuable, but any help would be much appreciated!
Below is an extract of my code:
if(Oscillator1 > Oscillator2 && Oscillator3 >= 45 && BuyMarketCount(Symbol(),MagicNumber) == 0)
{
// Close sell orders
if(SellMarketCount(Symbol(),MagicNumber) > 0)
{
CloseAllSellOrders(Symbol(),MagicNumber,Slippage);
}
// Open buy order
BuyTicket = OpenBuyOrder(Symbol(),LotSize,UseSlippage,MagicNumber);