Trade Copier Problem

 

Hello There Guys ,
i have made this trade copier Ea based on Master and Slave .
Master account just save the information of trades in excel file
and slave account take the information throw excel file and open trades on slave account , 
but what i need is i just want that slave account open the trade but close on their own tp sl , but slave does not allow me to close the trade until it close on Master account .
so what should  i suppose to do 
here is the CODE of slave EA...

//+------------------------------------------------------------------+
//|                                                 Master_Slave.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
enum copier_mode
  {
   master,
   slave,
  };
input copier_mode mode=0;  // Working mode
input int slip=10;         // Slippage (in pips)
input double mult=1.0;     // Multiplyer (for slave)

int filehandle,

type=0;

string symbol;

  



//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(!ObjectFind("mode") || ObjectDescription("mode")!=EnumToString(mode))
     {
      ObjectDelete("mode");
      ObjectCreate("mode",OBJ_LABEL,0,0,0);
      ObjectSet("mode",OBJPROP_XDISTANCE,10);
      ObjectSet("mode",OBJPROP_YDISTANCE,10);
      ObjectSet("mode",OBJPROP_COLOR,Red);
      ObjectSetText("mode",EnumToString(mode));
      ObjectSet("mode",OBJPROP_FONTSIZE,10);
     }
     
     
     
  //--- Master working mode
   if(EnumToString(mode)=="master")
     {
      //--- Saving information about opened deals
      if(OrdersTotal()==0)
        {
         filehandle=FileOpen("C4F.csv",FILE_WRITE|FILE_CSV|FILE_COMMON);
         FileWrite(filehandle,"");
         FileClose(filehandle);
        }
      else
        {
         filehandle=FileOpen("C4F.csv",FILE_WRITE|FILE_CSV|FILE_COMMON);

         if(filehandle!=INVALID_HANDLE)
           {
            for(int i=0; i<OrdersTotal(); i++)
              {
               if(!OrderSelect(i,SELECT_BY_POS)) break;
               if(OrderType()== OP_BUY)
               {
               type=1;
               }
               if(StringSubstr(OrderComment(),0,3)!="C4F") 
               FileWrite(filehandle,OrderTicket(),OrderSymbol(),type,OrderLots());
               FileFlush(filehandle);
              }
            FileClose(filehandle);
           }
        }
     }
    }
Here is the Master EA CODE..
//+------------------------------------------------------------------+
//|                                                    Simple Copier |
//|                                Copyright 2015, Vladimir V. Tkach |
//+------------------------------------------------------------------+
#property version "1.2"
#property copyright "Copyright © 2015, Vladimir V. Tkach"
#property description "Trades copying utility with multiplyer."
#property strict
//+------------------------------------------------------------------+
//| Enumerator of working mode                                       |
//+------------------------------------------------------------------+
enum copier_mode
  {
   master,
   slave,
  };

input copier_mode mode=0;  // Working mode
input int slip=10;         // Slippage (in pips)
input double mult=1.0;     // Multiplyer (for slave)
input int stoploss = 100;
input int takeprofit =100;

int
opened_list[500],
ticket,
type,
filehandle;

string
symbol;

double
lot;

//+------------------------------------------------------------------+
//|Initialisation function                                           |
//+------------------------------------------------------------------+
void init()
  {
   ObjectsDeleteAll();
   EventSetTimer(1);
   return;
  }
//+------------------------------------------------------------------+
//|Deinitialisation function                                         |
//+------------------------------------------------------------------+
void deinit()
  {
   ObjectsDeleteAll();
   EventKillTimer();
   return;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer()
  {
   if(!ObjectFind("mode") || ObjectDescription("mode")!=EnumToString(mode))
     {
      ObjectDelete("mode");
      ObjectCreate("mode",OBJ_LABEL,0,0,0);
      ObjectSet("mode",OBJPROP_XDISTANCE,10);
      ObjectSet("mode",OBJPROP_YDISTANCE,10);
      ObjectSet("mode",OBJPROP_COLOR,Red);
      ObjectSetText("mode",EnumToString(mode));
      ObjectSet("mode",OBJPROP_FONTSIZE,10);
     }


//--- Slave working mode
   if(EnumToString(mode)=="slave")
     {
      //--- Checking for the new deals and stop loss/take profit changes
      filehandle=FileOpen("C4F.csv",FILE_READ|FILE_CSV|FILE_COMMON);

      if(filehandle!=INVALID_HANDLE)
        {
         int o=0;
         opened_list[o]=0;

         while(!FileIsEnding(filehandle))
           {
            ticket=StrToInteger(FileReadString(filehandle));
            symbol=FileReadString(filehandle);
            type=StrToInteger(FileReadString(filehandle));
            lot=StrToDouble(FileReadString(filehandle));


            string
            OrdComm="C4F"+IntegerToString(ticket);

          for(int i=0; i<OrdersTotal(); i++)
              {
               if(!OrderSelect(i,SELECT_BY_POS)) continue;
               
               if(OrderComment()!=OrdComm) continue;

             opened_list[o]=ticket;
               opened_list[o+1]=0;
              // Comment(opened_list[0]);
               o++;
              break;
              }

            //--- If deal was not opened yet on slave-account, open it.
            if(InList(ticket)==-1 && ticket!=0)
              {
               FileClose(filehandle);
               if(type<2) OpenMarketOrder(ticket,symbol,type,lot);
               return;
              }
           }
         FileClose(filehandle);
        }
      else return;
     }
  }
//+------------------------------------------------------------------+
//|Checking list                                                     |
//+------------------------------------------------------------------+
int InList(int ticket_)
  {
  Comment(ticket_);
   int h=0;

   while(opened_list[h]!=0)
     {
      if(opened_list[h]==ticket_) return(1);
      h++;
     }
   return(-1);
  }
//+------------------------------------------------------------------+
//|Open market execution orders                                      |
//+------------------------------------------------------------------+
void OpenMarketOrder(int ticket_,string symbol_,int type_,double lot_)
  {
   if(type_==0) 
   {
   if(!OrderSend(symbol_,type_,LotNormalize(lot_),Ask,slip,Ask-stoploss*RealPipPoint(Symbol()),Ask+takeprofit*RealPipPoint(Symbol()),"C4F"+IntegerToString(ticket_)))
    Comment("Error: ",GetLastError()," during opening the market order.");
    }
       if(type_==1) 
   if(!OrderSend(symbol_,type_,LotNormalize(lot_),Bid,slip,Bid+stoploss*RealPipPoint(Symbol()),Bid-takeprofit*RealPipPoint(Symbol()),"C4F"+IntegerToString(ticket_)))
    Comment("Error: ",GetLastError()," during opening the market order.");
    
   return;
  }

//+------------------------------------------------------------------+
//|Normalize lot size                                                |
//+------------------------------------------------------------------+
double LotNormalize(double lot_)
  {
   double minlot=MarketInfo(symbol,MODE_MINLOT);

   if(minlot==0.001)      return(NormalizeDouble(lot_,3));
   else if(minlot==0.01)  return(NormalizeDouble(lot_,2));
   else if(minlot==0.1)   return(NormalizeDouble(lot_,1));

   return(NormalizeDouble(lot_,0));
  }
//+------------------------------------------------------------------+
// Pip Point Function
double RealPipPoint(string Currency)
  {
   double CalcPoint;
   int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
   if(CalcDigits == 2 || CalcDigits == 3)
      CalcPoint = 0.01;
   else
      if(CalcDigits == 4 || CalcDigits == 5)
         CalcPoint = 0.0001;
   return(CalcPoint);
  }