Problems with my moving average crossover EA.

To add comments, please log in or register
theforce
33
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
16412
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
20371
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
159843
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
William Roeder
20210
William Roeder  
Hector Pacheco
24192
Hector Pacheco  

The iMA function has the following structure:

 iMA ( 
   string        symbol,           // symbol  
   int           timeframe,         // timeframe  
   int           ma_period,         // MA averaging period  
   int           ma_shift,         // MA shift  
   int           ma_method,         // averaging method  
   int           applied_price,     // applied price  
   int           shift             // shift  
   );


The parameter applied_price can only take the following values:

PRICE_CLOSE -> 0

PRICE_OPEN -> 1

PRICE_HIGH -> 2

PRICE_LOW -> 3

PRICE_MEDIAN -> 4

PRICE_TYPICAL -> 5

PRICE_WEIGHTED -> 6


In the following code you gave wrong use to the parameter applied_price:

 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 );


You must assign some of the allowed values

Hector Pacheco
24192
Hector Pacheco  

Try this code

//Global Variables

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

extern int z= 150, w = 150; 

void OnTick()

{
int ticket;

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

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

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

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

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

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

if(maFast_1<maSlow_1 && maFast_0>=maSlow_0)//simultaneously condition

{

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

}

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

if(maFast_1>maSlow_1 && maFast_0<=maSlow_0)// simultaneously condition

{

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

}

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


  } 
To add comments, please log in or register