Request for help calculating starting point of horizontal grid

 

Good day to all,


I'm using MT4, but I just started to convert my indicators and scripts to MT5, so MT5 is new to me.

I'm using the code below which is in principle the same as I used to calculate the starting point of the grid in MT4, but in MT5 LastGloseGridnumber is calculated as zero which is not correct. Can anyone please explain what should be coded differently? (pips is set as: int pips = 250;)

   double myPoint = SymbolInfoDouble(_Symbol,SYMBOL_POINT);

//---
   double LastClose           = iClose(NULL,PERIOD_H1,1);
   int    LastCloseGridNumber = MathRound(LastClose/pips*myPoint);
   double StartPrice          = (LastCloseGridNumber * pips)/(1/myPoint);
//---
   Print("LastClose = " + LastClose,"LastCloseGridNumber = " + LastCloseGridNumber, "pips = " + DoubleToString(pips,0));

Best regards,


Robert

 
ReactoFX:

Good day to all,

I'm using MT4, but I just started to convert my indicators and scripts to MT5, so MT5 is new to me.

I'm using the code below which is in principle the same as I used to calculate the starting point of the grid in MT4, but in MT5 LastGloseGridnumber is calculated as zero which is not correct. Can anyone please explain what should be coded differently? (pips is set as: int pips = 250;)

have you done the math, do you know what the answer should be?

have you checked the value of the variables with the debugger?

do you know what order the highlighted line is calculated in?

regards

 double myPoint = SymbolInfoDouble(_Symbol,SYMBOL_POINT);

//---
   double LastClose           = iClose(NULL,PERIOD_H1,1);
   int    LastCloseGridNumber = MathRound(LastClose/pips*myPoint);
   double StartPrice          = (LastCloseGridNumber * pips)/(1/myPoint);
//---
   Print("LastClose = " + LastClose,"LastCloseGridNumber = " + LastCloseGridNumber, "pips = " + DoubleToString(pips,0));

example of your code output based on EURUSD


Documentation on MQL5: Common Functions / GetTickCount64
Documentation on MQL5: Common Functions / GetTickCount64
  • www.mql5.com
GetTickCount64 - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Hi Paul,


Thanks for your response. I noticed I had forgotten to put brackets like this (interval*myPoint), this solves the problem, and I changed the type of the LastClosedGridNumber to double, so now the code composes without warnings too.


Thanks again, and have a nice day,


Robert

Reason: