My Expert Advisor 3 ema crossing not optimal yet

 

Hello,

I created an EA on the basis of 3 ema's crossing. The most important function is int Crossed, which gets the current emas and returns 1 if the direction is up and 2 if it's down.

Later in the start() function, the EA chooses which Alert to show by if(isCrossed > 0 && first_time != true){...//a lot of code}.

The EA should have the ability not to alert each crossing. For example, if there is a lot of sideways movement with a lot of up-and-down crossings. Moreover it should alert immediately if a crossing appears and not later.

How can I implement this?

Maybe there is also an adjusted EA-version (strategy) of 3 emas crossing available, that you know. Can you tell me what to consider additionally in simple 3 emas crossing?

Thanks for your help.

Is that enough information or do you need more code?

  int Crossed (double line1 , double line2, double line3)
    {
      static int last_direction = 0;
      static int current_direction = 0;
      
      if(first_time == true)
        {
          first_time = false;
          return (0);
        }
  //----
 
     if((line1 > line2) && (line1 > line3))
        current_direction = 1;  //up
     if((line1 < line2) &&(line1 < line3))
        current_direction = 2;  //down
 
 
  //----
      if(current_direction != last_direction)
        {         
            last_direction = current_direction;
            return (last_direction);
        }
      else
        {
           return(0);
        }
    }
 

Your Crossed function seems correct.

For the rest, you have to define precisely what you need :

The EA should have the ability not to alert each crossing. For example, if there is a lot of sideways movement with a lot of up-and-down crossings. Moreover it should alert immediately if a crossing appears and not later.

What is "a lot" ? What is "sideways" ? What is "crossing appears and not later" ? If you can define these terms, then the coding is almost trivial.

 

Is it reasonable to edit the EA according to this: Do not alert if the short ema crossed the others within a short timeframe (1 Minute, 2 minutes)? Or is there another possibility, how to handle that?

When I edit the Crossings function above in the way that there should be a certain distance between the short ema and the others, my EA alerts too late - even much later than when the crossing took place.

But I plan a strategy that the signal should appear right at the time when the crossing appears.

 
     if((line1 > line2) && (line1 > line3) && MathAbs(line2-line3)>distanceEMAs*Point)
        current_direction = 1;  //up
     if((line1 < line2) &&(line1 < line3) && MathAbs(line2-line3)>distanceEMAs*Point)
        current_direction = 2;  //down
 
AutoJo:

Is it reasonable to edit the EA according to this: Do not alert if the short ema crossed the others within a short timeframe (1 Minute, 2 minutes)? Or is there another possibility, how to handle that?

When I edit the Crossings function above in the way that there should be a certain distance between the short ema and the others, my EA alerts too late - even much later than when the crossing took place.

But I plan a strategy that the signal should appear right at the time when the crossing appears.

Don't change your Crossed() function, but record time of last crossing and when a new cross is detected check that elapsed time is > to your limit.
 
angevoyageur:
Don't change your Crossed() function, but record time of last crossing and when a new cross is detected check that elapsed time is > to your limit.


Hello,


thanks for your advice.


I tried to implement it, but don't know, how to it works for different currencies on different timeframes.

My EA should work parallel for (e.g.):

EUR/USD: timeframes: 60, 30, 15 min

GBP/USD: timeframes: 60, 30, 15 min

USD/JPY: timeframes: 60, 30, 15 min

AUD/USD: timeframes: 60, 30, 15 min


I don't know, how to handle the following example-case:

Alert at 21.30h: EUR/USD Crossing, timeframe: 60min (should be traded)

Alert at 21.31h: GBP/USD Crossing, timeframe: 15min (should be traded)

Alert at 21:32h: EUR/USD Crossing, timeframe: 60min (should not be traded)

with just checking that elapsed time is above my limit.


Kind regards,

AutoJo

Reason: