MQL 4 of Quantitative Trading-Automatically save the last modified EA external parameters (file realization)


extern double order volume = 0.1;
extern int stop profit points = 200;
extern int stop loss points = 200;

int OnInit() {
    
    // get the csv file name with the name of the current EA
    string fileName = WindowExpertName() + ". csv";
    
    
    // The corresponding file was not found
    if(FileIsExist(fileName) == false) {
    
      int h = FileOpen(fileName, FILE_WRITE|FILE_READ|FILE_SHARE_READ|FILE_CSV,',', CP_ACP);
      if(h != INVALID_HANDLE) {
         FileWrite(h, order volume, take profit points, stop loss points);
         FileClose(h);
         Alert("koko");
      }
      
    } else {// find the corresponding file
      
      if (order volume == 0.1 && stop profit points == 200 && Stop loss points == 200) {// When the parameters are not modified outside the program
         
         int h = FileOpen(fileName, FILE_WRITE|FILE_READ|FILE_SHARE_READ|FILE_CSV, ',', CP_ACP);
         if(h != INVALID_HANDLE) {
            int i = 0;
            while(FileIsEnding(h) == false) {
               string readValue = FileReadString(h);
               if(i == 0) 下单量 = StringToDouble(readValue);
               if(i == 1) 止盈点数 = StringToInteger(readValue);
               if(i == 2) 止损点数 = StringToInteger(readValue);
               i++;
            }
         }
         
      } else { // 程序外部修改了参数情况
         
         int h = FileOpen(fileName, FILE_WRITE|FILE_READ|FILE_SHARE_READ|FILE_CSV, ',', CP_ACP);
         if(h != INVALID_HANDLE) {
            FileWrite(h, order volume, take profit points, stop loss points);
            FileClose(h);
         }
         
      }
      
    }
    
    return(INIT_SUCCEEDED);
}


void OnTick() {
    
    if(OrdersTotal() != 0) return;
    
    int orderTicket = OrderSend(Symbol(), OP_SELL, order volume, Bid, 0, Bid+stop loss points*Point, Bid-stop profit points*Point, "", 0, 0, clrNONE);
    
}

Guess you like

Origin blog.csdn.net/Michael_234198652/article/details/80395820