Download MetaTrader 5

Buying or Selling at the 00 levels.

To add comments, please log in or register
ForexTrader17
1041
ForexTrader17  

How would I code something like if bid is at 1.1756 then I want to put a buy limit at next 00 level below it or at 1.1700. Same or sell. If market at say 1.1756 then I want to place sell limit at closest above 00 level or 1.1800 for example. Is there a built in function that does something similar?

Thank you. 

Marco vd Heijden
Moderator
4963
Marco vd Heijden  
ForexTrader17:

How would I code something like if bid is at 1.1756 then I want to put a buy limit at next 00 level below it or at 1.1700. Same or sell. If market at say 1.1756 then I want to place sell limit at closest above 00 level or 1.1800 for example. Is there a built in function that does something similar?

Thank you. 

Yes

NormalizeDouble(value,3)
Depending on Digits of course.
Doerk Hilger
1188
Doerk Hilger  
I guess he rather asked for rounding. MathRound() will help him. 
Marco vd Heijden
Moderator
4963
Marco vd Heijden  
Doerk Hilger:
I guess he rather asked for rounding. MathRound() will help him. 
How does that handle double ? example>?
Doerk Hilger
1188
Doerk Hilger  
You can do it with MathMod(), with MathRound() as well as with MathFloor() or simply (int), whereby the last ones need a multiplication based on the amount of the (unwanted) digits upfront.
Doerk Hilger
1188
Doerk Hilger  

Untested example for Forex:

double roundbelow = Bid -MathMod(Bid,1);

double roundabove = Bid+1 -MathMod(Bid,1); 

 

And with MathRound():

double closestround=((double)MathRound(Bid*10)/10.0);

double nexthigherround=((double)MathRound(((Bid)*10)+1)/10.0);

double nextlowerround=((double)MathRound(((Bid)*10)-1)/10.0); 

Marco vd Heijden
Moderator
4963
Marco vd Heijden  
//Untested example for Forex:

double roundbelow = Bid -MathMod(Bid,1);

double roundabove = Bid+1 -MathMod(Bid,1); 

//And with MathRound():

double closestround=((double)MathRound(Bid*10)/10.0);

double nexthigherround=((double)MathRound(((Bid)*10)+1)/10.0);

double nextlowerround=((double)MathRound(((Bid)*10)-1)/10.0); 

Print("roundbelow ",roundbelow);
Print("roundabove ",roundabove);
Print("closestround ",closestround);
Print("nexthigherround ",nexthigherround);
Print("nextlowerround ",nextlowerround);
Alain Verleyen
Moderator
32008
Alain Verleyen  

No need to overcomplicate :

double BID=1.1756;
double nexthigherround=MathCeil(BID*100)/100.0;
double nextlowerround=MathFloor(BID*100)/100.0;
Doerk Hilger
1188
Doerk Hilger  
Many ways lead to Rome ;) ... but MathFloor() and MathCeil() seem to be the shortest, cause you don´t have to check anything more to figure out where "you are" currently.
To add comments, please log in or register