//+------------------------------------------------------------------+ //| ex-dif-fracionaria.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #include //#include //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ input int hist = 1000; //tamanho do serie de dados que serah analisada. void OnStart() { //for(double i=0.05; i<1.0; plotFFD(i+=0.05,1e-5)) plotFFD(0.05,1e-5); } //+------------------------------------------------------------------+ void plotFFD(double fd, double thresh) { datetime from = D'2020.08.14 09:00:00'; datetime to = D'2020.08.14 09:10:00'; double prarr[], out[]; MqlTick ticks[]; CopyClose(_Symbol, 0, 0, hist, prarr); CopyTicksRange( _Symbol ,// nome do símbolo ticks ,// matriz para recebimento de ticks COPY_TICKS_TRADE ,// sinalizador que define o tipo de ticks obtidos from*1000 ,// data a partir da qual são solicitados os ticks to *1000 // data ateh quando sao solicitados os ticks ); int lenVetTicks = ArraySize(ticks); ArrayResize(prarr,lenVetTicks,0); for(int i=0;i err) { eq = false; break; } } if (eq) Cm++; //m+1 - length series int k = m; if (eq && MathAbs(data[i+k] - data[j+k]) <= err) Cm1++; } } if (Cm > 0 && Cm1 > 0) return log((double)Cm / (double)Cm1); else return 0.0; } //+------------------------------------------------------------------+ // Calculate the cross-sample entropy of 2 signals // u : signal 1 // v : signal 2 // m : length of the patterns that compared to each other // r : tolerance // return the cross-sample entropy value double cross_SampEn(double &u[], double &v[], int m, double r) { double B = 0.0; double A = 0.0; if (ArraySize(u) != ArraySize(v)) Print("Error : lenght of u different than lenght of v"); int N = ArraySize(u); for(int i=0;i<(N-m);i++) { for(int j=0;j<(N-m);j++) { double ins[]; ArrayResize(ins, m); double ins2[]; ArrayResize(ins2, m); ArrayCopy(ins, u, 0, i, m); ArrayCopy(ins2, v, 0, j, m); B += cross_match(ins, ins2, m, r) / (N - m); ArrayResize(ins, m+1); ArrayResize(ins2, m+1); ArrayCopy(ins, u, 0, i, m + 1); ArrayCopy(ins2, v, 0, j, m +1); A += cross_match(ins, ins2, m + 1, r) / (N - m); } } B /= N - m; A /= N - m; return -log(A / B); } //+------------------------------------------------------------------+ // calculation of the matching number // it use in the cross-sample entropy calculation double cross_match(double &signal1[], double &signal2[], int m, double r) { // return 0 if not match and 1 if match double darr[]; for(int i=0; i