How to query if Stop Loss has been triggered
- Mql4 code to check if current order has been closed
- How to get the previous Stop Loss of the opened position?
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
- Some (not all) brokers modify the comment, usually adding "[SL]"
bool wasBySL = MathAbs( OrderClosePrice() - OrderStopLoss() ) < MathAbs( OrderClosePrice() - OrderTakeProfit() );
Remember that stops become market orders, and there will be slippage. So OCP < OSL will not work.
- Some (not all) brokers modify the comment, usually adding "[SL]"
- Remember that stops become market orders, and there will be slippage. So OCP < OSL will not work.
Thanks but i guess this will only work for MT4? Found no mql5 reference to commands like OrderClosePrice() ?
Please read the following thread for the MQL5 explanation: https://www.mql5.com/en/forum/130
- 2009.12.09
- www.mql5.com
Please read the following thread for the MQL5 explanation: https://www.mql5.com/en/forum/130
Ok digged it out by myself, here some code for the records (a script)
void OnStart() { datetime to = TimeCurrent(); datetime from = to - PeriodSeconds(PERIOD_D1); // check deals for the current day ResetLastError(); if(! HistorySelect(from, to)) Print(__FUNCTION__, " HistorySelect=false. Error code=", GetLastError()); unsigned int numOrders = HistoryOrdersTotal(); unsigned long ticket = HistoryOrderGetTicket(numOrders - 1); ENUM_ORDER_REASON reason = 0; if(HistoryOrderSelect(ticket)) reason = HistoryOrderGetInteger(ticket, ORDER_REASON); if(EnumToString(reason) == "ORDER_REASON_SL") Print("ticket ", ticket, " triggered SL"); }
Why is this thread in the
MQL4 section, (bottom of the Root page?) Instead of Root /
MT5 EA section?
Next time post in the correct place. The moderators will likely move this
thread there soon.
Ok digged it out by myself, here some code for the records (a script)
You can use this function:
void OnTradeTransaction(const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result) { }
- www.mql5.com