For any of several charts, how do I calculate the minimum "server-acceptable" stoploss for a new order?

 

I would like to know how to avoid the famous "130:iinvalid stops" error.

Thank you in advance.

 
chaffinsjc wrote >>

I would like to know how to avoid the famous "130:iinvalid stops" error.

Thank you in advance.

well, if you are doing a buy order, make sure your TP is above the Ask price and the SL is below the Bid price and vice versa for Sell order

 
ronaldosim wrote >>

well, if you are doing a buy order, make sure your TP is above the Ask price and the SL is below the Bid price and vice versa for Sell order

Are you saying that, on a Buy order, the broker's server will accept any stoploss below the Bid price? It can be that tight?

 
Hello,
Use the instruction : MarketInfo(CURRENCY,MODE_STOPLEVEL), that will give you the stoplevel you have to respect for your broker to accept your request. So, for exemple for a BUY order, to set the StopLoss above the Order Open Price the BID price should be > Order Open Price + MarketInfo(CURRENCY,MODE_STOPLEVEL)*POINT(StopLevel is in pips).
 
Jacques366:

I assume you are talking about an Open Order, as opposed to a Pending Order.

You said that StopLevel is in pips. Is it a fixed value set by the broker, or does it fluctuate on market dynamics(and broker preferences)?


So many details are NOT covered in the Documentation. The description info on most of the items in the docs are short and beg more questions than they answer.

 

FWIW...


SL,TP settings for market and pending orders are at the best of times "an issue" and ERR_INVALID_STOPS (130) is always lurking just beyond sight - lol


IF you want the rules as published in the MQL4 Book Appendix go to Requirements and Limitations in Making Trades.

Tables below show calculation values that limit the conduction of trades when opening, closing, placing, deleting or modifying orders.

To get the minimum distance to StopLevel and freezing distance FreezeLevel the MarketInfo() function should be called


The tables totally answer all questions - as long as one takes the time to really read and understand what they say ;-)

eg, I ended up writing more than one page of notes just to get my head around it all. Then condensed the notes into one essential datum

MarketInfo(CURRENCY,MODE_STOPLEVEL) Just like Jacques366 mentioned.


Also, this table is referenced in the MQL4 Book's Order Characteristics and Rules for Making Trades and is well worth the perseverance in reading!


BTW - beware implications surrounding MODE_FREEZELEVEL which are highlighted in the tables.

Also, should your data feed/broker be using sub Pip 3,5 pricing - STOPLEVEL is an integer which if multiplied by 'Point' will right shift the least significant digit of the STOPLEVEL value into the 3rd,5th decimal digit - something you do not want... and for sure will invoke the big 130 gremlin :o))

 

I trust chaffinsjc will not object to me asking a question which is in same area as thread... Ok? - thanks!

.

(A) Order Characteristics and Rules for Making Trades

(B) Requirements and Limitations in Making Trades

as I mentioned above are the references I request you to consider in detail, please.

.

In (A) section Modification of Market Orders we see:

Orders StopLoss and TakeProfit cannot be placed closer to the market price than at the minimum distance.
An order cannot be modified, if the execution price of its StopLoss or TakeProfit ranges within the freeze distance from the market price.

and:

The modification rule for market orders limits the stop-order approaching to the current price, but it does not limit the stop-order distance from the price. This is why stop orders can be placed at any distance from the current price, if this distance is larger than the limiting distance (if, as of the order modification moment, the stop order is outside the freeze band determined by the value). In Fig. 77, we can see the same order after one more modification: in this case, stop orders are well out of the range of the limiting minimum distance.

and in (B) the third table FreezeLevel Limitation (Freezing Distance). we see:

StopLoss or TakeProfit orders can not be modified if StopLoss or TakeProfit values violate the StopLevel parameter requirements.

MY issue is this:

What is correct when modify a market order ?

1. use MODE_FREEZELEVEL or use MODE_STOPLEVEL

2. use MODE_FREEZELEVEL because Docs: Standard constants - MarketInfo state:

MODE_FREEZELEVEL 33

Order freeze level in points. If the execution price lies within the range defined by the freeze level, the order cannot bemodified, cancelled or closed.

3. use MathMax(MODE_FREEZELEVEL,MODE_STOPLEVEL) eg, play safe...

.

This might be seen as making a mountain out of a molehill stuff BUT if scalping etc, ALL points count...

.

Pleeeeease - thoughts/interpretations/finalSolutions/WHATEVER ;) are requested.

.

At the moment, I favor (3) since I suspect (2) weights (A).

.

I have tried to conclude information in (B) as my guide in generating a generic make and forget function whereby this pain need not be continuously repeated EACH and every time one issues Trade Operation calls and of course, the requisite pre-call data calculations. Is a recurring nightmare for me... maybe you too?

.

Thank you for your time taken in considering this post :o)

.

btw, I may well be massively off course here! Is ok... please tell me your views/practices and experiences so that I can put this to rest - permanently !!!

.

.

update:

Below, from (A) section Trading Requirements and Limitations seems to lend weight to (3) above also.

Freeze distance limits the possibility to modify the requested prices of opening your pending orders, as well as the requested stop levels for market orders that are in the freeze area. This means, for example, that, if the market price is 1.3800, your pending order is placed to be opened at 1.3807 and the broker's prescription is 10, your pending order is in the freeze area, i.e., you cannot modify or delete it. At a calm market, brokers usually don't set freeze distance, i.e., its value = 0. However, during the period preceding important news or at high volatility, the broker may set a certain value of a freeze distance. In different conditions and for different brokers, this value may range from 1 to 30 points for basic symbols and take higher values for other symbols. Brokerage company can change the freeze-distance value at its own discretion at any time.

Reason: