How can I adjust a price to a multiple of Ticksize?

 

Hi,

I plot a line into a chart and then I execute a test-script. If the horizontal line is below the price it opens a market buy order and if the line is above the current price a sell market order is placed. Sometimes I get an error #130. I read about it and then I came to the conclusion that this error occurs when the horizontal line is not a multiple of Ticksize. It often happens when I test it with CFDs.

Unfortunately I have no idea how to correct this price. I have done this so far:

if (StopLine % MarketInfo(NULL, MODE_TICKSIZE) != 0) StopLine = ?

 

For example the German DAX: If the StopLine is 9814.32 the error #130 occurs while sending the order because a valid stoploss can only be 9814.00 or 9814.25.

What I also don't understand is that MarketInfo("DAX30", MODE_TICKSIZE) is 0.01 even though the ticks are in 0.25 steps. Or is that just a wrong information or a broker problem? 

 

1) %-Division is only for integer (int, long, ulong, ..)

2) For double-vars MathMod() does have a problem! You'd better use the this: https://www.mql5.com/en/forum/143605

3) Error 130 in many cases mean the price is too close (check:MODE_FREEZELEVEL & MODE_STOPLEVEL) or on the wrong side.

4) May be you should use the Point? (Point is the unit of price measurement for a symbol (the minimum possible price change, the last significant figure of the price value).)

 

Thanks, gooly. But unfortunately that doesn't work. I also found some code from WHRoeder and tested that. The problem here is definitely that my broker has false values for CFDs.

The Dax entry or stop price can only be in 0.25 steps but with all the MarketInfo() I can't find out about these steps and therefore I don't know how I can correct these values.

Because my ticksize is 0.01 instead of 0.25 (what it should be), I can't do a calculation based on ticksize.

 

 
mar:

Hi,

I plot a line into a chart and then I execute a test-script. If the horizontal line is below the price it opens a market buy order and if the line is above the current price a sell market order is placed. Sometimes I get an error #130. I read about it and then I came to the conclusion that this error occurs when the horizontal line is not a multiple of Ticksize. It often happens when I test it with CFDs.

Unfortunately I have no idea how to correct this price. I have done this so far:

 

For example the German DAX: If the StopLine is 9814.32 the error #130 occurs while sending the order because a valid stoploss can only be 9814.00 or 9814.25.

What I also don't understand is that MarketInfo("DAX30", MODE_TICKSIZE) is 0.01 even though the ticks are in 0.25 steps. Or is that just a wrong information or a broker problem? 

price=MathRound(price/tickSize)*tickSize
But in your example, it's seems MarketInfo("DAX30", MODE_TICKSIZE) is not reliable. Contact your broker.
 
mar:

Thanks, gooly. But unfortunately that doesn't work. I also found some code from WHRoeder and tested that. The problem here is definitely that my broker has false values for CFDs.

The Dax entry or stop price can only be in 0.25 steps but with all the MarketInfo() I can't find out about these steps and therefore I don't know how I can correct these values.

Because my ticksize is 0.01 instead of 0.25 (what it should be), I can't do a calculation based on ticksize.

 

Place a pending order and change its price randomly to find out levels it accepts. I guess it would respect the tick size value from the MQL, whatever the steps seem to be. Though the DAX futures has the tick size of 0.5 point, its CFDs vary, but I have never seen a different value from the point.

 
DeepThought:

Place a pending order and change its price randomly to find out levels it accepts. I guess it would respect the tick size value from the MQL, whatever the steps seem to be. Though the DAX futures has the tick size of 0.5 point, its CFDs vary, but I have never seen a different value from the point.

It is impossible that tick size can be 0.5 point. A point is the smallest decimal place.

Ie

if the smallest possible increment is 0.01, the point equals 0.01

0.5 point would be 0.005 and would not be acceptable. 

 
GumRai:

It is impossible that tick size can be 0.5 point. A point is the smallest decimal place.

Ie

if the smallest possible increment is 0.01, the point equals 0.01

0.5 point would be 0.005 and would not be acceptable. 

Hello GumRai,

a point is usually meant a price unit in trading futures, like a pip in Forex. A point in Metatrader is unfortunate term confusing the original meaning.

Reason: