invalid stops

 

hi guys . I made an ea that in backtest does good , but when I trade it on a live account it say invalid stop. why? (backtest made on realtick)

thanks

 
manucaaa:

hi guys . I made an ea that in backtest does good , but when I trade it on a live account it say invalid stop. why? (backtest made on realtick)

thanks

Forum on trading, automated trading systems and testing trading strategies

Unable to place order because of invalid stops

Automated-Trading, 2013.10.23 17:13

1. Use ZeroMemory before preparing MqlTradeRequest structure.

2. Calculate TP/SL levels relative to Bid/Ask levels.

void OnStart()
  {
//---
   MqlTradeRequest request;
   MqlTradeResult result;
   ZeroMemory(request);
   request.symbol      =Symbol();
   request.volume      =0.1;
   request.deviation   =1;
   request.type_filling=ORDER_FILLING_FOK;
   request.action=TRADE_ACTION_DEAL;
   double askPrice   = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
   double bidPrice   = SymbolInfoDouble(Symbol(),SYMBOL_BID);
   long stopLevels=SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL);
   request.type = ORDER_TYPE_BUY;
   request.sl   = NormalizeDouble(bidPrice - stopLevels * Point(),_Digits);
   request.tp   = NormalizeDouble(askPrice + stopLevels * Point(),_Digits);
   request.price= askPrice;
   if (!OrderSend(request,result)) {Print("Error=", GetLastError());}
  }

it could also be a freeze level (FreezeLevel - CSymbolInfo - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5.
Documentation on MQL5: Standard Library / Trade Classes / CSymbolInfo / FreezeLevel
Documentation on MQL5: Standard Library / Trade Classes / CSymbolInfo / FreezeLevel
  • www.mql5.com
Gets the freeze level (in points). Return Value Distance of freeze level (in points). Note The symbol should be selected by Name method.  ...