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.

Moderator

2342

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.

724

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

Moderator

2342

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?

724

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

Moderator

2342

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

724

It 'possible that the shift must be equal in these two values? Before I wrote thus:

after

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))

Moderator

2342

724

Moderator

6152

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(....

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);

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.

iHighest - Timeseries and Indicators Access - MQL4 Reference

- docs.mql4.com

iHighest - Timeseries and Indicators Access - MQL4 Reference

Moderator

35110

I think your problem is somewhere else in your code; NormalizeDouble is most likely not the solution.

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

}

}