Download MetaTrader 5

Problems with my moving average crossover EA.

To add comments, please log in or register
theforce
22
theforce  

Hi, I am preparing my first "simple" strategy, but for me it wasn´t that simple... I created this code:

 

 //Global Variables

extern int slow =  9, fast = 3; // for subsequent optimization process **

extern int z= 150, w = 150; 

 int start()

{

//--------------------------------------------------------Variables declaration. 

int pricet = (High[1]+Close[1]+Low[1])/3;

int ma1 =iMA(NULL, 0, slow, 0,MODE_SMA, PRICE_TYPICAL,0);

int ma2 =iMA(NULL, 0, fast, 0, MODE_SMA, PRICE_TYPICAL,0);

int ma3 =iMA(NULL, 0, slow, 0,MODE_SMA, pricet,0);// I created this variable for simultaneously condition.

int ma4=iMA(NULL, 0, fast, 0, MODE_SMA, pricet,0);  

//---------------------------------------------------

if(ma4<ma3 && ma2 == ma1)//simultaneously condition

{

int ticket = OrderSend(Symbol(),OP_BUY,0.03,Ask, 2, Bid-z*Point, Bid+w*Point);

}

//----------------------------------------------------

if(ma4>ma3 && ma2== ma1)// simultaneously condition

{

 ticket = OrderSend(Symbol(),OP_SELL,0.03,Bid, 2, Ask-z*Point, Ask+w*Point);

  }

 //----------------------------------------------------

  return(ticket);

  } 

 

When I run it with the strategy tester, it just doesnt execute the OrderSend(). Anyone can help me please :)???? 

Mohamad Zulhairi Baba
7007
Mohamad Zulhairi Baba  
theforce:

Hi, I am preparing my first "simple" strategy, but for me it wasn´t that simple... I created this code:

 

 //Global Variables

extern int slow =  9, fast = 3; // for subsequent optimization process **

extern int z= 150, w = 150; 

 int start()

{

//--------------------------------------------------------Variables declaration. 

int pricet = (High[1]+Close[1]+Low[1])/3;

int ma1 =iMA(NULL, 0, slow, 0,MODE_SMA, PRICE_TYPICAL,0);

int ma2 =iMA(NULL, 0, fast, 0, MODE_SMA, PRICE_TYPICAL,0);

int ma3 =iMA(NULL, 0, slow, 0,MODE_SMA, pricet,0);// I created this variable for simultaneously condition.

int ma4=iMA(NULL, 0, fast, 0, MODE_SMA, pricet,0);  

//---------------------------------------------------

if(ma4<ma3 && ma2 == ma1)//simultaneously condition

{

int ticket = OrderSend(Symbol(),OP_BUY,0.03,Ask, 2, Bid-z*Point, Bid+w*Point);

}

//----------------------------------------------------

if(ma4>ma3 && ma2== ma1)// simultaneously condition

{

 ticket = OrderSend(Symbol(),OP_SELL,0.03,Bid, 2, Ask-z*Point, Ask+w*Point);

  }

 //----------------------------------------------------

  return(ticket);

  } 

 

When I run it with the strategy tester, it just doesnt execute the OrderSend(). Anyone can help me please :)???? 

loop in void OnTick()
Keith Watford
Moderator
10619
Keith Watford  
ticket = OrderSend(Symbol(),OP_SELL,0.03,Bid, 2, Ask-z*Point, Ask+w*Point);
Do you have your SL and TP reversed?

Please use the SRC button when posting code, I have done it for you this time.
Mladen Rakic
62820
Mladen Rakic  
theforce:

Hi, I am preparing my first "simple" strategy, but for me it wasn´t that simple... I created this code:

When I run it with the strategy tester, it just doesnt execute the OrderSend(). Anyone can help me please :)????

 



Your ma1 and m12 will almost never be equal. It is a bad idea to us a comparison like this
if(ma4<ma3 && ma2 == ma1)
or this :
if(ma4>ma3 && ma2 == ma1)
in the conditions - it will, as you have already noticed, almost never happen. Use some other conditions
whroeder1
16058
whroeder1  
To add comments, please log in or register