Basic EA template

 

im looking for a template for a basic EA with buy sell command, something like buy when close above MA and sell on close below. so i can edit it to my liking, is there a one around somewhere? thanks

 

Sounds like the EMA cross coded by codersguru. That was the first EA I studied, all time classic.

 

dont happen to have the link do you?

 

Templates to create EAs and Indicators:

- some good templates are here;

- templates with some new codes are here.

- Programming Modules with many programming functions are here.

 

(REPS TO ALL THAT HELP)

ok ive managed to compile a very simple setup

//+----------------------------START---------------------------------+

extern int TakeProfit = 40;

extern int StopLoss = 20;

int start()

{

double lots, ma1, stop, profit, slippage;

ma1 = iMA(NULL,0,21,0,MODE_EMA,PRICE_WEIGHTED,0);

lots = 0.1;

slippage = 3;

stop = StopLoss*Point;

profit = TakeProfit*Point;

if(Close[0]>ma1)

{

OrderSend(Symbol(), OP_BUY, lots, Ask, slippage, Ask-stop, Ask+profit, 0);

}

if(Close[0]<ma1)

{

OrderSend(Symbol(), OP_SELL, lots, Bid, slippage, Bid+stop, Bid-profit, 0);

}

return(0);

}

//+-----------------------------END----------------------------------+

buy on close above 21EMA, sell on close below. is the above code right?, when i try it on the backtest it doesnt do anything.

 

Sorry i am not a coder but i think it should be 1 instead of 0:

...

ma1 = iMA(NULL,0,21,0,MODE_EMA,PRICE_WEIGHTED,1);

...

if(Close[1]>ma1)

...

if(Close[1]<ma1)

...

 
newdigital:
Sorry i am not a coder but i think it should be 1 instead of 0:

...

ma1 = iMA(NULL,0,21,0,MODE_EMA,PRICE_WEIGHTED,1);

...

if(Close[1]>ma1)

...

if(Close[1]<ma1)

...

I am a coder. ND's suggestion would be a more sensible way to do it.

 
 

thanks zidan, i did try it but when i opened it, it has so much code and variables i wasnt sure what i could and could not edit. at least my code above i know where to change the buy sell conditions.