Navigation:Home > Content >

SSRC_no_repaint.mq4

Time: 2010-10-21 | Download file:SSRC_no_repaint.mq4

//+------------+-----------------------------------------------------+
//| v.12.04.07 |                                 SSRC no repaint.mq4 |
//+------------+              Spearman,                              |
//|            |              Rosh                                   |
//|            |              И примазавшийся к ним                  |
//|            |              Bookkeeper, 2007, [email protected] |
//+------------+-----------------------------------------------------+
// http://www.improvedoutcomes.com/docs/WebSiteDocs/Clustering/
// Clustering_Parameters/Spearman_Rank_Correlation_Distance_Metric.htm
// http://www.infamed.com/stat/s05.html
// http://www.metaquotes.net
// http://codebase.mql4.com/ru/1023
#property copyright ""
#property link      ""
//----
#property indicator_separate_window
#property indicator_maximum 1.3
#property indicator_minimum -1.3
#property indicator_level1 0.9
#property indicator_level2 -0.9
#property indicator_level3 0.75
#property indicator_level4 -0.75
#property indicator_level5 0
#property indicator_buffers 1
#property indicator_color1 Lime
//---- input parameters
//---- Snake 
extern int    SnakeRange   =14; 
extern int    FilterPeriod =21; 
extern double MartFiltr    =2;
extern int    PriceConst   =6; // 0 - Close
                               // 1 - Open
                               // 2 - High
                               // 3 - Low
                               // 4 - (H+L)/2
                               // 5 - (H+L+C)/3
                               // 6 - (H+L+2*C)/4
//---- buffers
double SRCBuffer[];
double Axis[];
double Mart[];
//---- SpearmanRankCorrelation
int    rangeN = 14; //   = 30 maximum
double R2[];
double multiply;
int    PriceInt[];
int    SortInt[];

//+------------------------------------------------------------------+
void MartAxis(int Pos) 
{ 
   int SnakeWeight,i,w,ww,Shift;
   double SnakeSum;
/*
   switch(PriceConst) 
   {
      case  0:  Axis[Pos]=iMA(NULL,0,SnakeRange+1,0,MODE_LWMA,PRICE_CLOSE,Pos);    break;
      case  1:  Axis[Pos]=iMA(NULL,0,SnakeRange+1,0,MODE_LWMA,PRICE_OPEN,Pos);     break;
      case  2:  Axis[Pos]=iMA(NULL,0,SnakeRange+1,0,MODE_LWMA,PRICE_HIGH,Pos);     break;
      case  3:  Axis[Pos]=iMA(NULL,0,SnakeRange+1,0,MODE_LWMA,PRICE_LOW,Pos);      break;
      case  4:  Axis[Pos]=iMA(NULL,0,SnakeRange+1,0,MODE_LWMA,PRICE_MEDIAN,Pos);   break;
      case  5:  Axis[Pos]=iMA(NULL,0,SnakeRange+1,0,MODE_LWMA,PRICE_TYPICAL,Pos);  break;
      case  6:  Axis[Pos]=iMA(NULL,0,SnakeRange+1,0,MODE_LWMA,PRICE_WEIGHTED,Pos); break;
      default:  Axis[Pos]=iMA(NULL,0,SnakeRange+1,0,MODE_LWMA,PRICE_WEIGHTED,Pos); 
   }
*/
   Axis[Pos]=iMA(NULL,0,SnakeRange+1,0,MODE_LWMA,PriceConst,Pos);

   for(Shift=Pos+SnakeRange+2;Shift>Pos;Shift--) 
   { 
      SnakeSum=0.0;
      SnakeWeight=0; 

      i=0; 
      w=Shift+SnakeRange; 
      while(w>=Shift) 
      { 
         i++; 
         SnakeSum+=i*SnakePrice(w); 
         SnakeWeight+=i; 
         w--; 
      }

      ww=Shift-SnakeRange;
      if(ww=ww) 
      { 
         i--; 
         SnakeSum+=i*SnakePrice(w);
         SnakeWeight+=i; 
         w--; 
      }
      Axis[Shift]=SnakeSum/SnakeWeight; 
   } 
   return; 
}

//----
double SnakePrice(int Shift) 
{
   switch(PriceConst) 
   {
      case  0: return(Close[Shift]);
      case  1: return(Open[Shift]);
      case  2: return(High[Shift]);
      case  3: return(Low[Shift]);
      case  4: return((High[Shift]+Low[Shift])/2);
      case  5: return((Close[Shift]+High[Shift]+Low[Shift])/3);
      case  6: return((2*Close[Shift]+High[Shift]+Low[Shift])/4);
      default: return(Close[Shift]); 
   } 
}

//+------------------------------------------------------------------+
void SmoothOverMart(int Shift) 
{ 
   double t,b;
   t=Axis[ArrayMaximum(Axis,FilterPeriod,Shift)];
   b=Axis[ArrayMinimum(Axis,FilterPeriod,Shift)];
   Mart[Shift]=(2*(2+MartFiltr)*Axis[Shift]-(t+b))/2/(1+MartFiltr);
   return; 
}

//+------------------------------------------------------------------+
double SpearmanRankCorrelation(double Ranks[], int N) 
{ 
   double res,z2;
   for(int i=0;i30) 
      IndicatorShortName("Decrease rangeN input!");
   else 
      IndicatorShortName("SSRC no repaint( SR:"+SnakeRange+", FP:"+FilterPeriod+" )");
   multiply=MathPow(10,Digits); 
   return(0); 
}

//+------------------------------------------------------------------+
int deinit() 
{ 
   return(0); 
}

//+------------------------------------------------------------------+
int start() 
{ 
   int i,k,limit,limit2,limit3;
   int counted_bars=IndicatorCounted(); 
   if(rangeN>30) return(-1);
   if(counted_bars==0) {
      limit=Bars-(rangeN+FilterPeriod+SnakeRange+4);
      limit2=Bars-(SnakeRange+2);
      limit3=Bars-(FilterPeriod+SnakeRange+3); 
   }
   //if(counted_bars>0) { 
      limit=Bars-counted_bars; 
      limit2=limit; 
      limit3=limit; 
   //}
    
   for(i=limit;i>=0;i--) 
   { 
      MartAxis(i);
       SmoothOverMart(i);
      for(k=0;k1.0) SRCBuffer[i]=1.0; 
      if(SRCBuffer[i]<-1.0) SRCBuffer[i]=-1.0; 
   } 
   return(0); 
}

//+------------------------------------------------------------------+

Recommend