I have faced wtih the problem in the last year.
that is my way.
In the script below, you have to adjust something in the code especially
the comment
//=====Start and Close Market depending on what market you are trainding===//
//#pragma nocache
RequestTimedRefresh( 56, False );
robotName = "tfex_features_ls";
//============================path file==============================
batchPath ="D:\\AB_DB";
log_file = batchPath+"\\log_" + robotName + ".log";
batch_file = batchPath+"\\X_Batch_XXX.abb";
//paramExport2CSV= ParamTrigger("Export data to file", "Click here to Export");
fhLogFile = fopen(log_file, "a" ); // a = append
function writeLog(message) {
if (fhLogFile) {
fputs( message + "\n" , fhLogFile );
}
}
// =================================Set Trade Time======================================================
modelTF = 15;
amiTimeFrame = IIf(modelTF == 5, in5Minute, in15Minute);
// If you want to use other timeframe, please set the following 3 lines
TimeFrameSet(amiTimeFrame);
SetOption("StaticVarAutoSave", amiTimeFrame);
localTimeZone = 0;
//barHour = IIf(localTimeZone == 0, Hour(), Hour() + 7);
barHour = Hour();
barMinute = Minute();
// =================================Start and Close Market depending on what market you are trainding======================================================
// For Thailand 09:45-16:50
// Check first bar
isFirstBar = IIf( modelTF == 60 AND ( ( barHour >= 10 AND barHour < 11 ) OR ( barHour == 14 AND barHour < 15 )) ,1,
IIf( modelTF == 15 AND ( ( barHour < 10 ) OR ( barHour == 14 AND barMinute < 30 )) , 1,
IIf( modelTF == 5 AND( ( barHour == 9 AND barMinute < 50 ) OR( barHour == 14 AND barMinute < 20 ) ), 1, 0 ) ));
// Check last bar
isLastBar = IIf( modelTF == 60 AND( ( barHour == 12 ) OR( barHour == 16 ) ), 1,
IIf( modelTF == 15 AND( ( barHour == 12 AND barMinute >= 15 ) OR( barHour == 16 AND barMinute >= 45 ) ), 1,
IIf( modelTF == 5 AND( ( barHour == 12 AND barMinute >= 25 ) OR( barHour == 16 AND barMinute >= 50 ) ), 1, 0 ) ));
//===========================================================================================================================
lastBarTimeForTrade = Status("lastbarend");
recordTimestamp = Nz(StaticVarGet(Name() + robotName + "_lastBarTimeForTrade"));
// =================================Feed feature data to csv for ml prediction======================================================
if ( lastBarTimeForTrade != recordTimestamp AND LastValue(isFirstBar) == 0) {
timestamp = DateTimeToStr( Now(5) );
logLine = StrFormat("%s Start to Explore Features",timestamp);
writeLog(logLine);
ShellExecute("runbatch", batch_file, "" );
StaticVarSet(Name() + robotName + "_lastBarTimeForTrade", lastBarTimeForTrade);
timestamp = DateTimeToStr( Now(5) );
logLine = StrFormat("%s Completed to Explore Features", timestamp);
writeLog(logLine);
}
// Close log file
if (fhLogFile) {
fclose( fhLogFile );
}
_N(Title = StrFormat("Feed Features ML V2{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );