Order comment not showing !

 

Hello

using this code everything appears fine but the order comment  from the string

TradeComment

is not shown at all

any idea what could be wrong ??


// variables
string DayStart = "00:00"; // Day Start Time
double LastClosed_Profit; // Last Closed trade profit
string TradeSymbol, TradeType, TradeComment;


void OnTick()
  {
   CheckLastClosed();
  }


void CheckLastClosed()
{
   datetime HistoryTime = StringToTime(DayStart);

   if(HistorySelect(HistoryTime,TimeCurrent()))
     {
      int Total = HistoryDealsTotal();
      ulong Ticket = HistoryDealGetTicket(Total -1);

      LastClosed_Profit = NormalizeDouble(HistoryDealGetDouble(Ticket,DEAL_PROFIT),2);
      TradeSymbol       = HistoryOrderGetString(Ticket,ORDER_SYMBOL);
      TradeComment      = HistoryOrderGetString(Ticket,ORDER_COMMENT);

      if(HistoryDealGetInteger(Ticket,DEAL_TYPE) == DEAL_TYPE_BUY)    {TradeType = "Sell Trade"; }
      if(HistoryDealGetInteger(Ticket,DEAL_TYPE) == DEAL_TYPE_SELL)   {TradeType = "Buy Trade";  }

      // chart out put.
      Comment("\n","Deals Total - :  ", Total,
              "\n","Last Deal Ticket - :  ", Ticket,
              "\n", "Last Closed Profit -:  ", LastClosed_Profit,
              "\n", "Last Closed COMMENT -:  ", TradeComment  ,
              "\n", "Last Trade was -:  ", TradeType);
     }
}
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be...
 
Mohamed Mostafa Mohamed Sonbol:

Hello

using this code everything appears fine but the order comment  from the string

is not shown at all

any idea what could be wrong ??


As you're using HistoryDealGetTicket, try using DEAL_COMMENT from the deal history pool.

 
    TradeSymbol       = HistoryOrderGetString(Ticket,ORDER_SYMBOL);
      TradeComment      = HistoryOrderGetString(Ticket,ORDER_COMMENT);
You selected a deal, not an order.
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

It depends on the broker. 

Some brokers simply don´t accept order-comments and use such for their own needs.