//+------------------------------------------------------------------+ //| 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'2022.01.01 00:00:00'; // Start of the population period input datetime End = D'2024.07.01 23:59:00'; // End of the population period input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1; // Timeframe for loading data //input int BarsToLine = 5; // Number of historical bars in one pattern input string StudyFileName = "study_pricedelt_data_norm.csv";// File name to write the training dataset input string TestFileName = "test_pricedelt_data_norm.csv"; // File name to write the testing dataset input bool NormalizeData = true; // Data normalization flag //+------------------------------------------------------------------+ //| 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; int target1 = 0, target2 = 0; double target3 = 0; int total = ArraySize(close); int test[]; double A[], B[], C[], D[]; if(ArrayResize(test, total) <= 0 || ArrayResize(A, total) <= 0|| ArrayResize(B, total) <= 0 || ArrayResize(C, total) <= 0 || ArrayResize(D, total) <= 0) return; for(int i = 0; i (total-4)) { A[i] = A[i-1]; B[i] = B[i-1]; C[i] = C[i-1]; D[i] = D[i-1]; } else { A[i] = open[i]-high[i+1]; B[i] = high[i+1]-close[i+1]; C[i] = open[i+1]-low[i+1]; D[i] = low[i+1]-open[i+3]; } } if(NormalizeData) { double Asr, Bsr, Csr, Dsr; for(int i = 0; i 0) { target1 = 1; target2 = 0; } if(target3 < 0) { target1 = 0; target2 = 1; } if(!WriteData(A[i], B[i], C[i], D[i], target1, target2, target3,(test[i] == 1 ? Test : Study))) { PrintFormat("Error to write data: %d", GetLastError()); break; } } //--- Close files Comment(""); FileFlush(Study); FileClose(Study); FileFlush(Test); FileClose(Test); PrintFormat("Study data saved to file %s\\MQL5\\Files\\%s", TerminalInfoString(TERMINAL_DATA_PATH), StudyFileName); PrintFormat("Test data saved to file %s\\MQL5\\Files\\%s", TerminalInfoString(TERMINAL_DATA_PATH), TestFileName); } //+------------------------------------------------------------------+ //| Function for writing pattern to file | //+------------------------------------------------------------------+ bool WriteData(double &data0, // Buffer 1 of target values double &data1, // Buffer 1 of historical data double &data2, // Buffer 2 of historical data double &data3, // Buffer 3 of historical data int &dates0, int &dates1, double &dates2, int handle) // File handle for writing { //--- Validate file handle if(handle == INVALID_HANDLE) { Print("Invalid Handle"); return false; } string pattern = (string)data0 + ", "+ (string)data1 + ", "+ (string)data2 + ", "+ (string)data3 + ", "+ (string)dates0 + ", "+ (string)dates1 + ", "+ (string)dates2; return (FileWrite(handle, pattern) > 0); } //+------------------------------------------------------------------+