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

109 lines
9.9 KiB
MQL5

2025-05-30 16:12:30 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Initial_Data_MACD_Shift.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com/en/users/dng |
//+------------------------------------------------------------------+
//| Script for finding correlation between MACD values and target |
//| values when the indicator is shifted in time |
//+------------------------------------------------------------------+
#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>
//+------------------------------------------------------------------+
//| 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_MACD = iMACD(_Symbol, PERIOD_M5, 12, 48, 12, PRICE_TYPICAL);
double close[];
if(CopyClose(_Symbol, PERIOD_M5, Start, End, close) <= 0)
return;
//--- Load indicator data
double zz[], macd_main[], macd_signal[];
datetime end_zz = End + PeriodSeconds(PERIOD_M5) * (12 * 24 * 5);
if(CopyBuffer(h_ZZ, 0, Start, end_zz, zz) <= 0 ||
CopyBuffer(h_MACD, MAIN_LINE, Start, End, macd_main) <= 0 ||
CopyBuffer(h_MACD, SIGNAL_LINE, Start, End, macd_signal) <= 0)
return;
int total = ArraySize(close);
double target1[], target2[], macd_delta[];
if(ArrayResize(target1, total) <= 0 || ArrayResize(target2, total) <= 0 ||
ArrayResize(macd_delta, total) <= 0)
return;
//--- Prepare values
double extremum = -1;
for(int i = ArraySize(zz) - 2; i >= 0; i--)
{
if(zz[i + 1] > 0 && zz[i + 1] != EMPTY_VALUE)
extremum = zz[i + 1];
if(i >= total)
continue;
target2[i] = extremum - close[i];
target1[i] = (target2[i] >= 0);
macd_delta[i] = macd_main[i] - macd_signal[i];
}