ORDER_TP and ORDER_SL not reflected by OrderGetDouble or HistoryOrderGetDouble when applied after initial placing
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.
- www.mql5.com
- 2018.04.24
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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