Hello! Help please, how can determine that the last two orders were closed by StopLoss?
#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006 // Возврат тикетов последних Amount-сделок, закрытых по Reason-причине int GetLastHistoryPositions( long &Tickets[], int Amount = INT_MAX, const ENUM_DEAL_REASON Reason = DEAL_REASON_SL ) { int Count = ArrayResize(Tickets, 0); for (int i = OrdersHistoryTotal() - 1; (i >= 0) && (Count < Amount); i--) if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderCloseReason() == Reason)) Tickets[ArrayResize(Tickets, ++Count) - 1] = OrderTicket(); return(Count); } void OnStart() { long Tickets[]; // Последние две сделки, закрытые по SL for (int i = GetLastHistoryPositions(Tickets, 2) - 1; i >= 0; i--) Print(Tickets[i]); }
Addon for MT4
enum ENUM_DEAL_REASON { DEAL_REASON_CLIENT, DEAL_REASON_SL, DEAL_REASON_TP }; ENUM_DEAL_REASON OrderCloseReason( void ) { return((StringFind(OrderComment(), "[sl]") != -1) ? DEAL_REASON_SL : ((StringFind(OrderComment(), "[tp]") != -1) ? DEAL_REASON_TP : DEAL_REASON_CLIENT)); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register