Modify order works in Backtest and Debug but not in Live

 
Hi, I have a demo account in admiral and the same bot works fine when backtesting and debugging with historical data in DAX,DJI,SP500. But in live, I cannot modify the position. I get 10013 error. The code is Andrew Young's library.

if(glBuyTicket > 0)
{
    double openPrice = PositionOpenPrice(glBuyTicket);
  
    double buyStop = BuyStopLoss(_Symbol,StopLoss,openPrice);
    if(buyStop > 0) AdjustBelowStopLevel(_Symbol,buyStop);
  
    double buyProfit = BuyTakeProfit(_Symbol,TakeProfit,openPrice);
    if(buyProfit > 0) AdjustAboveStopLevel(_Symbol,buyProfit);
  
    if(buyStop > 0 || buyProfit > 0) Trade.ModifyPosition(glBuyTicket,buyStop,buyProfit);
    glSellTicket = 0;
    glBuyPlaced = true;
}

bool CTradeHedge::ModifyPosition(ulong pTicket, double pStop, double pProfit=0.000000)
{
    ZeroMemory(request);
    ZeroMemory(result);
   
    bool select = PositionSelectByTicket(pTicket);
    string symbol = PositionGetString(POSITION_SYMBOL);
    long digits = SymbolInfoInteger(_Symbol,SYMBOL_DIGITS);
    pStop = NormalizeDouble(pStop,(int)digits);
    pProfit = NormalizeDouble(pProfit,(int)digits);
    request.action = TRADE_ACTION_SLTP;
    request.sl = pStop;
    request.tp = pProfit;
    request.position = pTicket;
    request.symbol = symbol;

I use the same library successfully with other bots and in FX they work fine.
These are the error messages:

Open buy order #1052070433: 10009 - Request is completed, Volume: 1.0, Price: 0.0
Alert: Modify position: Error 10013 - Invalid request
MqlTradeRequest - action:6, comment:, deviation:0, expiration:1970.01.01 00:00:00, magic:0, order:0, position:1052070433, position_by:0, price:0.0, ls:3233.2, stoplimit:0.0, symbol:, tp:3273.2, type:0, type_filling:0, type_time:0, volume:0.0
MqlTradeResult - ask:0.0, bid:0.0, comment:Invalid request, deal:0, order:0, price:0.0, request_id:0, retcode:10013, retcode_external:0, volume:0.0
Modify position #1052070433: 10013 - Invalid request, SL: 3233.2, TP: 3273.2, Bid: 3252.8, Ask: 3253.2, Stop Level: 0
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
, then each symbol positions will be closed in the same order, in which they are opened, starting with the oldest one. In case of an attempt to close positions in a different order, the trader will receive an appropriate error. There are several types of accounts that can be opened on a trade server. The type of account on which an MQL5 program...