EA copier slave

 
Please can someone advise me how to modify the ea to copy the SL aTP and not close the trade according to the master ea? Thank you
Files:
 
Zbynek Liska: Please can someone advise me how to modify
  1. Open the editor and change it.

  2. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help (2017)

 
The problem is that it does not copy tp and sl and closes according to Master EA.  I don't want someone to redo it for me, just take a professional look to see if there is an easy solution
input int MasterAccountNumber = 66521433;                 //Master Account Number
input int Coefficient = 1;                         //Coefficient
input double MultipleLot = 2;                         //Multiple Lot
input int AllowDelayTime = 3;                      //Allow Delay Time(Second)

input string MajorPrefix = "";   //Master Prefix
input string MajorSuffix = "";   //Master Suffix
input string FollowPrefix = "";  //Slaver Prefix
input string FollowSuffix = "";  //Slaver Suffix

string openfilename = "";     //主信号交易情况的文件
string closefilename = "";    //判断是否需要平仓
string SharedFolders = "C:\\SharedFolder";  //共享文件夹

string            LabelName = "Label6";            // label name
string            LabelName1 = "Label1";            // label name
string            LabelName2 = "Label2";            // label name
string            LabelName3 = "Label3";            // label name
string            LabelName4 = "Label4";            // label name
string            LabelName5 = "Label5";            // label name


string            LabelText = "";          
ENUM_BASE_CORNER  LabelCorner = CORNER_RIGHT_UPPER;
input int               X1 = 300;                      //X coordinate 
input int               Y1 = 30;                       //Y coordinate 
input int               FontSize = 12;
input color               FontColor = clrWhite;


 input bool UseMajorSLAndTp = true;              //使用主账号的止损止盈值:是/否
input int  SL = 500;                            //止损值(points)
input int  TP = 500;                            //止盈值(points)

int LabelDistance = 20;
string prefix = "";
string EAComment = "FollowTicket";
int Slippage = 5;
int InpEncodingType = FILE_ANSI; // ANSI=32 or UNICODE=64 

int MagicNumber = 331652131;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{

//---
  prefix = Symbol();
  openfilename = IntegerToString(MasterAccountNumber) + "Open.txt";   //获取主信号的文件名,当前交易信息
  closefilename = IntegerToString(MasterAccountNumber) + "Close.txt";
  
  LabelText = "=========Start Copy======";
  LabelCreate(prefix + LabelName1, LabelCorner,X1,Y1,LabelText,FontSize,FontColor);
  
  LabelText = "Master Account: " + IntegerToString(MasterAccountNumber);
  LabelCreate(prefix + LabelName2, LabelCorner,X1,Y1 + LabelDistance,LabelText,FontSize,FontColor);
  
  LabelText = "Copy Account: " + IntegerToString(AccountNumber());
  LabelCreate(prefix + LabelName3, LabelCorner,X1,Y1 + LabelDistance * 2,LabelText,FontSize,FontColor);
  
  LabelText = "Coefficient: " + IntegerToString(Coefficient);
  LabelCreate(prefix + LabelName4, LabelCorner,X1,Y1 + LabelDistance * 3,LabelText,FontSize,FontColor);
  
  LabelText = "MultipleLot: " + IntegerToString(MultipleLot);
  LabelCreate(prefix + LabelName5, LabelCorner,X1,Y1 + LabelDistance * 4,LabelText,FontSize,FontColor);


  // EventKillTimer();
  
  EventSetMillisecondTimer(100);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
  DeleteGlobalVariables();
   DeleteAllObject();
   EventKillTimer();
}

