My EA is only opening SELL positions. I have the similar coding layout on my other EAs as well but haven't been able to figure out what's wrong with this particular one, since i don't see any error messages. Strategy Tester shows also no BUY positions being opened. The code is as below:
//Current chart, current period, number of candles, no shift, simple, current close pricedouble CurrentMainMACD = iMACD(Symbol(), PERIOD_M5, Fast, Slow, 9, PRICE_CLOSE, MODE_MAIN, 0);
//Current chart, current period, number of candles, no shift, simple, previous close pricedouble PreviousMainMACD = iMACD(Symbol(), PERIOD_M5, Fast, Slow, 9, PRICE_CLOSE, MODE_MAIN, 1);
//Current chart, current period, number of candles, no shift, simple, current close pricedouble CurrentSignalMACD = iMACD(Symbol(), PERIOD_M5, Fast, Slow, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
//Current chart, current period, number of candles, no shift, simple, previous close pricedouble PreviousSignalMACD = iMACD(Symbol(), PERIOD_M5, Fast, Slow, 9, PRICE_CLOSE, MODE_SIGNAL, 1);
double SlowEMA = iMA(NULL, 0, EMA_Period, 0, MODE_EMA, PRICE_CLOSE, 1);
//To make sure only one position is opened per barstaticdatetime prevtime = 0;
if(prevtime == Time[0])
return;
prevtime = Time[0];
{
//If fast SMA is above slow SMAif((PreviousSignalMACD < PreviousMainMACD) && (CurrentSignalMACD > CurrentMainMACD))
{
if(SlowEMA > EMA_Period)
{
//Chart output for BUY signal
signal="Buy";
}
}
//If fast SMA is below slow SMAelseif((PreviousSignalMACD > PreviousMainMACD) && (CurrentSignalMACD < CurrentMainMACD))
{
if(SlowEMA < EMA_Period)
{
//Chart output for SELL signal
signal="Sell";
}
}
//Position for BUY if(signal == "Buy")
{
//Here we are assuming that the TakeProfit and StopLoss are entered in Pips
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 10*10, Ask-SL*Point*10, Ask+TP*Point*10, "Long by MaCD & EMA", 616161, 0, Blue);
if(ticket < 0)
{
Alert("Error Sending Order! Error Code: ", GetLastError());
}
}
//Position for SELLelseif(signal == "Sell")
{
//Here we are assuming that the TakeProfit and StopLoss are entered in Pips
ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 10*10, Bid+SL*Point*10, Bid-TP*Point*10, "Short by MaCD & EMA", 616161, 0, Red);
if(ticket < 0)
{
Alert("Error Sending Order! Error Code: ", GetLastError());
}
}
}
//Create a chart outputComment("The signal is: ",signal,"\n");
SeferAmcaFTW #: I've written it as an extern input for 200 EMA, that i sometimes change into 100 or 50. So that's a buy/sell condition for being above/below 200 EMA.
I didn't ask you what you had done, I asked you why??????
Hello everyone,
My EA is only opening SELL positions. I have the similar coding layout on my other EAs as well but haven't been able to figure out what's wrong with this particular one, since i don't see any error messages. Strategy Tester shows also no BUY positions being opened. The code is as below:
Any help is appreciated.