//+------------------------------------------------------------------+ //| SpearmanRankCorrelation.mq5 | //| Copyright © 2007, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #property version "1.10" #property indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_type1 DRAW_LINE #property indicator_color1 clrGold #property indicator_style1 STYLE_SOLID #property indicator_width1 1 #property indicator_minimum -1 #property indicator_maximum +1 input uint rangeN=14; input uint CalculatedBars=0; input uint Maxrange=30; input bool direction=true; double ExtLineBuffer[]; //---- double multiply; double R2[],TrueRanks[]; int PriceInt[],SortInt[],Maxrange_; //+------------------------------------------------------------------+ //| calculate RSP function | //+------------------------------------------------------------------+ double SpearmanRankCorrelation(double &Ranks[],int N) { double res,z2=0.0; for(int iii=0; iiiMaxrange_) shortname="Decrease rangeN input!"; else StringConcatenate(shortname,"Spearman(",rangeN,")"); PlotIndexSetString(0,PLOT_LABEL,shortname); IndicatorSetString(INDICATOR_SHORTNAME,shortname); IndicatorSetInteger(INDICATOR_DIGITS,2); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); IndicatorSetInteger(INDICATOR_LEVELS,3); IndicatorSetDouble(INDICATOR_LEVELVALUE,0,+0.50); IndicatorSetDouble(INDICATOR_LEVELVALUE,1,0); IndicatorSetDouble(INDICATOR_LEVELVALUE,2,-0.50); IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrGray); IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrGray); IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,clrGray); IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_DOT); IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,STYLE_DOT); IndicatorSetInteger(INDICATOR_LEVELSTYLE,2,STYLE_DOT); //---- } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[] ) { if(rates_totalMaxrange_) return(0); int limit; if(prev_calculated>rates_total || prev_calculated<=0) { limit=rates_total-2-int(rangeN)-begin; // стартовый номер для расчета всех баров if(begin>0) PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,int(rangeN)+begin); } else { if(!CalculatedBars) limit = rates_total - prev_calculated; else limit = int(CalculatedBars); } ArraySetAsSeries(price,true); for(int bar=limit; bar>=0; bar--) { for(int k=0; k