I need to know if an order is stopped by a stoploss or take profit. by the server.
I think it is possible in the event OnTradeTransaction () but I can not find the right syntax and magic ticket and order ticket = 0?
This nice article may help you too: https://www.mql5.com/en/articles/211
- 2011.02.01
- MetaQuotes Software Corp.
- www.mql5.com
thank's
i use this code but in cannot read the ticket to read ithe closed order n the history
an idea ?
//+------------------------------------------------------------------+ //| OnTradeTransaction.mqh | //| Copyright 2014, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, MetaQuotes Software Corp." #property link "http://www.mql5.com" //+------------------------------------------------------------------+ //| defines | //+------------------------------------------------------------------+ // #define MacrosHello "Hello, world!" // #define MacrosYear 2010 //+------------------------------------------------------------------+ //| DLL imports | //+------------------------------------------------------------------+ // #import "user32.dll" // int SendMessageA(int hWnd,int Msg,int wParam,int lParam); // #import "my_expert.dll" // int ExpertRecalculate(int wParam,int lParam); // #import //+------------------------------------------------------------------+ //| EX5 imports | //+------------------------------------------------------------------+ // #import "stdlib.ex5" // string ErrorDescription(int error_code); // #import //+------------------------------------------------------------------+ if (_Symbol!=trans.symbol) return; if (result.retcode == TRADE_RETCODE_DONE) AffGrosMessage("C'est un ordre serveur !!!!!!!!!!!"); //--- get transaction type as enumeration value ENUM_TRADE_TRANSACTION_TYPE type=(ENUM_TRADE_TRANSACTION_TYPE)trans.type; //--- if the transaction is the request handling result, only its name is displayed // if(type==TRADE_TRANSACTION_REQUEST) // { Print(EnumToString(type)); //--- display the handled request string name Print("------------RequestDescription\r\n",RequestDescription(request)); //--- display request result description Print("------------ResultDescription\r\n",TradeResultDescription(result)); //--- store the order ticket for its deletion at the next handling in OnTick() if(result.order!=0) { //--- delete this order by its ticket at the next OnTick() call // order_ticket=result.order; // Print(" Pending order ticket ",order_ticket,"\r\n"); } } // else // display the full description for transactions of another type //--- display description of the received transaction in the Journal // Print("------------TransactionDescription\r\n",TransactionDescription(trans)); //--- // } //+------------------------------------------------------------------+ //| Returns transaction textual description | //+------------------------------------------------------------------+ string TransactionDescription(const MqlTradeTransaction &trans) { //--- string desc=EnumToString(trans.type)+"\r\n"; desc+="Symbol: "+trans.symbol+"\r\n"; desc+="Deal ticket: "+(string)trans.deal+"\r\n"; desc+="Deal type: "+EnumToString(trans.deal_type)+"\r\n"; desc+="Order ticket: "+(string)trans.order+"\r\n"; desc+="Order type: "+EnumToString(trans.order_type)+"\r\n"; desc+="Order state: "+EnumToString(trans.order_state)+"\r\n"; desc+="Order time type: "+EnumToString(trans.time_type)+"\r\n"; desc+="Order expiration: "+TimeToString(trans.time_expiration)+"\r\n"; desc+="Price: "+StringFormat("%G",trans.price)+"\r\n"; desc+="Price trigger: "+StringFormat("%G",trans.price_trigger)+"\r\n"; desc+="Stop Loss: "+StringFormat("%G",trans.price_sl)+"\r\n"; desc+="Take Profit: "+StringFormat("%G",trans.price_tp)+"\r\n"; desc+="Volume: "+StringFormat("%G",trans.volume)+"\r\n"; //--- return the obtained string return desc; } //+------------------------------------------------------------------+ //| Returns the trade request textual description | //+------------------------------------------------------------------+ string RequestDescription(const MqlTradeRequest &request) { //--- string desc=EnumToString(request.action)+"\r\n"; desc+="Symbol: "+request.symbol+"\r\n"; desc+="Magic Number: "+StringFormat("%d",request.magic)+"\r\n"; desc+="Order ticket: "+(string)request.order+"\r\n"; desc+="Order type: "+EnumToString(request.type)+"\r\n"; desc+="Order filling: "+EnumToString(request.type_filling)+"\r\n"; desc+="Order time type: "+EnumToString(request.type_time)+"\r\n"; desc+="Order expiration: "+TimeToString(request.expiration)+"\r\n"; desc+="Price: "+StringFormat("%G",request.price)+"\r\n"; desc+="Deviation points: "+StringFormat("%G",request.deviation)+"\r\n"; desc+="Stop Loss: "+StringFormat("%G",request.sl)+"\r\n"; desc+="Take Profit: "+StringFormat("%G",request.tp)+"\r\n"; desc+="Stop Limit: "+StringFormat("%G",request.stoplimit)+"\r\n"; desc+="Volume: "+StringFormat("%G",request.volume)+"\r\n"; desc+="Comment: "+request.comment+"\r\n"; //--- return the obtained string return desc; } //+------------------------------------------------------------------+ //| Returns the textual description of the request handling result | //+------------------------------------------------------------------+ string TradeResultDescription(const MqlTradeResult &result) { //--- string desc="Retcode "+(string)result.retcode+"\r\n"; desc+="Request ID: "+StringFormat("%d",result.request_id)+"\r\n"; desc+="Order ticket: "+(string)result.order+"\r\n"; desc+="Deal ticket: "+(string)result.deal+"\r\n"; desc+="Volume: "+StringFormat("%G",result.volume)+"\r\n"; desc+="Price: "+StringFormat("%G",result.price)+"\r\n"; desc+="Ask: "+StringFormat("%G",result.ask)+"\r\n"; desc+="Bid: "+StringFormat("%G",result.bid)+"\r\n"; desc+="Comment: "+result.comment+"\r\n"; //--- return the obtained string return desc;
thank's
i use this code but in cannot read the ticket to read ithe closed order n the history
an idea ?
Hello,
As RaptorUK already said you, with MT5 only a position can be closed by SL. I suggest you to read again the article which Figurelli gives you the link.
If you need help with your code you have to post code that compiles and has a meaning, what's the meaning of the code you posted ?
There are mainly 2 ways to detect that a position was closed by SL :
- If you had an open position and it is now closed, check the history of deals to find the closing price of your position. This is the standard approach.
- Use OnTradeTransaction to detect changes in your position "on the fly". But it's an advanced technique.
My code is a example MT5 from doc
it shows the structure MQLTradeTransaction and MQLTradeResult
but i don"t find the ticket of the closed order
- Use OnTradeTransaction to detect changes in your position "on the fly". But it's an advanced technique.
i'am interested by :
- Use OnTradeTransaction to detect changes in your position "on the fly". But it's an advanced technique.
i think i have understood..
i have to scan order in history with the filter symbol to find the caratéristics of the deal
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to know if an order is stopped by a stoploss or take profit. by the server.
I think it is possible in the event OnTradeTransaction () but I can not find the right syntax and magic ticket and order ticket = 0?