stoplevel limitation?

 

I am not sure about the correct definition of stoplevel...


For takeprofit, is the limitation:

1. MathAbs(openprice - takeprofit) >= servers_min_stop ?

or is it:
2. MathAbs(closeprice - takeprofit) >= servers_min_stop ?



For stoploss, is the limitation:
1. MathAbs(openprice -stoploss) >= servers_min_stop ?

or is it:

2. MathAbs(closeprice - stoploss) >= servers_min_stop ?


Thanks.

 

Hi Gordon,

I believe that the server minimum Stop Level is:

MarketInfo(Symbol(), MODE_STOPLEVEL)

The order opening price is Ask for a long order or Bid for a short order.

I don't know about the minimum take profit setting, but I suspect that it might be:

MarketInfo(Symbol(), MODE_FREEZELEVEL)

So, you could avoid a minimum stop level problem on a long order by comparing like this:

double yourstoplossvalue = ?.?;   //...whatever you want it to be
if(NormalizeDouble((Ask - yourstoplossvalue), Digits) >= (MarketInfo(Symbol(), MODE_STOPLEVEL) * Point))
  {
   .....;   // OK to place your order
  }

I have not done anything with these types of MarketInfo calls, but I believe that this is the correct way to do it. If I'm wrong I'm sure someone will correct me.

- Tovan

 
tovan:

I don't know about the minimum take profit setting, but I suspect that it might be:

MarketInfo(Symbol(), MODE_FREEZELEVEL)

I'm pretty sure that MODE_STOPLEVEL applies to three things: (1) distance from the current price to a stop or limit pending entry price; (2) distance between entry price and s/l; (3) distance between entry price and t/p.


The documentation says that MODE_FREEZELEVEL allows a broker to lock an order, preventing modifications, when the price gets close to its triggers. However, I've never yet seen a broker where MODE_FREEZELEVEL is anything other than zero (though brokers might be turning it on occasionally during news).


The following script tests the application of MODE_STOPLEVEL, seeing at what level error 130 kicks in. If I change either of the lines highlighted in green, so that they use a t/p or s/l of less than MODE_STOPLEVEL, then I get error 130.


   // Construct a buy limit price which is a decent distance away from the current ask price

   double limit = NormalizeDouble(MarketInfo(Symbol(), MODE_ASK) - (MarketInfo(Symbol(), MODE_SPREAD) * 50 * MarketInfo(Symbol(), MODE_TICKSIZE)), MarketInfo(Symbol(), MODE_DIGITS));


   // Number of pips from entry price to s/l and t/p. Use 0 for none.

   // Setting either of these to a value less than stoplevel (but greater than

   // zero) causes error 130

   int SLpips = MarketInfo(Symbol(), MODE_STOPLEVEL); // For example, MarketInfo(Symbol(), MODE_STOPLEVEL) - 1 causes error 130

   int TPpips = MarketInfo(Symbol(), MODE_STOPLEVEL);   // For example, MarketInfo(Symbol(), MODE_STOPLEVEL) - 1 causes error 130


   // Turn the number of s/l and t/p pips into prices, ignoring zero values

   double sl = 0, tp = 0;

   if (SLpips > 0) sl = NormalizeDouble(limit - (SLpips * MarketInfo(Symbol(), MODE_TICKSIZE)), MarketInfo(Symbol(), MODE_DIGITS));

   if (TPpips > 0) tp = NormalizeDouble(limit + (TPpips * MarketInfo(Symbol(), MODE_TICKSIZE)), MarketInfo(Symbol(), MODE_DIGITS));


   // Try sending the order 

   int ticket = OrderSend(Symbol(), OP_BUYLIMIT, 0.01, limit, 999, sl, tp);


   // Handle the results

   if (ticket > 0) {

      MessageBox("Order succeeded");

      OrderDelete(ticket);

   } else {

      int err= GetLastError();

      MessageBox("Order failed with error #" + err);

   }


 

Thanks, but I don't think u understood the question - is the StopLevel the distance from an order's OPEN PRICE when placing that order, or is it the distance from it's CLOSING PRICE?


If we look at "Requirements and Limitations in Making Trades" in the MQL4 Book (https://book.mql4.com/appendix/limits), it says quite specifically that StopLevel limitation is from CLOSING PRICE. But that doesn't make sense... How would I know the closing price if the spread is not fixed (as happens with some brokers)? And so I have seen many examples where Stoplevel was checked relative to and order's OPEN PRICE, specifically in a library I use - LibOrderReliable_V1_1_4, they check Stoplevel relative to OPEN PRICE.


So which one is the correct one, or maybe different brokers look at the Stoplevel differently?

 
gordon:

Thanks, but I don't think u understood the question - is the StopLevel the distance from an order's OPEN PRICE when placing that order, or is it the distance from it's CLOSING PRICE? 

My code is illustrating that it's from the open price, at least with all the brokers I use. (I also can't imagine what "from the closing price" would mean, though I can't see anything along those lines in https://book.mql4.com/appendix/limits).

 
jjc:

My code is illustrating that it's from the open price, at least with all the brokers I use. (I also can't imagine what "from the closing price" would mean, though I can't see anything along those lines in https://book.mql4.com/appendix/limits).

Look at the 2nd table (StopLevel Minimum Distance Limitation) in https://book.mql4.com/appendix/limits, notice that for BUY the limitation on SL is Bid-SL>=StopLevel, and for TP it's TP-Bid>=StopLevel. But Bid is the CLOSING PRICE for Buy orders! We open a Buy order at Ask price. And notice that also for Sell orders it's defined from closing price (Ask). So that's why I ask - is this a mistake in the book???

 
gordon:

Look at the 2nd table (StopLevel Minimum Distance Limitation) in https://book.mql4.com/appendix/limits, notice that for BUY the limitation on SL is Bid-SL>=StopLevel

On market orders, yes. But my code was demonstrating a limit order. Same principle on market orders, except that the closest stop allowed is - for obvious reasons - based on the current bid price, not a pending entry price. The aim, broadly speaking, is to give brokers some breathing space.


To put it another way, https://book.mql4.com/appendix/limits is saying that you can have a tighter stop on a pending order than a market order. On a pending order, the stop can be stoplevel from the entry. On a long market order, it can be stoplevel from the bid, and the closest possible stop to the entry price is therefore stoplevel plus the current spread. Doesn't imply anything about the spread at the time that the s/l is eventually hit, in the sense of "How would I know the closing price if the spread is not fixed (as happens with some broker)?"

Reason: