hello everyone,
i am trying writing a very simple EA for MT4. i dont know yet if this is correct code. but i run it. only few result because of the conditions, i think.
i am just a newbie for this. hope good samaritan out there can help me improve this.
the conditions are in this script, but i want to add an AUTO_TAKE_PROFIT to close order for buy once the price will cross the Moving Average and close below MA, and auto take profit to close order for sell once the price will cross the Moving Average and close above MA.
and add aTRAIL STOPS too. please help. thank you.
double MA1 = iMA(NULL,0,period,0, MODE_EMA,PRICE_CLOSE,barshift);
double OpenPrice = Open[1];
double ClosePrice = Close[1];
double LowPrice = Low[1];
double HighPrice = High[1];
double OpenBuyOrder;
double OpenSellOrder;
if((HighPrice>MA1)&&(LowPrice<MA1))
{
OpenSellOrder=OrderSend(Symbol(),OP_SELL,Lots,Bid,2,0,0,MAGICNUM,0,Red);
}
else if((LowPrice<MA1)&&(HighPrice>MA1))
{
OpenBuyOrder=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,0,0,MAGICNUM,0,Green);
}
i am trying writing a very simple EA for MT4. i dont know yet if this is correct code. but i run it. only few result because of the conditions, i think.
i am just a newbie for this. hope good samaritan out there can help me improve this.
the conditions are in this script, but i want to add an AUTO_TAKE_PROFIT to close order for buy once the price will cross the Moving Average and close below MA, and auto take profit to close order for sell once the price will cross the Moving Average and close above MA.
and add aTRAIL STOPS too. please help. thank you.
double MA1 = iMA(NULL,0,period,0, MODE_EMA,PRICE_CLOSE,barshift);
double OpenPrice = Open[1];
double ClosePrice = Close[1];
double LowPrice = Low[1];
double HighPrice = High[1];
double OpenBuyOrder;
double OpenSellOrder;
if((HighPrice>MA1)&&(LowPrice<MA1))
{
OpenSellOrder=OrderSend(Symbol(),OP_SELL,Lots,Bid,2,0,0,MAGICNUM,0,Red);
}
else if((LowPrice<MA1)&&(HighPrice>MA1))
{
OpenBuyOrder=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,0,0,MAGICNUM,0,Green);
}