Scripts: MT5 to MT4 Set File Converter

To add comments, please log in or register
Automated-Trading
147036
Automated-Trading  

MT5 to MT4 Set File Converter:

This script converts multiple .set files from MT5 format to MT4 format. This is a necessary step for optimizing and running cross-compatible EAs.

MetaTrader 5 is able to load .set files created in MT4, however, the format it saves set files in is not compatible with MetaTrader 4. This script acts as a useful tool to make .set files backwards compatible, so you can take advantage of MT5's better strategy tester then run a cross-compatible EA on MT4 and MT5 with the same parameters.

Two .set files have been attached as an example of the converter.

The "exampleMT5.set" file is produced by the MetaTreader 5 terminal. This is then converted to "exampleMT5-MT4.set" file by the converter.

Author: Richard Gunning

Goldland360
36
Goldland360  

Please can someone help in making  the zigzag color indicator which was made with MT5 language work in MT4 platform. I've tried using the above script but without success

the file is attached below.

Here is my email mgbe_nsor@yahoo.com.

Thanks in anticipation of your kind response

Files:
Mahdi Keramatfar
459
Mahdi Keramatfar  

good.

thanks

binary72
6
binary72  

I liked a MT5 indicator and converted it into MT4 set file using your script. But not sure how to use the MT4 set file without the MQL4/ex4 file.

How I can load the converted MT4 set file on MT4 chart without the MT4/ex4 files?

Is it possible to convert MQL5 file into MQL4 file?.

ThaironBathory
4
ThaironBathory  


I thought it was daora, but I tried and could not do a conversion. Could anyone convert the tabajara?

Keith Watford
Moderator
16236
Keith Watford  
ThaironBathory:


I thought it was daora, but I tried and could not do a conversion. Could anyone convert the tabajara?

This is an English language forum.

Please only post in English.

Use the translation tool if necessary.

Arturo Lopez Perez
180062
Arturo Lopez Perez  

Thanks for the script. There is an error that causes an Array Out of Range Error at line 94. Fixed code is:

//+------------------------------------------------------------------+
//|                                             SetFileConverter.mq5 |
//|                                                  Richard Gunning |
//|                                            https://rjgunning.com |
//+------------------------------------------------------------------+
#property copyright "Richard Gunning"
#property link      "https://rjgunning.com"
#property version   "1.00"
#property description "Script for converting set files from MT5 format to MT4 format."
#property description "Set files must be in Files Folder or a SubDirectory."
#property script_show_inputs
#property strict

#include <Files/FileTxt.mqh>

//--- input parameters
input string   File=""; // SetFile Name to Convert (Leave blank to convert all)
input string   SubDirectory=""; // SubDirectory of Files Folder in which to search
input string   Directory="MT4-Output-Setfiles"; //Output Directory Name (Not Blank)

//--- Create Global Variables
CFileTxt *output=new CFileTxt;
CFileTxt *file=new CFileTxt;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   long m_handle;
   bool m_file_found=true;
   string searchString="*.set";
   string thisDirectory=Directory;
   string src_path;
   string dst_path;

//--- Create Output Directory
   if(thisDirectory==""){thisDirectory="MT4-Output-Setfiles";}
   if(!output.FolderCreate(thisDirectory))
     {
      Print("Error Creating Destination Folder");
      delete output;
      delete file;
      return;
     }

//--- Set Search String and Find First Matching file in Directory
   if(File!=""){searchString=File;}
   if(SubDirectory=="")
     {
      m_handle=file.FileFindFirst(searchString,src_path);
     }
   else
     {
      m_handle=file.FileFindFirst(SubDirectory+"//"+searchString,src_path);
     }

//--- Loop through matching files and run conversion
   while(m_handle!=INVALID_HANDLE && m_file_found)
     {
      StringConcatenate(dst_path,thisDirectory,"//",src_path);
      StringReplace(dst_path,".set","-MT4.set");
      if(output.Open(dst_path,FILE_WRITE|FILE_REWRITE)!=INVALID_HANDLE &&
         file.Open(src_path,FILE_READ)!=INVALID_HANDLE)
        {
         Convert();
        }
      //--- Close SetFiles
      output.Close();
      file.Close();

      //--- Get Next SetFile
      m_file_found=file.FileFindNext(m_handle,src_path);

     }
//--- Delete Global objects
   delete output;
   delete file;
  }
//+------------------------------------------------------------------+
//|  Parse MT5 Set File Line By Line and Write Output Set File       |
//+------------------------------------------------------------------+
void Convert()
  {
   string line,str;
   string values[2];
   string split[];
   int opt;

   while(!file.IsEnding())
     {
      line=file.ReadString();
      StringSplit(line,'=',values);
      StringSplit(values[1],'|',split);
      if(ArraySize(split)==0){ArrayResize(split,1);}
      for(int i=0,count=0;i<ArraySize(split);i++)
        {
         if(split[i]==""){continue;}

         if(count==0)
           {
            str=StringFormat("%s=%s",values[0],split[i]);
           }
         else if(count<4)
           {
            str=StringFormat("%s,%d=%s",values[0],count,split[i]);
           }
         else
           {
            opt=(split[i]=="Y")?1:0;
            str=StringFormat("%s,F=%d",values[0],opt);
           }
         output.WriteString(str+"\r\n");

         count++;
        }
     }

  }
//+------------------------------------------------------------------+

guner
431
guner  
why it does not work on me.?
6465804 Thidarat
7
6465804 Thidarat  
Arturo Lopez Perez:

Thanks for the script. There is an error that causes an Array Out of Range Error at line 94. Fixed code is:

//+------------------------------------------------------------------+
//|                                             SetFileConverter.mq5 |
//|                                                  Richard Gunning |
//|                                            https://rjgunning.com |
//+------------------------------------------------------------------+
#property copyright "Richard Gunning"
#property link      "https://rjgunning.com"
#property version   "1.00"
#property description "Script for converting set files from MT5 format to MT4 format."
#property description "Set files must be in Files Folder or a SubDirectory."
#property script_show_inputs
#property strict

#include <Files/FileTxt.mqh>

//--- input parameters
input string   File=""; // SetFile Name to Convert (Leave blank to convert all)
input string   SubDirectory=""; // SubDirectory of Files Folder in which to search
input string   Directory="MT4-Output-Setfiles"; //Output Directory Name (Not Blank)

//--- Create Global Variables
CFileTxt *output=new CFileTxt;
CFileTxt *file=new CFileTxt;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   long m_handle;
   bool m_file_found=true;
   string searchString="*.set";
   string thisDirectory=Directory;
   string src_path;
   string dst_path;

//--- Create Output Directory
   if(thisDirectory==""){thisDirectory="MT4-Output-Setfiles";}
   if(!output.FolderCreate(thisDirectory))
     {
      Print("Error Creating Destination Folder");
      delete output;
      delete file;
      return;
     }

//--- Set Search String and Find First Matching file in Directory
   if(File!=""){searchString=File;}
   if(SubDirectory=="")
     {
      m_handle=file.FileFindFirst(searchString,src_path);
     }
   else
     {
      m_handle=file.FileFindFirst(SubDirectory+"//"+searchString,src_path);
     }

//--- Loop through matching files and run conversion
   while(m_handle!=INVALID_HANDLE && m_file_found)
     {
      StringConcatenate(dst_path,thisDirectory,"//",src_path);
      StringReplace(dst_path,".set","-MT4.set");
      if(output.Open(dst_path,FILE_WRITE|FILE_REWRITE)!=INVALID_HANDLE &&
         file.Open(src_path,FILE_READ)!=INVALID_HANDLE)
        {
         Convert();
        }
      //--- Close SetFiles
      output.Close();
      file.Close();

      //--- Get Next SetFile
      m_file_found=file.FileFindNext(m_handle,src_path);

     }
//--- Delete Global objects
   delete output;
   delete file;
  }
//+------------------------------------------------------------------+
//|  Parse MT5 Set File Line By Line and Write Output Set File       |
//+------------------------------------------------------------------+
void Convert()
  {
   string line,str;
   string values[2];
   string split[];
   int opt;

   while(!file.IsEnding())
     {
      line=file.ReadString();
      StringSplit(line,'=',values);
      StringSplit(values[1],'|',split);
      if(ArraySize(split)==0){ArrayResize(split,1);}
      for(int i=0,count=0;i<ArraySize(split);i++)
        {
         if(split[i]==""){continue;}

         if(count==0)
           {
            str=StringFormat("%s=%s",values[0],split[i]);
           }
         else if(count<4)
           {
            str=StringFormat("%s,%d=%s",values[0],count,split[i]);
           }
         else
           {
            opt=(split[i]=="Y")?1:0;
            str=StringFormat("%s,F=%d",values[0],opt);
           }
         output.WriteString(str+"\r\n");

         count++;
        }
     }

  }
//+------------------------------------------------------------------+

To add comments, please log in or register