Use
Gets the deal type |

Documentation on MQL5: Standard Library / Trade Classes / CDealInfo / DealType
- www.mql5.com
DealType - CDealInfo - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Shah Zeb # :
Please check the code, i am already using DealType but the problem is it return buy even if it's a sell deal.
Not!!! You are using
if(deal.Type == DEAL_TYPE_BUY){
a, you need to use
Gets the deal type |

Documentation on MQL5: Standard Library / Trade Classes / CDealInfo / DealType
- www.mql5.com
DealType - CDealInfo - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Please, insert code correctly: when editing a post, click
and paste your code in the popup window (the first time I edited your post and inserted the code correctly)


MQL5.community - User Memo
- www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
Use code:
//+------------------------------------------------------------------+ //| Expert1.mq5 | //| Copyright 2021, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" //--- #include <Trade\DealInfo.mqh> //--- CDealInfo m_deal; // object of CDealInfo class //--- input parameters //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- } //+------------------------------------------------------------------+ //| TradeTransaction function | //+------------------------------------------------------------------+ void OnTradeTransaction(const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result) { //--- get transaction type as enumeration value ENUM_TRADE_TRANSACTION_TYPE type=trans.type; //--- if transaction is result of addition of the transaction in history if(type==TRADE_TRANSACTION_DEAL_ADD) { ResetLastError(); if(HistoryDealSelect(trans.deal)) m_deal.Ticket(trans.deal); else { Print(__FILE__," ",__FUNCTION__,", ERROR: ","HistoryDealSelect(",trans.deal,") error: ",GetLastError()); return; } ENUM_DEAL_TYPE deal_type = m_deal.DealType(); ENUM_DEAL_ENTRY deal_entry = m_deal.Entry(); if(deal_type==DEAL_TYPE_BUY || deal_type==DEAL_TYPE_SELL) { long deal_reason=-1; if(!m_deal.InfoInteger(DEAL_REASON,deal_reason)) { Print(__FUNCTION__,", ERROR: InfoInteger(DEAL_REASON ..."); return; } if((ENUM_DEAL_REASON)deal_reason==DEAL_REASON_SL) { Print(__FUNCTION__,", DEAL_REASON_SL"); return; } if((ENUM_DEAL_REASON)deal_reason==DEAL_REASON_TP) { Print(__FUNCTION__,", DEAL_REASON_TP"); return; } } } } //+------------------------------------------------------------------+
Files:
Expert1.mq5
4 kb

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
I am trying to check deal type when a take profit triggered, i used deal.type method but it only return buy.