I've written this script this summer. Try to use it. Place your collected fxt-file in the expert\files directory and point its name as input parameter. Attach this script to the H4 chart
//+------------------------------------------------------------------+ //| fxt2fxt.mq4 | //| Copyright © 2006, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property show_inputs #include <FXTHeader.mqh> extern string ExtFxtFile="EURUSD15_0.fxt"; int ExtTicks; int ExtBars; int ExtFxtHandle=-1; int ExtHandle=-1; int ExtTmpHandle=-1; string ExtFileName; string ExtTmpFileName; int ExtPeriodSeconds; datetime ExtLastTime; datetime ExtLastBarTime; double ExtLastOpen; double ExtLastLow; double ExtLastHigh; double ExtLastClose; double ExtLastVolume; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void deinit() { //---- close all files if they are not closed yet if(ExtHandle>0) { FileClose(ExtHandle); ExtHandle=-1; } if(ExtFxtHandle>0) { FileClose(ExtFxtHandle); ExtFxtHandle=-1; } if(ExtTmpHandle>0) { FileClose(ExtTmpHandle); ExtTmpHandle=-1; } //---- } //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { datetime cur_time,cur_open; double tick_price; bool new_bar; string symbol=Symbol(); //---- check input fxt file if(ExtFxtFile=="") { Print("Input fxt file is not specified"); return(-1); } int offset=StringFind(ExtFxtFile,"_0.fxt"); if(offset<0) { offset=StringFind(ExtFxtFile,"_0.FXT"); if(offset<0) { Print("Input fxt file name is incorrect"); return(-1); } } //---- get period value from filename and check file int len=StringLen(symbol); int period=StrToInteger(StringSubstr(ExtFxtFile,len,offset-len)); if(period<=0 || period>=PERIOD_W1 || period==Period()) { Print("Input fxt period is incorrect"); return(-1); } ExtFxtHandle=FileOpen(ExtFxtFile,FILE_BIN|FILE_READ); if(ExtFxtHandle<0) return(-1); if(!ReadAndCheckHeader(ExtFxtHandle,period,len)) { Print("Input fxt file is wrong"); return(-1); } //---- check output temp file period=Period(); ExtTmpFileName=symbol+period+"_ticks.tmp"; ExtTmpHandle=FileOpen(ExtTmpFileName,FILE_BIN|FILE_WRITE); if(ExtTmpHandle<0) return(-1); //---- check existing fxt file ExtPeriodSeconds=period*60; ExtFileName=symbol+period+"_0.fxt"; ExtHandle=FileOpen(ExtFileName,FILE_BIN|FILE_READ); if(ExtHandle>0) { if(!ReadAndCheckHeader(ExtHandle,period,ExtBars)) { //---- file is wrong FileClose(ExtHandle); ExtHandle=-1; } } //---- ExtBars=0; ExtTicks=0; ExtLastTime=0; ExtLastBarTime=0; WriteHeaderAndFirstBars(); //---- double volume_diff=1; double last_open=0; double last_low=0; double last_high=0; double last_close=0; double last_volume=0; int last_shift=iBarShift(NULL,0,ExtLastBarTime,true); if(last_shift>0) { last_open=Open[last_shift]; last_low=Low[last_shift]; last_high=High[last_shift]; last_close=Close[last_shift]; last_volume=Volume[last_shift]; } //---- while(!IsStopped()) { new_bar=false; if(!ReadNextTick(cur_time,tick_price,volume_diff)) break; cur_open=cur_time/ExtPeriodSeconds; cur_open*=ExtPeriodSeconds; //---- new bar? if(ExtLastBarTime!=cur_open) { new_bar=true; //---- finalize bar if(last_shift>0) { if(ExtLastHigh!=last_high || ExtLastLow!=last_low || ExtLastClose!=last_close || ExtLastVolume!=last_volume) { FileWriteInteger(ExtHandle, ExtLastBarTime, LONG_VALUE); FileWriteDouble(ExtHandle, last_open, DOUBLE_VALUE); FileWriteDouble(ExtHandle, last_low, DOUBLE_VALUE); FileWriteDouble(ExtHandle, last_high, DOUBLE_VALUE); FileWriteDouble(ExtHandle, last_close, DOUBLE_VALUE); FileWriteDouble(ExtHandle, last_volume, DOUBLE_VALUE); FileWriteInteger(ExtHandle, ExtLastBarTime+ExtPeriodSeconds-1, LONG_VALUE); FileWriteInteger(ExtHandle, 1, LONG_VALUE); } } //---- new bar time ExtLastBarTime=cur_open; //---- take next bar last_shift=iBarShift(NULL,0,ExtLastBarTime,true); if(last_shift>=0) { last_open=Open[last_shift]; last_low=Low[last_shift]; last_high=High[last_shift]; last_close=Close[last_shift]; last_volume=Volume[last_shift]; } //---- check open price if(last_open!=tick_price) { ExtLastOpen=last_open; ExtLastLow=last_open; ExtLastHigh=last_open; ExtLastClose=last_open; ExtLastVolume=1; WriteTick(); ExtBars++; new_bar=false; } } //---- check for maximum and minimum of the existing bar if(last_shift>=0) { if(tick_price>last_high) tick_price=last_high; else if(tick_price<last_low) tick_price=last_low; } if(new_bar) { ExtLastOpen=tick_price; ExtLastLow=tick_price; ExtLastHigh=tick_price; ExtLastClose=tick_price; ExtLastVolume=volume_diff; WriteTick(); ExtBars++; } else { //---- check for current minimum and maximum if(ExtLastLow>tick_price) ExtLastLow=tick_price; if(ExtLastHigh<tick_price) ExtLastHigh=tick_price; ExtLastClose=tick_price; ExtLastVolume+=volume_diff; if(last_shift>=0 && ExtLastVolume>last_volume) ExtLastVolume=last_volume; WriteTick(); } } //---- if(!IsStopped()) { //---- store processed bars amount FileFlush(ExtTmpHandle); FileSeek(ExtTmpHandle,88,SEEK_SET); FileWriteInteger(ExtTmpHandle,ExtBars,LONG_VALUE); //---- Print(ExtTicks," ticks added. ",ExtBars," bars finalized in the header"); FileClose(ExtTmpHandle); ExtTmpHandle=-1; } //---- return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void WriteHeaderAndFirstBars() { datetime cur_time,cur_open; double tick_price,volume_diff; int start_bar=0; //---- ExtHandle=FileOpen(ExtFileName,FILE_BIN|FILE_WRITE); if(ExtHandle<0) return; //---- if(!ReadNextTick(cur_time,tick_price,volume_diff)) return; int shift=iBarShift(NULL,0,cur_time); if(shift<Bars) { start_bar=shift+100; if(start_bar>=Bars) start_bar=Bars-1; } else shift=0; WriteHeader(ExtHandle,Symbol(),Period(),start_bar-shift); //---- 100 bars before first tick for(int i=start_bar; i>shift; i--,ExtBars++) { cur_open=Time[i]; FileWriteInteger(ExtHandle, cur_open, LONG_VALUE); FileWriteDouble(ExtHandle, Open[i], DOUBLE_VALUE); FileWriteDouble(ExtHandle, Low[i], DOUBLE_VALUE); FileWriteDouble(ExtHandle, High[i], DOUBLE_VALUE); FileWriteDouble(ExtHandle, Close[i], DOUBLE_VALUE); FileWriteDouble(ExtHandle, Volume[i], DOUBLE_VALUE); //---- generated current time for bar state FileWriteInteger(ExtHandle, cur_open+ExtPeriodSeconds-1, LONG_VALUE); //---- flag 0 - testing is not evaluated FileWriteInteger(ExtHandle, 0, LONG_VALUE); } //---- cur_open=cur_time/ExtPeriodSeconds; ExtLastBarTime=cur_open*ExtPeriodSeconds; ExtLastOpen=tick_price; ExtLastLow=tick_price; ExtLastHigh=tick_price; ExtLastClose=tick_price; ExtLastVolume=volume_diff; WriteTick(); ExtBars++; } //+------------------------------------------------------------------+ //| YYYY.MM.DD HH:MI:SS;1.2345 | //+------------------------------------------------------------------+ bool ReadNextTick(datetime& cur_time, double& tick_price, double& volume_diff) { //---- while(!IsStopped()) { //---- first read date and time string date_time=FileReadString(ExtFxtHandle); if(FileIsEnding(ExtFxtHandle)) return(false); cur_time=StrToTime(date_time); //---- read tick price tick_price=FileReadNumber(ExtFxtHandle); if(FileIsEnding(ExtFxtHandle)) return(false); //---- time must go forward. if no then read further if(cur_time>ExtLastTime) break; } //---- price must be normalized tick_price=NormalizeDouble(tick_price,Digits); ExtLastTime=cur_time; return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void WriteTick() { FileWriteInteger(ExtHandle, ExtLastBarTime, LONG_VALUE); FileWriteDouble(ExtHandle, ExtLastOpen, DOUBLE_VALUE); FileWriteDouble(ExtHandle, ExtLastLow, DOUBLE_VALUE); FileWriteDouble(ExtHandle, ExtLastHigh, DOUBLE_VALUE); FileWriteDouble(ExtHandle, ExtLastClose, DOUBLE_VALUE); FileWriteDouble(ExtHandle, ExtLastVolume, DOUBLE_VALUE); FileWriteInteger(ExtHandle, ExtLastTime, LONG_VALUE); FileWriteInteger(ExtHandle, 4, LONG_VALUE); ExtTicks++; } //+------------------------------------------------------------------+
The script you sent me generates two files, FXT file, and TMP file. The FXT filesize is 4KB, which definitely means that they don't contain all the ticks recorded by the original fxt.
It seems to me like the script waits for incoming ticks and convert them to H4 format. I mean, is it exactly like attaching FXT_Collector to two different charts in two different MetaTraders, one in the H1 and another in the H4?
I don't know if this is right. But what I need is converting the recorded data that I obtained from the market into another format, not to collect new data from the market if you understand what I mean.
Please make this clear,
Thank you.
It seems to me like the script waits for incoming ticks and convert them to H4 format. I mean, is it exactly like attaching FXT_Collector to two different charts in two different MetaTraders, one in the H1 and another in the H4?
I don't know if this is right. But what I need is converting the recorded data that I obtained from the market into another format, not to collect new data from the market if you understand what I mean.
Please make this clear,
Thank you.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
The output file is .fxt extension, I can't use the PeriodConverter_Optimized to do it.
Please Help,