English

## Checking for Price multiples of 20 points to Pyramid trade

 83 barnacle7 2013.02.20 13:01    I would like to Enter the trade and then have the 1st Pyramid order occur at the next Bid with a multiple of 20pips. Example: Entry 1.3315 then (Pyramid at next Bid with  20pip multiple after entry)1st Pyramid occurs at 1.3320    (5 Pips from Entry in this example , but varies depending on when the entry criteria triggers the entry order,so could be more or less then 5pips )2nd Pyramid at 1.3340 then each subsequent pyrmaids will be every 20 pips .etc As th 1st Pyramid is not set from the entry price and fluctuates I am finding it difficult to choose the best way to code this,Does anyone know how I can find the next Bid multiple of 20pips from the entry price ?I could only think of excel functions  , No.s ending in 20. """"20.Have it cycle through a list of Bid prices 1.2980,1.3300,1.3320, (The list of at least 200 numbers).   Thanks        similar
 14167 RaptorUK 2013.02.20 13:32 #   barnacle7:  I would like to Enter the trade and then have the 1st Pyramid order occur at the next Bid with a multiple of 20pips. Example: Entry 1.3315 then (Pyramid at next Bid with  20pip multiple after entry)1st Pyramid occurs at 1.3320    (5 Pips from Entry in this example , but varies depending on when the entry criteria triggers the entry order,so could be more or less then 5pips )2nd Pyramid at 1.3340 then each subsequent pyrmaids will be every 20 pips .etc As th 1st Pyramid is not set from the entry price and fluctuates I am finding it difficult to choose the best way to code this,Does anyone know how I can find the next Bid multiple of 20pips from the entry price ? You can use MathMod() so . . .```double PyramidStep = 0.0020; double NextStep; NextStep = Bid - MathMod(Bid, PyramidStep) + PyramidStep;  // 1st step above Bid```  . . .  but MathMod() doesn't always work so you should really code your own version:  https://forum.mql4.com/36585#391146  similar
 13116 WHRoeder 2013.02.20 13:43 #   ```int StepPips = 20; double NextStep = MathFloor( Bid / pips2dbl + StepPips) * pips2dbl;```
 83 barnacle7 2013.02.20 13:49 #   Thanks,Raptouk and WHRoeder, I'll look both.
 Moderator3206 angevoyageur 2013.02.21 13:01 #   RaptorUK: You can use MathMod() so . . .  . . .  but MathMod() doesn't always work so you should really code your own version:  https://forum.mql4.com/36585#391146  Function to replace MathMod presented in the thread specified is not correct :```double MathModCorrect(double a, double b) { int tmpres=a/b; return(a-tmpres*b); } ```for a=1.25500 and b=0.0005 give :```2013.02.21 12:47:17     tst EURUSD,H1: a = 1.25500 tmpres = 2509 tmpres*b = 1.25450 ```This does not solve the problem of MathMod. similar
 14167 RaptorUK 2013.02.21 13:45 #   angevoyageur: Function to replace MathMod presented in the thread specified is not correct :for a=1.25500 and b=0.0005 give :This does not solve the problem of MathMod. Just tested this,  you are correct,  one day I will remember to check proposed solutions from every source not just the ones that I think need checking.  similar
 14167 RaptorUK 2013.02.21 17:12 #   RaptorUK: Just tested this,  you are correct,  one day I will remember to check proposed solutions from every source not just the ones that I think need checking.  Try this . . .```double MathModCorrect(double a, double b)    {    double Power = MathPow(10, Digits);    double RoundUp = 4.9 / (Power * 10);       a = MathRound( Power * ( a + RoundUp ) ) ;    b = MathRound( Power * ( b + RoundUp ) ) ;       int tmpres = a / b;       return( (a - tmpres * b) / Power );    } ```   Attached files:   mathmod_test.mq4  (3.17 KB)
 Moderator3206 angevoyageur 2013.02.21 17:46 #   RaptorUK: Try this . . .Not much time to test, but seem correct to me. Thank you RaptorUk.
 14167 RaptorUK 2013.02.21 18:15 #   angevoyageur: Not much time to test, but seem correct to me. Thank you RaptorUk. Thanks for taking a look :-)
 Moderator3206 angevoyageur 2014.11.27 12:36 #   RaptorUK: Try this . . .  The function proposed by RaptorUK doesn't work in all cases. The problem comes from Digits (for example if Digits is 1).If the RoundUp value is too close to a or b , you will get wrong result. As I only used this function with positive numbers, I use this simple function :```double CustomMathMod(double dividend,double divisor)   {    return(dividend-int(dividend/divisor)*divisor);   } ```