A constant number

 

Hi, I just made some EA with simple function, but I have a problem.

The settings of my EA is when 2 EMA crossed the numbers within the DX variable will change.

For example

Dx = 10

If fast EMA crossing up Dx += 1 that mean Dx = 11

If fast EMA crossing Down Dx -=1 that mean Dx = 9

But, when EMA crossing up or down the number was changed for few second and changed back to 10.  I don't want that to happen. Can I make the variable constant?

   if (
         (MovingAverageArray1[0]>MovingAverageArray2[0])
       &&(MovingAverageArray1[1]<MovingAverageArray2[1])
      )
   {
   DX++; 
   }
   
   if (
         (MovingAverageArray1[0]<MovingAverageArray2[0])
       &&(MovingAverageArray1[1]>MovingAverageArray2[1])
      )
   {
   DX--;
   }
 

You are checking for a cross on the forming bar. As price moves up and down, you will get multiple cross/uncross. Your DX is useless. It indicates how many ticks has occurred since the cross.

If you don't want that, check for the cross on one and two.