Trailing Stop not Working Properly on VPS but Works Just Fine on Backtesting

 
Hi, 

I have an EA that open and closes positions, but my trailing stop and breakeven isn't working properly on VPS, but it works just as expected when backtesting
void trailSlAndBreakEven(void) {
   for (int i = 0; i < PositionsTotal(); i++) {
      ulong posTicket = PositionGetTicket(i);

      if (PositionGetSymbol(POSITION_SYMBOL) != _Symbol) continue;
      if (PositionGetInteger(POSITION_MAGIC) != Magic) continue;

      double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
      doublB ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);

      double posPriceOpen = PositionGetDouble(POSITION_PRICE_OPEN);
      double posSl = PositionGetDouble(POSITION_SL);
      double posTp = PositionGetDouble(POSITION_TP);

      if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) {
         // Trailing Stop
         if (TrailingOn && bid > posPriceOpen + TslTriggerPoints * _Point) {
            double sl = bid - TslPoints * _Point;
            sl = NormalizeDouble(sl, _Digits);

            if (sl > posSl) {
               trade.PositionModify(posTicket, sl, posTp);
            }
         }
         // Breakeven Stop for Buy positions
         if (BreakEven && bid >= posPriceOpen + BreakEvenPoints * _Point) {
            double sl = posPriceOpen;
            sl = NormalizeDouble(sl, _Digits);

            if (sl > posSl) {
               trade.PositionModify(posTicket, sl, posTp);
            }
         }
      } else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) {
         // Trailing Stop
         if (TrailingOn && ask < posPriceOpen - TslTriggerPoints * _Point) {
            double sl = ask + TslPoints * _Point;
            sl = NormalizeDouble(sl, _Digits);

            if (sl < posSl || posSl == 0) {
               trade.PositionModify(posTicket, sl, posTp);
            }
         }
         // Breakeven Stop for Sell positions
         if (BreakEven && ask <= posPriceOpen - BreakEvenPoints * _Point) {
            double sl = posPriceOpen;
            sl = NormalizeDouble(sl, _Digits);

            if (sl < posSl || posSl == 0) {
               trade.PositionModify(posTicket, sl, posTp);
            }
         }
      }
   }
}


BACKTEST

Backtest               


REAL ON VPS

REAL ON VPS

 

1. Check VPS log for possible errors when modifying position stop loss.

2. Use backtest with real ticks and exact same inputs setting.

3. Make sure to run the EA with the exact same symbol.

note: posSL==0 condition is not checked for BUY positions.

 
Yashar, thank you for your comment.

The weird thing is that yesterday it didn't work, but today it just worked on VPS. I didn't change anything. 
Is it a problem to have the terminal open while the trade is going on a VPS?
 
Artur Alves De Carvalho #:
Yashar, thank you for your comment.

The weird thing is that yesterday it didn't work, but today it just worked on VPS. I didn't change anything. 
Is it a problem to have the terminal open while the trade is going on a VPS?

I have had such problem with VPS that it worked after reloading. I guess this is because we are not well familiar with VPS setup.