//+------------------------------------------------------------------+ //| fractional.mq5 | //| Copyright 2019, Dmitrievsky Max. | //| https://www.mql5.com/en/users/dmitrievsky | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, Dmitrievsky Max." #property link "https://www.mql5.com/en/users/dmitrievsky" #property version "1.00" #property indicator_separate_window #property indicator_buffers 2 #property indicator_plots 1 #include //+----------------------------------------------+ //| Indicaor display parameters | //+----------------------------------------------+ //--- draw indicaor 1 as a line #property indicator_type1 DRAW_LINE #property indicator_color1 clrGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- draw the indicator's bullish label #property indicator_label1 "Fracdiff" double ind_buffer[], calc_buffer[]; double weights[]; input bool entropy_eval = true; // exibir leituras de entropia ou incremento input double diff_degree = 0.3 ; // grau de diferenciacao da serie temporal input double treshhold = 1e-5; // limite para cortar pesos em excesso (pode ser deixado por padrao) input int hist_display = 5000; // profundidade do historico exibido input int entropy_window = 50 ; // janela deslizante para avaliar a entropia do processo double maxdigit, mindigit; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { get_weight_ffd(diff_degree, treshhold, 10000, weights); //--- indicator buffers mapping SetIndexBuffer(0, ind_buffer, INDICATOR_DATA); SetIndexBuffer(1, calc_buffer, INDICATOR_CALCULATIONS); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, NULL); PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, NULL); ArraySetAsSeries(ind_buffer, true); ArraySetAsSeries(calc_buffer, true); IndicatorSetInteger(INDICATOR_DIGITS, 2); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate (const int rates_total, // price[] array size const int prev_calculated, // pricessed bars at the previous call const int begin, // where the meaningful data starts from const double& price[]) // array for calculation { //--- frac_diff_ffd(weights, price, calc_buffer, (entropy_eval) ? hist_display+entropy_window+1 : hist_display, prev_calculated !=0); if(!entropy_eval) calc_zscore(calc_buffer, ind_buffer); else { double prpr []; ArrayResize(prpr , entropy_window+1); ArraySetAsSeries(prpr , true); double calcEn[]; ArrayResize(calcEn, entropy_window ); ArraySetAsSeries(calcEn, true); for(int i=0;i 0 ? 1 : -1; double st = MathStandardDeviation(calcEn); ind_buffer[i] = sample_entropy(calcEn, 1, 0.01, entropy_window, st); if(prev_calculated != 0) break; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ void calc_zscore(double &inp[], double &out[]) { static double max = DBL_MIN, min = DBL_MAX, zmean, zstd; double buff[]; ArraySetAsSeries(buff, true); ArrayCopy(buff, inp, 0, 0, hist_display); if(buff[ArrayMaximum(buff)] > max || buff[ArrayMinimum(buff)] < min) { max = buff[ArrayMaximum(buff)]; min = buff[ArrayMinimum(buff)]; zmean = MathMean(buff); zstd = MathStandardDeviation(buff); 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; }