Why my trade close prematurely?

 
 #property copyright "Ch"

 

 int handle,i,Total;
 int Slip = 3;
 int BuyTicket;
 int SellTicket;
 double H1W4_0,H1W4_1,H1W20_0,H1W20_1;
 double iCH10,xMultiply,zH1W420_00,zH1W420_11;

 

 
 // Init function
 int init()
 {
 if(Digits==2) xMultiply =10;
 if(Digits==3) xMultiply=100;
 if(Digits==5) xMultiply=10000;
 return(1);

 }

 // Start function
 int start()
 {
 iCH10=  iClose(Symbol(),PERIOD_H1,0);
 H1W4_0=iMA(NULL,PERIOD_H1,4,0,MODE_LWMA,PRICE_CLOSE,0); 
 H1W4_1=iMA(NULL,PERIOD_H1,4,0,MODE_LWMA,PRICE_CLOSE,1); 
 H1W20_0=iMA(NULL,PERIOD_H1,20,0,MODE_LWMA,PRICE_CLOSE,0); 
 H1W20_1=iMA(NULL,PERIOD_H1,20,0,MODE_LWMA,PRICE_CLOSE,1);
 zH1W420_00=(H1W4_0-H1W20_0)*xMultiply; 
 zH1W420_11=(H1W4_1-H1W20_1)*xMultiply; 

 

 Total=OrdersTotal();


 //***************CLOSE TRADES IF zH1W420_11><=0 && zH1W420_22><=0 STARTED ******************

 for(  i=0; i<Total; i++)
 {
 OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

 if(OrderType()== OP_BUY && zH1W420_00<=0 && zH1W420_11>=0 && (iCH10-OrderOpenPrice())*xMultiply >=50 ) 
      {
 OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Red);
 handle=FileOpen("Trades.csv",FILE_CSV|FILE_READ|FILE_WRITE,',');
 FileSeek(handle, 0, SEEK_END); 
 FileWrite(handle,Symbol(),TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS),"U","Close #",BuyTicket," : zH1W420_11<=0 :",NormalizeDouble(zH1W420_00,1)," zH1W420_22>=0 :",NormalizeDouble(zH1W420_11,1)); 
 FileClose(handle);                                         
      }
 if(OrderType()== OP_SELL && zH1W420_00>=0 && zH1W420_11<=0 && (OrderOpenPrice()-iCH10)*xMultiply >=50 ) 
      {
 OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red);
 handle=FileOpen("Trades.csv",FILE_CSV|FILE_READ|FILE_WRITE,',');
 FileSeek(handle, 0, SEEK_END); 
 FileWrite(handle,Symbol(),TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS),"D","Close #",SellTicket," : zH1W420_11>=0  :", NormalizeDouble(zH1W420_00,1),"  zH1W420_22<=0 :",NormalizeDouble(zH1W420_11,1)); 
 FileClose(handle);                            
      } 
 }

 //***************CLOSE TRADES IF zH1W420_11><=0 && zH1W420_22><=0 ENDED ******************


 return(0);

 }

 

This code close the manually open trades when

1) LMWA4 and LMWA20 crossed

2) When the profit is more than 50 pips.

Why my trades are closed before LMWA4 and LMWA20 crossed and profit still less than 50 pips? Also, why there are warning messages as below:

return value of 'OrderSelect' should be checked 20250314 Simplified EA.mq4 45 2

return value of 'OrderClose' should be checked 20250314 Simplified EA.mq4 49 2

return value of 'OrderClose' should be checked 20250314 Simplified EA.mq4 57 2


Please help , thanks