Download MetaTrader 5
To add comments, please log in or register
Added support for the Spanish language. Come and check it out!
barnacle7
376
barnacle7 2013.02.20 12: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 

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.02.20 12: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://www.mql5.com/en/forum/129832

whroeder1
13644
whroeder1 2013.02.20 12:43  
int StepPips = 20;
double NextStep = MathFloor( Bid / pips2dbl + StepPips) * pips2dbl;
barnacle7
376
barnacle7 2013.02.20 12:49  

Thanks,Raptouk and WHRoeder, I'll look both.

Alain Verleyen
Moderator
28672
Alain Verleyen 2013.02.21 12:01  
RaptorUK:


You can use MathMod() so . . .

  . . .  but MathMod() doesn't always work so you should really code your own version:  https://www.mql5.com/en/forum/129832

 


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.

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.02.21 12: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. 
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.02.21 16: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 );
   } 
Files:
Alain Verleyen
Moderator
28672
Alain Verleyen 2013.02.21 16:46  
RaptorUK:

Try this . . .


Not much time to test, but seem correct to me. Thank you RaptorUk.
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2013.02.21 17:15  
angevoyageur:

Not much time to test, but seem correct to me. Thank you RaptorUk.
Thanks for taking a look :-)
Alain Verleyen
Moderator
28672
Alain Verleyen 2014.11.27 11: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);
  }
/
To add comments, please log in or register