Need some help with my codes. Keep getting [Invalid Price] error in the Journal

 

Hi, when I backtested my codes, some of the trades went through, but a bunch of them keeps returning the [Invalid Price] error in the Journal.

If someone can help me troubleshoot or give me some direction to work towards, that would be great.

This is my trade codes,

void OnTick(){
   double high = iHigh(_Symbol,PERIOD_CURRENT,1);
   double low = iLow(_Symbol,PERIOD_CURRENT,1);
   double open = iOpen(_Symbol,PERIOD_CURRENT,1);
   double close = iClose(_Symbol,PERIOD_CURRENT,1);
   
   double difference = high - low;
   
   if(open < close){
      //--- Open long order
      double slLevel = NormalizeDouble(high - difference,_Digits);
      double tpLevel = NormalizeDouble(high + difference,_Digits);
      
      datetime expiration = TimeCurrent() + (3 * 60 * 60);
      
      double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
      if(high < ask){
         trade.BuyLimit(1,high,_Symbol,slLevel,tpLevel,ORDER_TIME_SPECIFIED,expiration,"Buy Limit");
      }else if(high > ask){
         trade.BuyStop(1,high,_Symbol,slLevel,tpLevel,ORDER_TIME_SPECIFIED,expiration,"Buy Stop");
      }
   }else if(open > close){
      //--- Open short order
      double slLevel = NormalizeDouble(low + difference,_Digits);
      double tpLevel = NormalizeDouble(low - difference,_Digits);
      
      datetime expiration = TimeCurrent() + (3 * 60 * 60);
      
      double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
      if(low < bid){
         trade.SellLimit(1,low,_Symbol,slLevel,tpLevel,ORDER_TIME_SPECIFIED,expiration,"Bull Engulfing");
      }else if(low > bid){
         trade.SellStop(1,low,_Symbol,slLevel,tpLevel,ORDER_TIME_SPECIFIED,expiration,"Bull Engulfing");
      }
   }
}
 
Jerry Wee:

Hi, when I backtested my codes, some of the trades went through, but a bunch of them keeps returning the [Invalid Price] error in the Journal.

If someone can help me troubleshoot or give me some direction to work towards, that would be great.

This is my trade codes,

check SYMBOL_TRADE_FREEZE_LEVEL.

         if(entry<Bid-SYMBOL_TRADE_FREEZE_LEVEL*_Point)
            trade.SellStop(...)
Reason: