Download MetaTrader 5

Unable to place order because of invalid stops

To add comments, please log in or register
RudolfKrugstein
25
RudolfKrugstein 2013.10.23 12:56 

Hey,

 In an EA, I place orders like this:

 

MqlTradeRequest request;
MqlTradeResult result;
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);
int stopLevels = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL);
int stopDist = MathMax(stopLevels+1,50);
request.type = ORDER_TYPE_BUY;
request.sl   = NormalizeDouble(askPrice - stopDist * Point(),_Digits);
request.tp   = NormalizeDouble(askPrice + stopDist * Point(),_Digits);
request.price = askPrice;
OrderSend(request,result);

I always get as a result: "Invalid stops".

That is confusing, because my stops are at least "stopLevels+1" pips away from the price.

Any tips/Idea what is wrong?

Thanks!

Nathan

 Edit: Use SRC instead of CODE 

Moses Olawale  Ajayi
2398
Moses Olawale Ajayi 2013.10.23 13:03  

This may be due to your brokers spreads.exanples: If your broker spread is 3 and you set your stop to one, the ea won't open order till yur stop level is greater than 3.

Appart from that, your brokers may have predifine stop level: (some brokers don't allow their client to set stop loss level closer to the ask level. So, ask your prokers the numbers of pips you are to move away from the price level before setting stop loss.

Simon Gniadkowski
Moderator
18002
Simon Gniadkowski 2013.10.23 13:12  
RudolfKrugstein:

Hey,

 In an EA, I place orders like this:

 <CODE REMOVED>

I always get as a result: "Invalid stops".

That is confusing, because my stops are at least "stopLevels+1" pips away from the price.

Any tips/Idea what is wrong?

Thanks!

Nathan 

Please use the SRC button to post code: How to use the SRC button.

Do you know that you can send Stops with your Order ?  or do you need to send them afterwards ?  you need to check, click the following links for more info . . .

It depends on the symbol execution type  ( ENUM_SYMBOL_TRADE_EXECUTION ) if it's Market or Exchange execution then you don't send the open price,  if it's Request or Instant execution then you need to send the open price.

There is a little more info in this thread:  https://www.mql5.com/en/forum/11303  

RudolfKrugstein
25
RudolfKrugstein 2013.10.23 13:54  

Hey,

 Well, when I change the line

int stopDist = MathMax(stopLevels+1,50);

 to

int stopDist = MathMax(stopLevels+1,100);

 (so I the TP and SL will be set 100 pips away from the price), it works!

 So my TP and SL are to close to the price, and that is what is confusing me. I though that  stopDist = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL); would return a number of pips, that is enough for setting TP and SL.

Am I wrong?

 

Thanks!

Nathan 

Alain Verleyen
Moderator
31085
Alain Verleyen 2013.10.23 14:11  
RudolfKrugstein:

Hey,

 Well, when I change the line

 to

 (so I the TP and SL will be set 100 pips away from the price), it works!

 So my TP and SL are to close to the price, and that is what is confusing me. I though that  stopDist = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL); would return a number of pips, that is enough for setting TP and SL.

Am I wrong?

 

Thanks!

Nathan 

Sometimes SYMBOL_TRADE_STOPS_LEVEL  return 0, but your stop still have to be outside the spread.
RudolfKrugstein
25
RudolfKrugstein 2013.10.23 14:49  
angevoyageur:
Sometimes SYMBOL_TRADE_STOPS_LEVEL  return 0, but your stop still have to be outside the spread.
Mmmh, good Idea. But when I print the stop levels, it returns 80.
Automated-Trading
Admin
100921
Automated-Trading 2013.10.23 17:13  
RudolfKrugstein:

I always get as a result: "Invalid stops".

That is confusing, because my stops are at least "stopLevels+1" pips away from the price.

Any tips/Idea what is wrong?

Thanks!

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());}
  }
RudolfKrugstein
25
RudolfKrugstein 2013.10.25 01:01  
Automated-Trading:

1. Use ZeroMemory before preparing MqlTradeRequest structure.

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

Ah, I set the TP/SL both on bid, and not SL on Ask.

 Thanks! 

To add comments, please log in or register