Function Close Buy and Close Sell for EA?

 
Galera alguém consegue me ajudar com esse código abaixo?

eu anexei uma imagem mostrando como fica o EA Anexado em com ordens em Sell abertas, no iMA abaixo ele me mostra que o trend mudou mas não fecha as ordens.

se alguém tiver alguma idéia pra arrumar isso eu posto o EA depois dessa correção.


Obrigado!
if (ClosePosition_TrendInverse) {


int ticket = 0;
  MC3=-1;
  
     if (Bid<iMA(Symbol(),MATF,MA_ClosePeriodH4,0,MODE_SMMA,PRICE_CLOSE,MODE_MAIN)) MC3=1;
     
     if (Bid>iMA(Symbol(),MATF,MA_ClosePeriodH4,0,MODE_SMMA,PRICE_CLOSE,MODE_MAIN)) MC3=0;
     
     if (MC3==0){
     MarketInfo(Symbol(),MODE_ASK);
     if(OrderSelect(1, SELECT_BY_TICKET, MODE_TRADES)==True) ticket=OrderTicket();
     if(OrderClose(ticket,OrderLots(),Ask,3,Red)==True) Print("Sell closed at: ",OrderClosePrice());

   }
     if (MC3==1){
     MarketInfo(Symbol(),MODE_BID);
     if(OrderSelect(1, SELECT_BY_TICKET, MODE_TRADES)==True) ticket=OrderTicket();
     if(OrderClose(ticket,OrderLots(),Bid,3,Red)==True) Print("Buy closed at: ",OrderClosePrice());

   }
  if (MC3==0) Trend_Close = "Trend UP H4, Closed Sell";
  
  if (MC3==1) Trend_Close = "Trend Down H4, Closed Buy";
   
   }
Files:
Close.jpg  101 kb
 
Guys can anyone help me with this code below? 

I've attached a picture showing how it looks in the EA Attached to Sell orders in open, magnet below it shows me that the trend has changed but does not close the orders. 

if anyone has any idea to fix this EA after I post this fix. 


Thank you!
 

...

in parts of it the result appears in the Journal that attempted to perform the action, but there was an error, ...

...

Which error ?

Reason: