Download MetaTrader 5

Usage difference between MarketInfo() & SymbolInfoDouble() - page 2

To add comments, please log in or register
BigFisherman
125
BigFisherman  
angevoyageur:
What do you mean ?


Maybe I didn't explain myself clear enough.. My understanding is Ticksize & Tickvalue obtained from MarketInfo() isn't a constant, it may fluctuate depending on the market condition. However I have not verified it myself, I simply read it from some old post: https://www.mql5.com/en/forum/109552/page3#185757.

Btw, may I ask if this:

EntryPrice = MathFloor( EntryPrice / PriceStep) * PriceStep;

is more accurate & correct than this?

EntryPrice = NormalizeDouble( EntryPrice / PriceStep, 0) * PriceStep;

They looked similar to me other than the rounding off part.

Thanks.

BigFisherman
125
BigFisherman  
WHRoeder:
  1. The market can jump more than a tick, but ticksize is a constant.
  2. You only have to normalize price for pending orders. See https://www.mql5.com/en/forum/146370

Yeap, I saw that post before, thanks for the tips. However when you mention ticksize is a constant, do you mean this..

double PriceStep = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE);

... is always going to be return constant? I've just replied angevoyageur showing him what I meant actually, maybe I explained wrongly in my previous post.

Alain Verleyen
Moderator
31604
Alain Verleyen  
BigFisherman:


Maybe I didn't explain myself clear enough.. My understanding is Ticksize & Tickvalue obtained from MarketInfo() isn't a constant, it may fluctuate depending on the market condition. However I have not verified it myself, I simply read it from some old post: https://www.mql5.com/en/forum/109552/page3#185757.

Btw, may I ask if this:

is more accurate & correct than this?

They looked similar to me other than the rounding off part.

Thanks.

Ok I see. There are people who report once that ticksize may not be constant. But in my opinion, it was a bug or a broker's error. I never experimented that personally, and I don't want my code to take into account all past bugs and errors. But it's up to each one to decide.

About both code, I didn't check. The code I posted is working, possibly the variant with NormalizeDouble is also ok.

GreenMoney
379
GreenMoney  
BigFisherman:


Maybe I didn't explain myself clear enough.. My understanding is Ticksize & Tickvalue obtained from MarketInfo() isn't a constant, it may fluctuate depending on the market condition. However I have not verified it myself, I simply read it from some old post: https://www.mql5.com/en/forum/109552/page3#185757.

Btw, may I ask if this:

EntryPrice = MathFloor( EntryPrice / PriceStep) * PriceStep;

is more accurate & correct than this?

EntryPrice = NormalizeDouble( EntryPrice / PriceStep, 0) * PriceStep;

They looked similar to me other than the rounding off part.

Thanks.

angevoyageur:

About both code, I didn't check. The code I posted is working, possibly the variant with NormalizeDouble is also ok.


In the above instance, the usage of NormalizeDouble() and MathFloor() don't always give equivalent results. For example:

double EntryPrice = 1.400006;
double PriceStep = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE); // TickSize = 0.00001
double EntryPrice_ND = NormalizeDouble( EntryPrice / PriceStep, 0) * PriceStep;
double EntryPrice_MF = MathFloor( EntryPrice / PriceStep) * PriceStep;
Print ("EntryPrice_ND: ", DoubleToStr(EntryPrice_ND, 5), "  EntryPrice_MF: ", DoubleToStr(EntryPrice_MF, 5));

The above shows that, based on the same price, the two can at times give different results: NormalizeDouble() rounds up (1.40001) while MathFloor() rounds down (1.40000).

@BigFisherman: Just remember...the rounding can be important, depending on the situation. The question is: where to use which and when? That is up to each individual coder. :)

BigFisherman
125
BigFisherman  
angevoyageur:

Ok I see. There are people who report once that ticksize may not be constant. But in my opinion, it was a bug or a broker's error. I never experimented that personally, and I don't want my code to take into account all past bugs and errors. But it's up to each one to decide.

About both code, I didn't check. The code I posted is working, possibly the variant with NormalizeDouble is also ok.



You may be right about it being a bug or broker's error. I just did a short test logging 3 instruments' ticks info (Ticksize & Tickvalue of HKDJPY, CFD on Gold futures & CFD on Natural Gas) for the last 4 hrs. The results were consistent thus far. This may not be a thorough test but I supposed it's fairly safe to treat it as a constant. Even if it did fluctuate for a ticksize or 2, the calculated "PriceStep" inaccuracies should be rather insignificant.

//"_MI": MarketInfo();	 "_SI": SymbolInfoDouble()
...
...
2014.04.24 10:08:49_HKDJPY  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 1.052 | TickValue_SI: 1.052
2014.04.24 10:08:56_HKDJPY  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 1.052 | TickValue_SI: 1.052
2014.04.24 10:10:09_HKDJPY  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 1.052 | TickValue_SI: 1.052
2014.04.24 10:10:10_HKDJPY  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 1.052 | TickValue_SI: 1.052
2014.04.24 10:10:11_HKDJPY  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 1.052 | TickValue_SI: 1.052
2014.04.24 10:10:11_HKDJPY  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 1.052 | TickValue_SI: 1.052
2014.04.24 10:10:36_HKDJPY  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 1.052 | TickValue_SI: 1.052
2014.04.24 10:12:24_HKDJPY  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 1.051 | TickValue_SI: 1.051
...
...
2014.04.24 10:03:23_#NG  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 10.000 | TickValue_SI: 10.000
2014.04.24 10:04:01_#NG  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 10.000 | TickValue_SI: 10.000
2014.04.24 10:04:59_#NG  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 10.000 | TickValue_SI: 10.000
2014.04.24 10:05:35_#NG  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 10.000 | TickValue_SI: 10.000
2014.04.24 10:05:41_#NG  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 10.000 | TickValue_SI: 10.000
2014.04.24 10:05:49_#NG  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 10.000 | TickValue_SI: 10.000
2014.04.24 10:10:26_#NG  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 10.000 | TickValue_SI: 10.000
2014.04.24 10:16:34_#NG  Point: 0.001 | TickSize_MI: 0.001 | TickSize_SI: 0.001 | TickValue_MI: 10.000 | TickValue_SI: 10.000
...
...
2014.04.24 10:10:18_#GC  Point: 0.01 | TickSize_MI: 0.1 | TickSize_SI: 0.1 | TickValue_MI: 10.00 | TickValue_SI: 10.00
2014.04.24 10:10:20_#GC  Point: 0.01 | TickSize_MI: 0.1 | TickSize_SI: 0.1 | TickValue_MI: 10.00 | TickValue_SI: 10.00
2014.04.24 10:10:23_#GC  Point: 0.01 | TickSize_MI: 0.1 | TickSize_SI: 0.1 | TickValue_MI: 10.00 | TickValue_SI: 10.00
2014.04.24 10:10:27_#GC  Point: 0.01 | TickSize_MI: 0.1 | TickSize_SI: 0.1 | TickValue_MI: 10.00 | TickValue_SI: 10.00
2014.04.24 10:10:51_#GC  Point: 0.01 | TickSize_MI: 0.1 | TickSize_SI: 0.1 | TickValue_MI: 10.00 | TickValue_SI: 10.00
2014.04.24 10:11:39_#GC  Point: 0.01 | TickSize_MI: 0.1 | TickSize_SI: 0.1 | TickValue_MI: 10.00 | TickValue_SI: 10.00
2014.04.24 10:11:45_#GC  Point: 0.01 | TickSize_MI: 0.1 | TickSize_SI: 0.1 | TickValue_MI: 10.00 | TickValue_SI: 10.00
2014.04.24 10:12:41_#GC  Point: 0.01 | TickSize_MI: 0.1 | TickSize_SI: 0.1 | TickValue_MI: 10.00 | TickValue_SI: 10.00
BigFisherman
125
BigFisherman  
Thirteen:

In the above instance, the usage of NormalizeDouble() and MathFloor() don't always give equivalent results. For example:

The above shows that, based on the same price, the two can at times give different results: NormalizeDouble() rounds up (1.40001) while MathFloor() rounds down (1.40000).

@BigFisherman: Just remember...the rounding can be important, depending on the situation. The question is: where to use which and when? That is up to each individual coder. :)


Yeah, that's also what I meant about the rounding off difference. Thanks for the heads-up.

Cheers!

12
To add comments, please log in or register