ORDER_TP and ORDER_SL not reflected by OrderGetDouble or HistoryOrderGetDouble when applied after initial placing

 

Situation: I have an EA which lists on each <onTrade> all orders and history orders since last scan.

The code of <onTrade>

 ulong ticket=0;


  string    property_val="";

   /// loop over living orders
   for(int i=0;i < OrdersTotal();i++)
   {
      ticket=OrderGetTicket(i);
      if(ticket > 0)
         property_val=  DoubleToString(OrderGetDouble(ORDER_TP));
   }

   /// loop over history orders
   HistorySelect(_dtLastHistoryScan,TimeCurrent());
   for(int j=0;j < HistoryOrdersTotal();j++)
   {
      ticket=HistoryOrderGetTicket(j);

      if(ticket > 0)

           property_val=  DoubleToString(HistoryOrderGetDouble(ticket,ORDER_SL));

       

   }

   _dtLastHistoryScan=TimeCurrent()-1;



property_val always "0.0". The price can always retrieved this way, also ordertype etc. But not stop and / or loss.

This happens only, when first place a BUY/SELL order, then change it by attaching stop and or loss.

Stop and / or loss can be seen in trade-tab; but not in property val.

Can anyone help how to get stop and loss for those orders ?

Thank you

Documentation on MQL5: Trade Functions / HistorySelect
  • www.mql5.com
Trade Functions / HistorySelect - Documentation on MQL5
 

As a summary: it seems, for buy or sell orders (market or instant orders) you can't retrieve stop or profit value by calling

HistoryOrderGetDouble or OrderGetDouble, even if initially selected. Then, if you modify stop or loss, values listed are stale.

The trade-tab shows correct values.  Code below demonstrates this. To check it out, please create a script and overwrite onStart.

Then place a buy market order. Attach stop and loss. Change stop and loss and check if stop and loss reflected by script.


//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   ulong ticket=0;
   string line="";
   Print("--- pending ---");
   /// loop over living orders
   for(int i=0;i < OrdersTotal();i++)
   {
      ticket=OrderGetTicket(i);
      if(ticket > 0)
      {
        if(OrderSelect(ticket) == true)
        {
            line="stop=" +  DoubleToString(OrderGetDouble(ORDER_SL));
            line = line + " target=" + DoubleToString(OrderGetDouble(ORDER_TP));
            Print(line);
        }
        else
            Print("OrderSelect failed");
      }
   }

   Print("--- history ---");
   /// loop over history orders
   HistorySelect(0,TimeCurrent());
    uint total=HistoryOrdersTotal();
   for(uint j=0;j < total;j++)
   {
      ticket=HistoryOrderGetTicket(j);
      if(ticket > 0)
      {
        line="stop=" +  DoubleToString(HistoryOrderGetDouble(ticket,ORDER_SL));
        line = line + " target=" + DoubleToString(HistoryOrderGetDouble(ticket,ORDER_TP));
        Print(line);
      }
   }


}
//+------------------------------------------------------------------+



any help appreciated.

Documentation on MQL5: Trade Functions / HistorySelect
  • www.mql5.com
Trade Functions / HistorySelect - Documentation on MQL5
 

Important comment: i checked this out with MT4. MT4 always allows to retrieve latest stop and target value.

->

OrderSelect(index,SELECT_BY_POS,MODE_TRADES);

DoubleToStr(OrderTakeProfit();

DoubleToStr(OrderStopLoss();


So, i claim, this has to be considered as BUG in MetaTrader5

 
I'm quite sure you have to be checking position's stop-loss and take-profit, not order's.
 
Hi Guys, I consider with this problem too, it is still a BUG in MT5!
 
https://www.mql5.com/en/forum/240232
Why TP and SL levels are not visible in MT5 history?
Why TP and SL levels are not visible in MT5 history?
  • 2018.04.24
  • www.mql5.com
I wonder why MT5 offers less information about the details of a trade in history than its predecessor...
Reason: