Hi guys, I am having some error with my EA codes and would like you to seek help here. I have done some editing previously however, my EA still only opens 1 trade and the stop executing new trades can some1 point me in the right direction here?
my strategy works in such a way that if SMA 20 crosses SMA 50 downwards (downtrend) the system will only open trade when LWMA 10 crosses LWMA 20 downwards and ignoring the crosses upwards.
the reverse is the same for when SMA 20 crosses SMA 50 upwards for a uptrend.
Thanks
//— input parameters
extern double TakeProfit=1000.0;
extern double Lots=0.01;
extern double StopLoss=1500.0;
//±-----------------------------------------------------------------+
//| expert initialization function |
//±-----------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//±-----------------------------------------------------------------+
//| expert deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
int mainCrossed (double mainline1 , double mainline2)
{
static int mainlast_direction = 0;
static int maincurrent_dirction = 0;
if(mainline1>mainline2)maincurrent_dirction = 1; //main up
if(mainline1<mainline2)maincurrent_dirction = 2; //main down
if(maincurrent_dirction != mainlast_direction) //main changed
{
mainlast_direction = maincurrent_dirction;
return (mainlast_direction);
}
else
{
return (0);
}
}
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_dirction = 0;
if(line1>line2)current_dirction = 1; //up
if(line1<line2)current_dirction = 2; //down
if(current_dirction != last_direction) //changed
{
last_direction = current_dirction;
return (last_direction);
}
else
{
return (0);
}
}
//±-----------------------------------------------------------------+
//| expert start function |
//±-----------------------------------------------------------------+
int start()
{
//----
int cnt, ticket, total, downcounter, upcounter;
double shortEma, longEma, mainshortEma, mainlongEma;
if(Bars<100)
{
Print(“bars less than 100”);
return(0);
}
if(TakeProfit<10)
{
Print(“TakeProfit less than 10”);
return(0); // check TakeProfit
}
shortEma = iMA(NULL,0,10,0,MODE_LWMA,PRICE_CLOSE,0);
longEma = iMA(NULL,0,20,0,MODE_LWMA,PRICE_CLOSE,0);
mainshortEma = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
mainlongEma = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,0);
int mainisCrossed = mainCrossed (mainshortEma,mainlongEma);
int isCrossed = Crossed (shortEma,longEma);
total = OrdersTotal();
downcounter = 1;
upcounter = 1;
if(mainisCrossed == 2)
{
downcounter++;
if(total < 1 && isCrossed == 2 && downcounter > 1)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+S topLossPoint,
Bid-TakeProfitPoint,“My EA”,12345,0,Red);
}
return(0);
}
return(0);
if(mainisCrossed == 1)
{
upcounter++;
if(total < 1 && isCrossed == 1 && upcounter > 1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLossPoint,
Ask+TakeProfitPoint,“My EA”,12345,0,Green);
}
return(0);
}
return(0);
}
//±-----------------------------------------------------------------+