EA with 3 Moving Averages

To add comments, please log in or register
Blancomi
21
Blancomi  

Hi Everyone!


i'm a beginner and i'm trying to create an EA which uses 3 Moving Averages.


First i was using 2 MA, no Problem.


But there a Problems with 3 MA.


The Code:

if(timestamp == iTime(Symbol(),Timeframe,0)) return;
  timestamp = iTime(Symbol(),Timeframe,0);
 
  double maFast = iMA(Symbol(),Timeframe,PeriodsMAFast,0,MethodMAFast,PRICE_CLOSE,1);
  double maSlow = iMA(Symbol(),Timeframe,PeriodsMASlow,0,MethodMASlow,PRICE_CLOSE,1);
  double maSlower = iMA(Symbol(),Timeframe,PeriodsMASlower,0,MethodMASlower,PRICE_CLOSE,1);
  double maFastLast = iMA(Symbol(),Timeframe,PeriodsMAFast,0,MethodMAFast,PRICE_CLOSE,2);
  double maSlowLast = iMA(Symbol(),Timeframe,PeriodsMASlow,0,MethodMASlow,PRICE_CLOSE,2);
  double maSlowerLast = iMA(Symbol(),Timeframe,PeriodsMASlower,0,MethodMASlower,PRICE_CLOSE,2);
  
 
  
  if(maFast > maSlow && maFast > maSlower && maSlow > maSlower && maFastLast < maSlowLast && maFastLast < maSlowerLast && maSlowLast < maSlowerLast){
     Print("Long");
     int ticket = executeLong();
     Print(IntegerToString(ticket));
  }else if (maFast < maSlow && maFast < maSlower && maSlow < maSlower && maFastLast > maSlowLast && maFastLast > maSlowerLast && maSlowLast > maSlowerLast){
     Print("Short");
     int ticket = executeShort();
     Print(IntegerToString(ticket));
     }
  }

Sometimes it works:

Open Position

Sometimes it doesn't work:

No Position opened


The EA should open Positions, if the 3 MA a Crossing.


Thank you for your help!

Carl Schreiber
Moderator
8500
Carl Schreiber  
Search first before you try - there is almost nothing that has not been coded for Mt4/5 - I am sure there are quite a lot of EA like yours - without error!
Blancomi
21
Blancomi  
You're Right. But i want to learn how it works
To add comments, please log in or register