不要 每5秒 太麻煩了
給你 tick by tick 的
然後 輸出檔案,不能隨意,只能放在 MT4 安裝目錄的
C:\MT4 主目錄\experts\files 底下
//=============================================================================
// tcINTickDataA.mq4 modified by Trading144.net
// modified from TickSave.mq4
// written by komposter at komposterius@mail.ru
// 04/09/08 modified for format
// logs date time and bid to \experts\files\TickData\<symbol>.csv
// (Example output: 2008.05.07 22:25:21;1.5316)
// runs as an indicator on 1 minute (or any) chart
// places the record count in a separate window
//=============================================================================
#property copyright "Copyright" //komposter
#property link "" //many thanks to the original author(s)
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
extern int i_1Override_2Append = 2;
int iRcdCnt = 0;
string sFileName = "";
string sComment = "";
bool bRtn = false;
int iRtn = 0;
int err = 0;
double ExtMapBuffer[];
bool bFirst=True;
bool bKilled = false;
int prevPeriod=0;
int initBars=0;
int prevBars=0;
bool bOneTime = false;
//=============================================================================
// indicator initialization function
//=============================================================================
int init() {
string short_name;
short_name = "TickDataA(" + i_1Override_2Append + ")";
IndicatorShortName(short_name);
SetIndexStyle(0,DRAW_LINE,0,1);
SetIndexBuffer(0,ExtMapBuffer);
SetIndexLabel(0,short_name);
IndicatorDigits(0);
return(0);
}
//=============================================================================
// deinitialization function
//=============================================================================
int deinit() {
Comment("");
return(0);
}
//=============================================================================
// start function
//=============================================================================
int start() {
if ( bKilled == true ) return;
if ((i_1Override_2Append == 1) || (i_1Override_2Append == 2)) {
//valid parm entered
} else {
sComment = "Please select valid Overwrite or Append parameter.";
Print(sComment);
Comment(sComment);
bKilled = true;
return(-1);
}
sFileName = StringConcatenate( "TickData\\", Symbol() + ".csv" );
if(bOneTime == false) {
bOneTime = true;
Print("output file name is: ", sFileName);
}
if(Period() != prevPeriod) {
prevPeriod = Period();
bFirst = True;
}
if(IndicatorCounted() == 0) bFirst = True;
if(bFirst == True) {
initBars = Bars;
prevBars = Bars;
//calculate x on loaded bars - if wanted
//int kklmt = Bars-20; //allow for lookback
//for(int kk=kklmt; kk>=1; kk--) {
// iRtn = Calc_X(kk);
//}
if ( i_1Override_2Append == 1 ) {
FileDelete(sFileName);
}
bFirst = False;
}
//Initialize End
//All bars (full and tick)
if(Bars <= initBars) return; //are we past initially loaded bars
//if(Bars == prevBars) { //still filling out current bar
// //Print("continuation bar.", TimeToStr(CurTime())," bars: ",Bars,TimeToStr(Time[0]));
//} else { //first tick of new bar, process prior bar
// //Print("new bar.", TimeToStr(CurTime())," bars: ",Bars,TimeToStr(Time[0]));
// iRtn = Write_Tick();
//}
iRtn = Write_Tick();
prevBars = Bars;
return(0);
}
int Write_Tick() {
iRcdCnt++;
//Comment("writing rcd no: " , iRcdCnt);
int handle;
handle = FileOpen(sFileName, FILE_READ|FILE_WRITE|FILE_CSV, ";");
bRtn = FileSeek(handle, 0, SEEK_END);
if (bRtn == false) {
err=GetLastError();
Print("error of seek: ",err);
return(-1);
}
FileWrite(handle, TimeToStr(CurTime(), TIME_DATE|TIME_SECONDS), Bid);
FileClose(handle);
ExtMapBuffer[0] = iRcdCnt;
return(0);
}
//--- end --- |