NormalizeDouble info

 
Hello everyone, I'm trying to normalize the decimal places of the moving average, this code is correct or not? Even if I do not receive errors, I am not entirely sure of what is written!

for(L=0; L< 50; L++){      
        
          if(NormalizeDouble(iMA(NULL, PERIOD_CURRENT, 120, 0, MODE_SMA, PRICE_CLOSE, 1+L) >= iMA(NULL, PERIOD_CURRENT, 120, 0, MODE_SMA, PRICE_CLOSE, 2+L),5))

          {
           //my condition
          }
         }

      

 

That probably isn't doing what you want. It is normalizing 1 or 0 (true or false) to 5 decimal places.

What exactly do you want? Your code is comparing 2 moving averages. 

 
I would like to know if the moving average is ascending or descending of 50 candles, but I would also normalize the price
 
fly7680:
I would like to know if the moving average is ascending or descending of 50 candles, but I would also normalize the price

May I ask why you want to normalize the moving average? 

 
honest_knave:

May I ask why you want to normalize the moving average? 

Sometimes my signal not work if the moving average is ascending or descending ... it thought that the problem could depend on the misreading of the moving average with more or less decimal
 
fly7680:
Sometimes my signal not work if the moving average is ascending or descending ... it thought that the problem could depend on the misreading of the moving average with more or less decimal
I think your problem is somewhere else in your code; NormalizeDouble is most likely not the solution.
 
It 'possible that the shift must be equal in these two values? Before I wrote thus:

          if(iMA(NULL, PERIOD_CURRENT, 120, 0, MODE_SMA, PRICE_CLOSE, 1+I) <= iMA(NULL, PERIOD_CURRENT, 120, 0, MODE_SMA, PRICE_CLOSE, 2+I))

after
          if(iMA(NULL, PERIOD_CURRENT, 120, 1+I, MODE_SMA, PRICE_CLOSE, 1+I) <= iMA(NULL, PERIOD_CURRENT, 120, 2+I, MODE_SMA, PRICE_CLOSE, 2+I))

 
Do you want to compare the moving average 50 bars ago to the moving average now?
 
I have to figure out if the moving average in the last 50 candles is always uphill


 
fly7680:
I have to figure out if the moving average in the last 50 candles is always uphill


That is simple.

If price is above your moving average it has, and if price is below moving average it has not.

If you want to know that for 50 bars you can use

int index_lowest_bar=iLowest(.....
int index_highest_bar=iHighest(....

To get the price do

double price_low=iLow(Symbol(),PERIOD_CURRENT,index_lowest_bar);
double price_high=iHigh(Symbol(),PERIOD_CURRENT,index_highest_bar);

Or you can substitute iLow and iHigh with your moving average of course.

Then you have the bar index number of the lowest and highest bars out of 50 last bars.

And then you can compare these min and max values to the same bars of your moving average and see if there was a crossover or not.

https://docs.mql4.com/series/ihighest

iHighest - Timeseries and Indicators Access - MQL4 Reference
iHighest - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
iHighest - Timeseries and Indicators Access - MQL4 Reference
 
honest_knave:
I think your problem is somewhere else in your code; NormalizeDouble is most likely not the solution.
It could. Don't believe all what you read here