Watch
1
0
Fork
You've already forked NeuroBook
0
forked from rosh/NeuroBook
NeuroBook/Scripts/initial_data/initial_data.mq5

177 lines
17 KiB
MQL5

2025-05-30 16:12:30 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Initial_Data.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com/en/users/dng |
//+------------------------------------------------------------------+
//| Script for calculating Pearson correlation coefficient between |
//| historical price fluctuations, indicator data and extremes |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link "https://www.mql5.com/en/users/dng"
#property version "1.00"
//+------------------------------------------------------------------+
//| Connect libraries |
//+------------------------------------------------------------------+
#include <Math\Stat\Math.mqh>
//---
#define FileName "correlation.csv"
//+------------------------------------------------------------------+
//| External parameters |
//+------------------------------------------------------------------+
input datetime Start = D'2015.01.01 00:00:00'; // Period beginning
input datetime End = D'2020.12.31 23:59:00'; // Period end
//+------------------------------------------------------------------+
//| Script program |
//+------------------------------------------------------------------+
void OnStart(void)
{
//--- Connect indicators
int h_ZZ = iCustom(_Symbol, PERIOD_M5, "Examples\\ZigZag.ex5", 48, 1, 47);
int h_CCI = iCCI(_Symbol, PERIOD_M5, 12, PRICE_TYPICAL);
int h_RSI = iRSI(_Symbol, PERIOD_M5, 12, PRICE_TYPICAL);
int h_Stoh = iStochastic(_Symbol, PERIOD_M5, 12, 8, 3, MODE_LWMA, STO_LOWHIGH);
int h_MACD = iMACD(_Symbol, PERIOD_M5, 12, 48, 12, PRICE_TYPICAL);
int h_ATR = iATR(_Symbol, PERIOD_M5, 12);
int h_BB = iBands(_Symbol, PERIOD_M5, 48, 0, 3, PRICE_TYPICAL);
int h_SAR = iSAR(_Symbol, PERIOD_M5, 0.02, 0.2);
int h_MFI = iMFI(_Symbol, PERIOD_M5, 12, VOLUME_TICK);
double close[], open[], high[], low[];
if(CopyClose(_Symbol, PERIOD_M5, Start, End, close) <= 0 ||
CopyOpen(_Symbol, PERIOD_M5, Start, End, open) <= 0 ||
CopyHigh(_Symbol, PERIOD_M5, Start, End, high) <= 0 ||
CopyLow(_Symbol, PERIOD_M5, Start, End, low) <= 0)
return;
//--- Load indicator data
double zz[], cci[], macd_main[], macd_signal[], rsi[], atr[], bands_medium[],
bands_up[], bands_low[], sar[], stoch[], ssig[], mfi[];
datetime end_zz = End + PeriodSeconds(PERIOD_M5) * (12 * 24 * 5);
if(h_ZZ == INVALID_HANDLE || CopyBuffer(h_ZZ, 0, Start, end_zz, zz) <= 0)
{
PrintFormat("Error loading indicator %s data", "ZigZag");
return;
}
if(h_CCI == INVALID_HANDLE || CopyBuffer(h_CCI, 0, Start, End, cci) <= 0)
{
PrintFormat("Error of load indicator %s data", "CCI");
return;
}
if(h_RSI == INVALID_HANDLE || CopyBuffer(h_RSI, 0, Start, End, rsi) <= 0)
{
PrintFormat("Error loading indicator %s data", "RSI");
return;
}
if(h_MACD == INVALID_HANDLE || CopyBuffer(h_MACD, MAIN_LINE, Start, End, macd_main) <= 0 ||
CopyBuffer(h_MACD, SIGNAL_LINE, Start, End, macd_signal) <= 0)
{
PrintFormat("Error loading indicator %s data", "MACD");
return;
}
if(h_ATR == INVALID_HANDLE || CopyBuffer(h_ATR, 0, Start, End, atr) <= 0)
{
PrintFormat("Error loading indicator %s data", "ATR");
return;
}
if(h_BB == INVALID_HANDLE || CopyBuffer(h_BB, BASE_LINE, Start, End, bands_medium) <= 0 ||
CopyBuffer(h_BB, UPPER_BAND, Start, End, bands_up) <= 0 ||
CopyBuffer(h_BB, LOWER_BAND, Start, End, bands_low) <= 0)
{
PrintFormat("Error loading indicator %s data", "Bollinger Bands<00>");
return;
}
if(h_SAR == INVALID_HANDLE || CopyBuffer(h_SAR, 0, Start, End, sar) <= 0)
{
PrintFormat("Error loading indicator %s data", "SAR");
return;
}
if(h_Stoh == INVALID_HANDLE || CopyBuffer(h_Stoh, MAIN_LINE, Start, End, stoch) <= 0 ||
CopyBuffer(h_Stoh, SIGNAL_LINE, Start, End, ssig) <= 0)
{
PrintFormat("Error loading indicator %s data", "Stochastic");