Please help with my TP SL Error

Hi guys, I need some help on this. My EA seems to go a bit haywire. Occasionally it will auto SL or TP on its own even before the actual SL or TP is reached like the one shown in my screenshot. why is this so?

Thanks and regards
Terrance

//— input parameters
extern double TakeProfit=1000.0;
extern double Lots=0.1;
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);
}
}
//±-----------------------------------------------------------------+
//| expert start function |
//±-----------------------------------------------------------------+
int start()
{
//----
int cnt, ticket, total;
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
}

int isCrossed = 0;
double shortEma1 = iMA(NULL,0,10,0,MODE_LWMA,PRICE_CLOSE,1);
double longEma1 = iMA(NULL,0,20,0,MODE_LWMA,PRICE_CLOSE,1);
double shortEma2 = iMA(NULL,0,10,0,MODE_LWMA,PRICE_CLOSE,2);
double longEma2 = iMA(NULL,0,20,0,MODE_LWMA,PRICE_CLOSE,2);
double diff1 = shortEma1-longEma1;
double diff2 = shortEma2-longEma2;

mainshortEma = iMA(NULL,0,30,0,MODE_SMA,PRICE_CLOSE,0);
mainlongEma = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,0);
int mainisCrossed = mainCrossed (mainshortEma,mainlongEma);

if ((diff1*diff2)<0)
{
if (shortEma1>longEma1)
isCrossed = 1;
else isCrossed = 2;
}

total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1 && mainshortEma > mainlongEma)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLossPoint,Ask+TakeProfitPoint,
“My EA”,12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(isCrossed == 2 && mainshortEma < mainlongEma)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+S topLossPoint,
Bid-TakeProfit
Point,“My EA”,12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}

return(0);
}
//±-----------------------------------------------------------------+

I can’t see screenshot here.
This EA works normal. It’s pretty simple to make such strange things. Check if other EA is messing with trades.

Hi, here is the screen shot.