Invalid stops only in JPY currency pair

 

Having trouble to opening sell trade on all currency that the second currency is JPY (AUDJPY, NZDJPY, etc).

  • I've check stop level
  • I've check freeze level
  • I've check calculated lot against min lot
  • I've check stoploss price above open price and take profit price
  • I've check take profit price below open price and stoploss price

The error code is 4756 and the trade server error is 10016 which is invalid stops. Here's the log of the problem trade,

LH 0 09:12:51.596 Core 1 2023.05.08 04:24:20   ===== TRADE PARAMETER >>>>> Symbol: AUDJPY, Volume: 0.15, Price: 90.997, sl: 91.0015, tp: 90.98350000000002, magic number: 2090

MQ 2 09:12:51.596 Core 1 2023.05.08 04:24:20   failed market sell 0.15 AUDJPY sl: 91.002 tp: 90.984 [Invalid stops]

FN 0 09:12:51.596 Core 1 2023.05.08 04:24:20   CTrade::OrderSend: market sell 0.15 AUDJPY sl: 91.001 tp: 90.984 [invalid stops]

LM 0 09:12:51.596 Core 1 2023.05.08 04:24:20   ===== ERROR - failed to open sell position with error code 4756 and trade result error 10016 = invalid stops =====

KP 0 09:12:51.596 Core 1 2023.05.08 04:24:20   request result: Direction=buy Price=90.99700 SL=91.00150 TP=90.98350 TypeFilling=fill or kill

DM 0 09:12:51.596 Core 1 2023.05.08 05:10:20   ===== TRADE PARAMETER >>>>> Symbol: NZDJPY, Volume: 0.13, Price: 84.915, sl: 84.92, tp: 84.90500000000002, magic number: 2090

PD 2 09:12:51.596 Core 1 2023.05.08 05:10:20   failed market sell 0.13 NZDJPY sl: 84.920 tp: 84.905 [Invalid stops]

ND 0 09:12:51.596 Core 1 2023.05.08 05:10:20   CTrade::OrderSend: market sell 0.13 NZDJPY sl: 84.920 tp: 84.905 [invalid stops]

DG 0 09:12:51.596 Core 1 2023.05.08 05:10:20   ===== ERROR - failed to open sell position with error code 4756 and trade result error 10016 = invalid stops =====

QK 0 09:12:51.596 Core 1 2023.05.08 05:10:20   request result: Direction=buy Price=84.91500 SL=84.92000 TP=84.90500 TypeFilling=fill or kill

Here's the code to open the trade,

if(open_signal == OPEN_SHORT) {
        price = tick.bid;
        sl = tick.bid + Stoploss * PointValue();
        tp = tick.bid - (TakeProfit * (sl - price));

        // calculate volume
      switch (VolumeMethod) {
      case VOLUME_MODE_FIXED :
         volume = Volume;
         break;
      case VOLUME_MODE_MONETARY_VALUE :
         volume = NormalizeDouble(SymbolInfoDouble(CurrentSymbol, SYMBOL_VOLUME_MIN) * (AccountInfoDouble(ACCOUNT_EQUITY) / Volume), 2);
         break;
      case VOLUME_MODE_EQUITY_RISK_PCT : {
         double riskAmount = AccountInfoDouble(ACCOUNT_EQUITY) * Volume / 100;
         double riskPoints = SLCoef[SymbolLoop];

         double tickSize = SymbolInfoDouble(CurrentSymbol, SYMBOL_TRADE_TICK_SIZE);
         double tickValue = SymbolInfoDouble(CurrentSymbol, SYMBOL_TRADE_TICK_VALUE);

         double ticksPerPoint = tickSize/SymbolInfoDouble(CurrentSymbol, SYMBOL_POINT);
         double pointValue = tickValue/ticksPerPoint;

         volume = NormalizeDouble(riskAmount/(pointValue*riskPoints), 2);
         break;
      }
      }
      //... check lot size against min and max lot size
      volume = MathMin(volume, SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MAX));
      volume = MathMax(volume, SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN));

      //... check lot size against min and max lot size
      volume = MathMin(volume, SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MAX));
      volume = MathMax(volume, SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN));

      //... check stoplevel and freeze level
      if(SymbolInfoInteger(CurrentSymbol, SYMBOL_TRADE_FREEZE_LEVEL) > SLCoef[SymbolLoop] || SymbolInfoInteger(CurrentSymbol, SYMBOL_TRADE_FREEZE_LEVEL) > TPCoef[SymbolLoop]) {
         Print("===== ERROR - SL or TP less then freeze level =====");
         return;
      }
      if(SymbolInfoInteger(CurrentSymbol, SYMBOL_TRADE_STOPS_LEVEL) > SLCoef[SymbolLoop] || SymbolInfoInteger(CurrentSymbol, SYMBOL_TRADE_STOPS_LEVEL) > TPCoef[SymbolLoop]) {
         Print("===== ERROR - SL or TP less then stop level =====");
         return;
      }

      trade.SetDeviationInPoints(Slippage);
      trade.SetExpertMagicNumber(MagicNumber);
      Print("===== TRADE PARAMETER >>>>> Symbol: ", CurrentSymbol, ", Volume: ", volume, ", Price: ", price, ", sl: ", sl, ", tp: ", tp, ", magic number: ", MagicNumber);
      if(!trade.Sell(volume, CurrentSymbol, price, sl, tp)) {
         Print("===== ERROR - failed to open sell position with error code ", GetLastError(), " and trade result error ", trade.ResultRetcode(), " = ", trade.ResultRetcodeDescription(), " =====");
         PrintFormat("request result: Direction=%s Price=%.5lf SL=%.5lf TP=%.5lf TypeFilling=%s", trade.RequestTypeDescription(), trade.RequestPrice(), trade.RequestSL(), trade.RequestTP(),                   trade.RequestTypeFillingDescription());
      }
}

I think I've check all the things that will resulting in 'invalid stops' error, do I missed something here?

NB: 1. Sl and Tp using bid price to have equal distance, and it still close at close price.

2. Adding NormalizeDouble() doesn't help since the price already normalize on trade server.

 
Have solve the problem