EA Error

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-TakeProfit
Point,“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+TakeProfit
Point,“My EA”,12345,0,Green);

}
return(0);

}
return(0);

}
//±-----------------------------------------------------------------+

It works for me. it does not open alot of orders because you have it set to a high stoploss and takeprofit.

if(maincurrent_dirction != mainlast_direction) //main changed
//{
//mainlast_direction = maincurrent_dirction;

Why not just return maincurrent_dirction?

   double ma=iMA(NULL,0,maperiod1,0,mamethod,maprice,shift);
   double maa=iMA(NULL,0,maperiod1,0,mamethod,maprice,shift+1);
   
   double ma2=iMA(NULL,0,maperiod2,0,mamethod,maprice,shift);
   double ma2a=iMA(NULL,0,maperiod2,0,mamethod,maprice,shift+1);
   
  
   if(ma>ma2 && maa<ma2a ) //buy;
   if(ma<ma2 && maa>ma2a ) //sell;

You r better off doing something like this to find your MA crosses. Otherwise you will have a buy or sell order as soon as you close a trade, instead of the ma cross.

Then you could use an opposite close?