- Read the last closed order and decide
enableopen = true; for(int iPos=OrdersHistoryTotal()-1; iPos >= 0 ; iPos--) if ( OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderMagicNumber() == Magic.Number // my magic number && OrderSymbol() == chart.symbol // and my pair. && OrderType() <= OP_SELL// Avoid cr/bal https://www.mql5.com/en/forum/126192 ){ if (MathAbs( OrderStopLoss() - OrderClosePrice() ) < pips2dbl) enableopen=false; break; }
- Remove an EA through MQL4 code - MQL4 forum
Hi, many thanks!
Two clarifications please: 1) what is pips2dbl - I gather this is a sort of finetuneing of pip digits (?) or why not just use something orderstoploss = ordercloseprice? ; 2) and also, more importantly, the current logic suspends the EA indefinitely, I am aiming to have it suspended ONLY UNTIL a new condition is met, when enableopen = true again, say, for sake of argument till a certain time of the day/.
Thanks!
Dan
- "what is pips2dbl" because doubles rarely compare equal and orders will not be closed at exactly SL (except in the tester)
- "current logic suspends the EA indefinitely" That's what you asked for.
Stop trading after Stop-loss hit
- So MODIFY it.
No Slaves here, learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you.if ( !enableopen && conditionB) enableopen=true;
Thanks for your reply, I will look into what you posted and try to make it work.
To your point: learn - the way to go! easier said than done though : ) ; pay someone - I do respect coders' knowledge and I am paying for code - I clearly see the value. I only thought this would be just a simple tweak and I could do it myself w/ just a bit of guidance from in here, but it seems it aint quite so ! : )))
Thanks again for sharing!

- 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 forum,
I have a pretty cool EA from a programmer (I am quite new at this), by the good old logic:
if CONDITION A, open
if CONDITION B, close
but I would like to add a little tweak, as follows:
if CONDITION A, open
if:
1) CONDITION B, close; or
2) stop loss was reached BEFORE CONDITION B (order was closed automatically )
then suspend ea (enableopen=false? I guess) until CONDITION B
etc.
Can some one give some guidance translating this logic into code? If you know this has been discussed in another thread, please kindly post a link.
Best,
Dan.