void OnTimer()
{
  CloseBySlOrTP();
  ReadInfoAndOpenTicket();
  
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+
//获取主信号下单情况处理当前订单
void ReadInfoAndOpenTicket()
{ 
  int flag = CopyFileW(SharedFolders + "\\" + openfilename,TerminalInfoString(TERMINAL_DATA_PATH)+"\\MQL4\\Files" + "\\" + openfilename,0);
  string line = "";
  string ArrayBuf[9];
  
  long ticket = 0;
  string symbol = "";
  double lot = 0;
  long ordertype = 0;
  double openprice = 0;
   double sl = 0; 
   double tp = 0;
  double sl_point = 0; 
  double tp_point = 0;
  
  int opentime = 0;
  int platformtime = 0;
  int differencetime = 0;
  double pendingdistance = 0;

  
  double myopenprice = 0;
  double mystoploss = 0;
  double mytakeprofit = 0;
  int mytype = 0;
  int length = 0;

  int filehandle = FileOpen(openfilename,FILE_READ|FILE_TXT|InpEncodingType);
  
  //需要获取以下所在市场的数据写入csv文件
  if(filehandle != INVALID_HANDLE)
  {      
    while(!FileIsEnding(filehandle)) 
    {
        line = FileReadString(filehandle); 
        length = StringSplit(line,';', ArrayBuf);
        if(length < 8) continue;
        
        ticket = StringToInteger(ArrayBuf[0]);  
        symbol = ArrayBuf[1];
        symbol = GetSymbol(symbol);
        
        
        lot = NormalizeDouble(StringToDouble(ArrayBuf[2]),2);
        ordertype = StringToInteger(ArrayBuf[3]);
        openprice = NormalizeDouble(StringToDouble(ArrayBuf[4]),SymbolInfoInteger(symbol,SYMBOL_DIGITS));
        sl_point = NormalizeDouble(StringToDouble(ArrayBuf[5]),0);
        tp_point = NormalizeDouble(StringToDouble(ArrayBuf[6]),0);
        opentime = StringToInteger(ArrayBuf[7]);
        platformtime = StringToInteger(ArrayBuf[8]);
        
        pendingdistance = StringToDouble(ArrayBuf[9]);
        EAComment = IntegerToString(ticket);
        
        if(ticket > 0)  //查找是否存在改订单,进行下单
        {
          bool exist = false;
          for(int i = 0; i < OrdersTotal();i++)
          {
            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            {
              if(OrderComment() == EAComment) //订单存在
              {
                exist = true;
                break;
              }
            }
          }
  
          if(!exist && (int)TimeCurrent() - (int)opentime /*+ differencetime)*/ >= AllowDelayTime) //订单不存在,而且在符合延时时间范围内
          {
            if(ordertype == OP_BUYLIMIT)
            {
                myopenprice = GetOpenPrice(symbol,OP_BUYLIMIT,openprice,pendingdistance);
                if(sl_point > 0)
                {
                  sl = myopenprice - sl_point * GetPoint(symbol);
                }
                else
                {
                  sl = 0;
                }
                if(tp_point > 0)
                {
                  tp = myopenprice + tp_point * GetPoint(symbol);
                }
                else
                {
                  tp = 0;
                }
            }
            else if(ordertype == OP_SELLLIMIT ) // ||ordertype ==OP_SELL
            {
                myopenprice = GetOpenPrice(symbol,OP_SELLLIMIT,openprice,pendingdistance);
                if(sl_point > 0)
                {
                  sl = myopenprice + sl_point * GetPoint(symbol);
                }
                else
                {
                  sl = 0;
                }
                if(tp_point > 0)
                {
                  tp = myopenprice - tp_point * GetPoint(symbol);
                }
                else
                {
                  tp = 0;
                }
            }
            else
            { 
                continue;
            }
            
            lot = GetLot(lot);  //倍数
            PendingOrder(symbol,ordertype,lot, myopenprice,sl,tp,EAComment,MagicNumber); //ticket 作为Magic Number
          }
        }
    }
    FileClose(filehandle);
  }
}

double GetLot(double inLot)
{
  double lot = 0;
  lot = inLot * MultipleLot;
    
  double   min_lot     = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
  double   max_lot     = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
  int lotdigits = 0;
  if(StringFind(min_lot,".",0) < 0)
  { 
    lotdigits = 0; 
  }
  else 
  { 
    lotdigits = (StringLen(min_lot) - (StringFind(min_lot,".",0) + 1)); 
  }
  double   lots        = 0;
  lots = NormalizeDouble(lot, lotdigits);
  if (lots < min_lot) lots = min_lot;
  if (lots > max_lot) lots = max_lot;
  return lots;
}

void CloseBySlOrTP()
{
  string symbol = "";
  int ticket = 0;
  for(int i=0;i < OrdersTotal();i++)
  {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true
       && OrderMagicNumber() == MagicNumber 
       && OrderType() <= OP_SELL)
    {
      ticket = OrderTicket();
      symbol = OrderSymbol();

      if(OrderType() == OP_BUY
        && GVGet("Ticket SL" + IntegerToString(ticket)) > 0
        && SymbolInfoDouble(symbol,SYMBOL_BID) <= GVGet("Ticket SL" + IntegerToString(ticket)))
      {
          if(!OrderClose(ticket,OrderLots(),SymbolInfoDouble(symbol,SYMBOL_BID),Slippage,clrNONE))
          {
            Print("Close order failed, error:",GetLastError());
          }
          else
          {
            Print("Ticket:" + IntegerToString(ticket) + " Close By Touch SL");
          }
      }
      else  if(OrderType() == OP_BUY
        && GVGet("Ticket TP" + IntegerToString(ticket)) > 0
        && SymbolInfoDouble(symbol,SYMBOL_BID) >= GVGet("Ticket TP" + IntegerToString(ticket)))
      {
          if(!OrderClose(ticket,OrderLots(),SymbolInfoDouble(symbol,SYMBOL_BID),Slippage,clrNONE))
          {
            Print("Close order failed, error:",GetLastError());
          }
          else
          {
            Print("Ticket:" + IntegerToString(ticket) + " Close By Touch TP");
          }
      }
      
      else if(OrderType() == OP_SELL
        && GVGet("Ticket SL" + IntegerToString(ticket)) > 0
        && SymbolInfoDouble(symbol,SYMBOL_ASK) >= GVGet("Ticket SL" + IntegerToString(ticket)))
      {
          if(!OrderClose(ticket,OrderLots(),SymbolInfoDouble(symbol,SYMBOL_ASK),Slippage,clrNONE))
          {
            Print("Close order failed, error:",GetLastError());
          }
          else
          {
            Print("Ticket:" + IntegerToString(ticket) + " Close By Touch SL");
          }
      }
      else  if(OrderType() == OP_SELL
        && GVGet("Ticket TP" + IntegerToString(ticket)) > 0
        && SymbolInfoDouble(symbol,SYMBOL_ASK) <= GVGet("Ticket TP" + IntegerToString(ticket)))
      {
          if(!OrderClose(ticket,OrderLots(),SymbolInfoDouble(symbol,SYMBOL_ASK),Slippage,clrNONE))
          {
            Print("Close order failed, error:",GetLastError());
          }
          else
          {
            Print("Ticket:" + IntegerToString(ticket) + " Close By Touch TP");
          }
      }
    }
  }
}


void PendingOrder(string inSymbol,int inType, double inLot, double inOpenPrice,double inSL,double inTP,string inComment,int inMagicNumber)
{
  double mystoploss = 0;
  double mytakeprofit = 0;
  double myopenprice = 0;
  color opencolor = NULL;
 
  myopenprice = inOpenPrice;
  mystoploss = inSL;
  mytakeprofit = inTP;

  if(inType == OP_BUYLIMIT || inType == OP_BUYSTOP)
  {
    opencolor = clrBlue; 
  }
  else if(inType == OP_SELLLIMIT  || inType == OP_SELLSTOP)
  {
    opencolor = clrRed; 
  }
  
  int ticket = OrderSend(inSymbol,inType,inLot,myopenprice,Slippage,0,0,inComment,inMagicNumber,0,opencolor);
  if(ticket <= 0)
  {
    Print("Pending order open failed, Error reason:", GetLastError());
  }
  else
  {
    GVSet("Ticket SL" + IntegerToString(ticket),mystoploss);
    GVSet("Ticket TP" + IntegerToString(ticket),mytakeprofit);
    Print("Ticket: " + IntegerToString(ticket) + ",open @" + myopenprice + ",SL @" + mystoploss + ",TP @" + mytakeprofit);
  }
}


double GetOpenPrice(string inSymbol,int inType,double inOpenprice, double inDistance)
{
  double openprice = 0;
  double total_distance = 0;
      
  
  for(int i = 1;i <= Coefficient;i++)
  {
    total_distance = total_distance + i * inDistance;
  }
  
  if(inType == OP_BUYLIMIT)
  {
    openprice = inOpenprice - total_distance * GetP(inSymbol) * GetPoint(inSymbol);


  }
  else if(inType == OP_SELLLIMIT)
  {
    openprice = inOpenprice + total_distance * GetP(inSymbol) * GetPoint(inSymbol);
  }
  
  
  return openprice;
}

double GetPoint(string inSymbol)
{
  double value = SymbolInfoDouble(inSymbol,SYMBOL_POINT);
  return value;
}

int GetP(string inSymbol)
{
  int p = 1;
  if(SymbolInfoInteger(inSymbol,SYMBOL_DIGITS) == 3 
  || SymbolInfoInteger(inSymbol,SYMBOL_DIGITS) == 5)
  {
    p = 10;
  }
  else
  {
    p = 1;
  }
  return p;
}



//前缀和后缀:传入是主信号货币对
string GetSymbol(string inSymbol)
{
  string result = inSymbol;
  if(MajorPrefix != "")
  {
    StringReplace(result,MajorPrefix,""); 
  }
  if(MajorSuffix != "")
  { 
    StringReplace(result,MajorSuffix,"");
  }
  
  result = FollowPrefix + result + FollowSuffix;
  return result;
}





