In MQL5, get ticket number of order that just hit take profit

In MQL5, get ticket number of order that just hit take profit

Manage alerts

Loading saved threads...

rerat · External communityPost link
External question — Stack Overflow Stack Exchange Author: rerat Original post: https://stackoverflow.com/questions/72399495 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I have an EA and I am easily able to detect a TP or SL, but I am not able to determine what ticket number hit the TP or SL. Seems so easy, but it's really giving me trouble. Here is the working code that shows an alert when a trade hits the TP, but I need it to show which ticket number hit the TP. void OnTradeTransaction(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result){ ENUM_TRADE_TRANSACTION_TYPE type=trans.type; //--- if transaction is result of addition of the transaction in history if(type==TRADE_TRANSACTION_DEAL_ADD){ if(HistoryDealSelect(trans.deal)){ m_deal.Ticket(trans.deal); } else { Print(__FILE__," ",__FUNCTION__,", ERROR: HistoryDealSelect(",trans.deal,")"); return; } long reason=-1; if(!m_deal.InfoInteger(DEAL_REASON,reason)){ Print(__FILE__," ",__FUNCTION__,", ERROR: InfoInteger(DEAL_REASON,reason)"); return; } if((ENUM_DEAL_REASON)reason==DEAL_REASON_SL){ Alert("Stop Loss activation"); } else { if((ENUM_DEAL_REASON)reason==DEAL_REASON_TP){ //SHOW TICKET NUMBER } } } }
Quote
Report
rerat · External communityPost link
External answer — Stack Overflow Stack Exchange Author: rerat Original post: https://stackoverflow.com/a/72408411 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Alert(trans.position) is the solution.
Quote
Report
simon · External communityPost link
External answer — Stack Overflow Stack Exchange Author: simon Original post: https://stackoverflow.com/a/78365185 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. these changes should do if((ENUM_DEAL_REASON)reason==DEAL_REASON_SL){ Alert("Stop Loss activated for position with ticket ==> ",trans.position ); } else { if((ENUM_DEAL_REASON)reason==DEAL_REASON_TP){ Alert("Take profit activated for position with ticket ==> ", trans.position ); } }
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: rerat Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/72408411 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Alert(trans.position) is the solution.

Cancel quote

Checking account access…