Hello guys,
Iam pretty new to this MQL5 coding, but I manage to make my own EA in last 3 days and it seems to be working very well. Iam now fixing some issues to improve the EA.
My problem is that when is one trade closed by stoploss then alogirthm open new trade in current cadle (if coditions allow).
This is the way i can loose multiple trades in one candle. On the other hand it works with takeprofit the same (but I would like to keep this takeprofit issue - its the way to make more profit in one candle).
I have searched some articles and forum topics about this issue, I found only the way how to stop multiple trades in one candle, but not
how to stop them if first trade hit stoploss only. I have read about HistoryDealGetInteger()
function, about DEAL_REASOn and about DEAL_REASON_SL, BUT it is too hard for me to
understand the syntax and how to manage with this code. Or there is another way ?
Do you have any idea? Please help, Iam despered right now :/
Thank you very much.
It sounds to me as if you are looking for a conditional time delay? If your position got closed by a profit taker you want to enable a next trade immediately. But if your position got closed by a stoploss you want to wait until the start of a next candle?
If this is indeed what you want then you need to calculate the time remaining on the current candle and use that as waiting time for your next
trade, if the position got closed by stoploss.
It sounds to me as if you are looking for a conditional time delay? If your position got closed by a profit taker you want to enable a next trade immediately. But if your position got closed by a stoploss you want to wait until the start of a next candle?
If this is indeed what you want then you need to calculate the time remaining on the current candle and use that as waiting time for your next
trade, if the position got closed by stoploss.
if(UpTrend) { if(lastbartime!=bartime) if(CanOrder && UpSignal) OpenNew(OP_BUY); lastbartime=bartime; }
This is I got so far. But it prevent multiple trades in single bar after stop loss or take profit is taken. How to solve the same only for stop loss ?
Thank you
This is I got so far. But it prevent multiple trades in single bar after stop loss or take profit is taken. How to solve the same only for stop loss ?
Thank you
I would approach this in a slightly different way. I would first monitor the open order and see which one gets filled: stoploss or profit taker. Based on that would I decide on how long to wait until the next new order. In pseudo-code:
if(OrderExecuted) { if(ProfittakerExecuted) { Delaytime = 0; //allow opening a new order immediately } if(StoplossExecuted) { Delaytime = calculateTimeDifference(Currenttime, BarSize);//calculate the time until the current bar ends //allow opening a new position after this delay time has passed } }
But there are of course multiple ways to solve a challenge.
I would approach this in a slightly different way. I would first monitor the open order and see which one gets filled: stoploss or profit taker. Based on that would I decide on how long to wait until the next new order. In pseudo-code:
But there are of course multiple ways to solve a challenge.
Thank you for your reply and code.
Please, can you give me exaple of code for bool "ProfittakerExecuted" or "StoplossExecuted" ? This is the part of the task I cannot handle myself...
- Don't open if you already have a trade open.
- 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 #1
- Don't open if you already have a trade open.
- 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 #1
I think you didnt understand me. I do not have problem with opening two trades in same tame. There is only one open trade, no more.
I dont want to go that way because it would also affect take profit trades in single candle.

- www.mql5.com
Thank you for your reply and code.
Please, can you give me exaple of code for bool "ProfittakerExecuted" or "StoplossExecuted" ? This is the part of the task I cannot handle myself...

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello guys,
Iam pretty new to this MQL5 coding, but I manage to make my own EA in last 3 days and it seems to be working very well. Iam now fixing some issues to improve the EA.
My problem is that when is one trade closed by stoploss then alogirthm open new trade in current cadle (if coditions allow).
This is the way i can loose multiple trades in one candle. On the other hand it works with takeprofit the same (but I would like to keep this takeprofit issue - its the way to make more profit in one candle).
I have searched some articles and forum topics about this issue, I found only the way how to stop multiple trades in one candle, but not how to stop them if first trade hit stoploss only. I have read about HistoryDealGetInteger() function, about DEAL_REASOn and about DEAL_REASON_SL, BUT it is too hard for me to understand the syntax and how to manage with this code. Or there is another way ?
Do you have any idea? Please help, Iam despered right now :/
Thank you very much.