73 lines
5.8 KiB
MQL5
73 lines
5.8 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Create_Initial_Data.mq5 |
|
|
//| Copyright 2021, MetaQuotes Ltd. |
|
|
//| https://www.mql5.com/en/users/dng |
|
|
//+------------------------------------------------------------------+
|
|
//| Script creates training and testing datasets |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "Copyright 2021, MetaQuotes Ltd."
|
|
#property link "https://www.mql5.com/en/users/dng"
|
|
#property version "1.00"
|
|
#property script_show_inputs
|
|
//+------------------------------------------------------------------+
|
|
//| External parameters for script operation |
|
|
//+------------------------------------------------------------------+
|
|
input datetime Start = D'2024.01.01 00:00:00'; // Start of the population period
|
|
input datetime End = D'2024.010.01 23:59:00'; // End of the population period
|
|
input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1; // Timeframe for loading data
|
|
input string StudyFileName = "pricecorr.csv";// File name to write the training dataset
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Script program start |
|
|
//+------------------------------------------------------------------+
|
|
void OnStart(void)
|
|
{
|
|
|
|
double close[];
|
|
if(CopyClose(_Symbol, TimeFrame, Start, End,close) <= 0)
|
|
return;
|
|
double open[];
|
|
if(CopyOpen(_Symbol, TimeFrame, Start, End, open) <= 0)
|
|
return;
|
|
double high[];
|
|
if(CopyHigh(_Symbol, TimeFrame, Start, End, high) <= 0)
|
|
return;
|
|
double low[];
|
|
if(CopyLow(_Symbol, TimeFrame, Start, End, low) <= 0)
|
|
return;
|
|
|
|
|
|
//--- Open the training dataset file for writing
|
|
int Study = FileOpen(StudyFileName, FILE_WRITE | FILE_CSV | FILE_ANSI, ",", CP_UTF8);
|
|
if(Study == INVALID_HANDLE)
|
|
{
|
|
PrintFormat("Error opening file %s: %d", StudyFileName, GetLastError());
|
|
return;
|
|
}
|
|
|
|
int total = ArraySize(close);
|
|
FileWrite(Study, "Close, Open, Close1, Open1, Close2, Open2, Close3, Open3, Close4, Open4");
|
|
//--- Write datasets to files
|
|
for(int i = 0; i < total-4; i++)
|
|
{
|
|
FileWrite(Study, close[i],
|
|
open[i],
|
|
close[i+1],
|
|
open[i+1],
|
|
close[i+2],
|
|
open[i+2],
|
|
close[i+3],
|
|
open[i+3],
|
|
close[i+4],
|
|
open[i+4]);
|
|
}
|
|
|
|
//--- Close files
|
|
Comment("");
|
|
FileFlush(Study);
|
|
FileClose(Study);
|
|
|
|
PrintFormat("Study data saved to file %s\\MQL5\\Files\\%s",
|
|
TerminalInfoString(TERMINAL_DATA_PATH), StudyFileName);
|
|
|
|
}
|