double GetSL(string inSymbol,int inType,double inOpenprice,int inSL)
{
  double price = 0;
  if(inType == OP_BUY || inType == OP_BUYLIMIT || inType == OP_BUYSTOP)
  {
    if(inSL > 0)
    {
      price = inOpenprice - inSL * SymbolInfoDouble(inSymbol,SYMBOL_POINT);
    }
    else 
    {
      price = 0;
    }
  } 
  else if(inType == OP_SELL || inType == OP_SELLLIMIT || inType == OP_SELLSTOP)
  {
    if(inSL > 0)
    {
      price = inOpenprice + inSL  * SymbolInfoDouble(inSymbol,SYMBOL_POINT);
    }
    else 
    {
      price = 0;
    }
  } 
  return price;
}

double GetTP(string inSymbol,int inType,double inOpenprice,int inTP)
{
  double price = 0;
  if(inType == OP_BUY || inType == OP_BUYLIMIT || inType == OP_BUYSTOP)
  {
    if(inTP > 0)
    {
      price = inOpenprice + inTP * GetP(inSymbol) * SymbolInfoDouble(inSymbol,SYMBOL_POINT);
    }
    else 
    {
      price = 0;
    }
  } 
  else if(inType == OP_SELL || inType == OP_SELLLIMIT || inType == OP_SELLSTOP)
  {
    if(inTP > 0)
    {
      price = inOpenprice - inTP * GetP(inSymbol) * SymbolInfoDouble(inSymbol,SYMBOL_POINT);
    }
    else 
    {
      price = 0;
    }
  } 
  return price;
}

//+------------------------------------------------------------------+ 
//| Create a text label                                              | 
//+------------------------------------------------------------------+ 
void LabelCreate(string            name="Label",             // label name
                 ENUM_BASE_CORNER  corner=CORNER_RIGHT_UPPER, // chart corner for anchoring  
                 int               x=0,                      // X coordinate 
                 int               y=0,                      // Y coordinate 
                 string            text="Label",             // text                  
                 int               font_size = 10,
                 color             clr= clrDarkOrchid
                )
{ 
long              inchart_ID=0;               // chart's ID 
int               sub_window=0;             // subwindow index
string            font="Engravers MT";             // font 
bool              back=false;               // in the background 
bool              selection=false;          // highlight to move 
bool              hidden=true;              // hidden in the object list
long              z_order=0;                // priority for mouse click
double            angle=0.0;                // text slope 
ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER; // anchor type 

//--- create a text label 
   ObjectCreate(inchart_ID,name,OBJ_LABEL,sub_window,0,0);
//--- set label coordinates 
   ObjectSetInteger(inchart_ID,name,OBJPROP_XDISTANCE,x); 
   ObjectSetInteger(inchart_ID,name,OBJPROP_YDISTANCE,y); 
//--- set the chart's corner, relative to which point coordinates are defined 
   ObjectSetInteger(inchart_ID,name,OBJPROP_CORNER,corner); 
//--- set the text 
   ObjectSetString(inchart_ID,name,OBJPROP_TEXT,text); 
//--- set text font 
   ObjectSetString(inchart_ID,name,OBJPROP_FONT,font); 
//--- set font size 
   ObjectSetInteger(inchart_ID,name,OBJPROP_FONTSIZE,font_size); 
//--- set the slope angle of the text 
   ObjectSetDouble(inchart_ID,name,OBJPROP_ANGLE,angle); 
//--- set anchor type 
   ObjectSetInteger(inchart_ID,name,OBJPROP_ANCHOR,anchor); 
//--- set color 
   ObjectSetInteger(inchart_ID,name,OBJPROP_COLOR,clr); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(inchart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the label by mouse 
   ObjectSetInteger(inchart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(inchart_ID,name,OBJPROP_SELECTED,selection); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(inchart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(inchart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
} 


void DeleteAllObject()
{
  for(int tries = 0; tries < 10; tries++)
  {
    int obj = ObjectsTotal();
    for(int o = 0; o < obj;o++)
    {
      string name = ObjectName(o);
      int index = StringFind(name,prefix,0);
      if(index > -1)
      {
        ObjectDelete(name);
      }
    }
  }
}


void DeleteGlobalVariables()
{
   for(int tries = 0; tries < 10; tries++)
     {
      int obj = GlobalVariablesTotal();
      for(int o = 0; o < obj;o++)
        {
         string name = GlobalVariableName(o);
         int index = StringFind(name,prefix,0);
         if(index > -1)
         {
            GlobalVariableDel(name);
         }
        }
     }
}


double GVGet(string name)
{
   return(GlobalVariableGet(prefix+name));
}

datetime GVSet(string name, double value)
{
   return(GlobalVariableSet(prefix+name, value));
}