Download MetaTrader 5
To add comments, please log in or register
Have you published a program in the Market? Place it in your blog as well - the widget will help!
AutoJo
12
AutoJo 2013.12.17 22:32 

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);
        }
    }
Alain Verleyen
Moderator
30298
Alain Verleyen 2013.12.17 23:20  

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.

AutoJo
12
AutoJo 2013.12.18 08:19  

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
Alain Verleyen
Moderator
30298
Alain Verleyen 2013.12.18 09:58  
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.
AutoJo
12
AutoJo 2014.01.07 20:33  
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

/
To add comments, please log in or register