Basic EA template

 

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.

 

Seems ok to me. What did the logs say? Backtest again and check the Journal tab or log files in metatrader 4\logs\ folder. Zip em up for fast upload.

 

i was playing around with it last night ..... turns out it does work fine, it was something to do with MT not my code, i changed my demo to another broker and got many trades. thanks.

Reason: