MA Buffer problem MQL5

 

Hi, 

i need some help comparing two elements of MA. Usually i have no problem with this,but this time is different.

   ArrayResize(MA,MAdirectionPeriod);
   ArraySetAsSeries(MA,true);
   if(CopyBuffer(ma,0,0,MAdirectionPeriod,MA)!=MAdirectionPeriod)
     {
      Print("CopyBuffer from MA failed, no data");
      return;
     }
   double ma1 = NormalizeDouble(MA[0],_Digits);
   double ma2 = NormalizeDouble(MA[MAdirectionPeriod-1],_Digits);

This is how i assign value to the buffer.

I need as simple as 

 ma1<ma2

to set as filter for opening trades, i have worked multiple times with this, but this time does not work.

For example i set for buy ma1>ma2, but it still opens buy on the opposite signal, when i print the values the really seem to increase, but when i look to the chart the values are different.

So i believe it get wrong values for the current and the "MAdirectoinPeriod-1"-th bar. Do you know what needs to be changed?

Btw i tried with and without ArraySetAsSeries, no effect  

 
Stanislav Ivanov:

Hi, 

i need some help comparing two elements of MA. Usually i have no problem with this,but this time is different.

This is how i assign value to the buffer.

I need as simple as 

to set as filter for opening trades, i have worked multiple times with this, but this time does not work.

For example i set for buy ma1>ma2, but it still opens buy on the opposite signal, when i print the values the really seem to increase, but when i look to the chart the values are different.

So i believe it get wrong values for the current and the "MAdirectoinPeriod-1"-th bar. Do you know what needs to be changed?

Btw i tried with and without ArraySetAsSeries, no effect  

why normalize?
never normalize
 
Code2219 or probably 2319:
why normalize?
never normalize

in both cases didnt work, i did it because it showed a big string of numbers after the decimal, i hoped it could help, but i guess there was no point in it

 
Stanislav Ivanov:

in both cases didnt work, i did it because it showed a big string of numbers after the decimal, i hoped it could help, but i guess there was no point in it

to get rid of those long chain of numbers, use DoubleToString(), when printing.
still NEVER normalize anything. not needed. just compare non-normalized doubles, or compare them the right way.
 
Code2219 or probably 2319:
to get rid of those long chain of numbers, use DoubleToString(), when printing.
still NEVER normalize anything. not needed. just compare non-normalized doubles, or compare them the right way.
i believe it is a bit different, i am not sure how this will help,i compared non normalized doubles, and the result is that its completely different what we calculate and whats on chart