//+------------------------------------------------------------------+ //| mq4tomq5_script_sample.mq4 | //| keiji | //| http://www.dr-ea.com/meta-blog/ | //+------------------------------------------------------------------+ #property copyright "keiji" #property link "http://www.dr-ea.com/meta-blog/" #property show_inputs #include extern string MQL4FileName = "FileName"; extern int FileType = 1; extern string note = "FileType 0 :Indicator, 1 :EA, 2 :Script"; //top code string FuncAddTop() { return("\n//:::::::::::::::::::::::::::::::::::::::::::::\n"+ "#include \n"+ "#include \n"+ "#include \n"+ "#include \n"+ "#include \n"+ "//Etc.\n"+ "//:::::::::::::::::::::::::::::::::::::::::::::::\n"); } //code in OnInit() string FuncAddInInit() { return("\n //:::::::::::::::::::::::::::::::::::::::::::::\n"+ " double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);\n"+ " double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);\n"+ " int Bars=Bars(Symbol(),PERIOD_CURRENT);\n"+ " double Point=Point();\n"+ " //Etc.\n"+ " //:::::::::::::::::::::::::::::::::::::::::::::::\n"); } //code in OnCalculate(),OnTick(),OnStart() string FuncAddInStart() { return("\n //:::::::::::::::::::::::::::::::::::::::::::::\n"+ " double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);\n"+ " double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);\n"+ " int Bars=Bars(Symbol(),PERIOD_CURRENT);\n"+ " double Point=Point();\n"+ " //Etc.\n"+ " //:::::::::::::::::::::::::::::::::::::::::::::::\n"); } //code in OnDeinit() string FuncAddInDeinit() { return("\n //:::::::::::::::::::::::::::::::::::::::::::::\n"+ " double Ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);\n"+ " double Bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);\n"+ " int Bars=Bars(Symbol(),PERIOD_CURRENT);\n"+ " double Point=Point();\n"+ " //Etc.\n"+ " //:::::::::::::::::::::::::::::::::::::::::::::::\n"); } string text; //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- string filename=MQL4FileName+".mq4"; int handle; int linecnt=0,includeline=0; handle=FileOpen(filename,FILE_CSV|FILE_READ,"\t"); if(handle<0) { Alert("File " + filename + " not found, the last error is ", ErrorDescription(GetLastError())); return(false); } else { while(!FileIsEnding(handle)) { text=FileReadString(handle); linecnt++; if(StringSubstr(text,0,2)!="//" && StringSubstr(text,0,2)!="#p") { if(FuncFind(text, "int ") || FuncFind(text, "double ") || FuncFind(text, "string ") || FuncFind(text, "bool ") || FuncFind(text, "color ") || FuncFind(text, "datetime ")) { includeline=linecnt; break; } } } FileSeek(handle,0,SEEK_SET); } string filename1="mq4_"+MQL4FileName+".mq5"; int handle1; handle1=FileOpen(filename1,FILE_CSV | FILE_WRITE,"\t"); if(handle1<0) { Alert("File " + filename1+" not Open, the last error is ", ErrorDescription(GetLastError())); return(false); } string filename2="mq4_"+MQL4FileName+".txt"; int handle2; handle2=FileOpen(filename2,FILE_CSV | FILE_READ | FILE_WRITE,"\t"); if(handle2<0) { Alert("File " + filename2+" not Open, the last error is ", ErrorDescription(GetLastError())); return(false); } if(handle>0 && handle1>0 && handle2>0) { bool init=false,start=false,deinit=false; bool changeinit=false,changestart=false,changedeinit=false; linecnt=0; while(!FileIsEnding(handle)) { text=FileReadString(handle); linecnt++; string mq4word,mq5word; //-------------------------------FuncRewrite(string mql4 word, stirng mql5 word); //REWRITE************************************************************************ //extern to input mq4word= "extern"; mq5word= "input"; FuncRewrite(mq4word, mq5word); //Account Info mq4word= "AccountBalance("; mq5word= "AccountInfoDouble(ACCOUNT_BALANCE"; FuncRewrite(mq4word, mq5word); mq4word= "AccountCredit("; mq5word= "AccountInfoDouble(ACCOUNT_CREDIT"; FuncRewrite(mq4word, mq5word); mq4word= "AccountCompany("; mq5word= "AccountInfoString(ACCOUNT_COMPANY"; FuncRewrite(mq4word, mq5word); mq4word= "AccountCurrency("; mq5word= "AccountInfoString(ACCOUNT_CURRENCY"; FuncRewrite(mq4word, mq5word); mq4word= "AccountEquity("; mq5word= "AccountInfoDouble(ACCOUNT_EQUITY"; FuncRewrite(mq4word, mq5word); mq4word= "AccountFreeMargin("; mq5word= "AccountInfoDouble(ACCOUNT_FREEMARGIN"; FuncRewrite(mq4word, mq5word); //AccountFreeMarginCheck(string symbol, int cmd, double volume) //AccountFreeMarginMode() mq4word= "AccountLeverage("; mq5word= "AccountInfoInteger(ACCOUNT_LEVERAGE"; FuncRewrite(mq4word, mq5word); mq4word= "AccountMargin("; mq5word= "AccountInfoDouble(ACCOUNT_MARGIN"; FuncRewrite(mq4word, mq5word); mq4word= "AccountName("; mq5word= "AccountInfoString(ACCOUNT_NAME"; FuncRewrite(mq4word, mq5word); mq4word= "AccountNumber("; mq5word= "AccountInfoInteger(ACCOUNT_LOGIN"; FuncRewrite(mq4word, mq5word); mq4word= "AccountProfit("; mq5word= "AccountInfoDouble(ACCOUNT_PROFIT"; FuncRewrite(mq4word, mq5word); mq4word= "AccountServer("; mq5word= "AccountInfoString(ACCOUNT_SERVER"; FuncRewrite(mq4word, mq5word); mq4word= "AccountStopoutLevel("; mq5word= "AccountInfoDouble(ACCOUNT_MARGIN_SO_SO"; FuncRewrite(mq4word, mq5word); mq4word= "AccountStopoutMode("; mq5word= "AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE"; FuncRewrite(mq4word, mq5word); //String Function mq4word= "CharToStr("; mq5word= "CharToString("; FuncRewrite(mq4word, mq5word); mq4word= "DoubleToStr("; mq5word= "DoubleToString("; FuncRewrite(mq4word, mq5word); mq4word= "StrToDouble("; mq5word= "StringToDouble("; FuncRewrite(mq4word, mq5word); mq4word= "StrToInteger("; mq5word= "StringToInteger("; FuncRewrite(mq4word, mq5word); mq4word= "StrToTime("; mq5word= "StringToTime("; FuncRewrite(mq4word, mq5word); mq4word= "TimeToStr("; mq5word= "TimeToString("; FuncRewrite(mq4word, mq5word); int i=0; //Change & ADD**************************************************** //top part if(linecnt==includeline) text=FuncAddTop()+"\n"+text; //init if(!init && !changeinit) { for(i=0;i