Article-24041-Autoregressiv.../vol2.mq5
alexeynikolaev2 9dc6bf09a1
2026-10-07 19:49:50 +03:00

48 lines
1.9 KiB
MQL5

//+------------------------------------------------------------------+
//| vol2.mq5 |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2026, MetaQuotes Ltd."
#property link "https://www.mql5.com"
//---
#property script_show_inputs
//---
input string symbol = "EURCHF"; // Market symbol for analysis
input datetime from_t = D'2024.09.20'; // Start of analysis time interval
input datetime to_t = D'2026.09.20'; // End of analysis time interval
input ulong pfit = 3; // Fitted p for model testing
input ulong qfit = 3; // Fitted q for model testing
//---
#include "EconometricsM.mqh"
//---
void OnStart()
{
//--- quotes downloading
MqlRates rates[];
int n_rates = CopyRates(symbol, PERIOD_D1, from_t, to_t, rates);
PrintFormat("Number of downloaded quotes for market symbol %s: %d", symbol, n_rates);
if(n_rates < 2)
return;
//--- y calculation
ulong n=(ulong)n_rates;
vector y(n);
for(ulong i=0;i<n;++i)
y[i]=MathLog(rates[i].high/rates[i].low);
//--- Model with fitted p and q testing
vector e;
CoefficientStats stats[];
SPrognose prog;
regression_CLS(y,pfit,qfit,vector::Zeros(pfit),vector::Zeros(qfit),e,stats,prog);
//--- Residuals graph vs t
t_residuals_plot(e);
//--- Residuals QQ-plot
qq_plot(e);
//--- EPDF of residuals vs. normal density
epdf_vs_normalpdf(e);
// Adaptive lag m for LM-test
ulong m = (ulong)MathMax(pfit+qfit+1,MathRound(MathLog(n)));
//--- Breusch-Godfrey serial correlation LM-test
LM_test(y,e,pfit,m);
}
//+------------------------------------------------------------------+