Navigation:Home > Content >

Leledc-SsrcForce.mq4

Time: 2014-11-08 | Download file:Leledc-SsrcForce.mq4

//попробовать с PriceInt[k]=MathRound(Mart[i+k]*multiply);
//+------------+-----------------------------------------------------+
//| v.12.04.07 |                                            SSRC.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
//Leledc:added MaBuffer and Visual Alert 
#property copyright ""
#property link      "http://www.forexter.land.ru/indicators.htm"
//----
#property indicator_separate_window
#property indicator_level1   0.9
#property indicator_level2  -0.9
#property indicator_level3   0.8
#property indicator_level4  -0.8
#property indicator_level5   0.7
#property indicator_level6  -0.7
#property indicator_levelcolor White
#property indicator_buffers  4
#property indicator_color1   Lime
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 2
#property indicator_color3 DodgerBlue
#property indicator_width3 1
#property indicator_color4 Magenta
#property indicator_width4 1

//---- input parameters
//---- Snake 
extern int    SnakeRange   =13; 
extern int    FilterPeriod =21; 
extern double MartFiltr    =2;
extern int    PriceConst   =6; 
extern int MaPeriod=8;
extern int MaMode=0;
extern bool   AlertOn=false;
extern int    ArrowUp=108;
extern int    ArrowDown=108;
extern int    distance =3;
extern bool   Five_digit_broker=true;
                               
int    Nrecalc = 20;
//---- buffers
double SRCBuffer[];
double Axis[];
double Mart[];
double Ma[];
double Up[],Down[];
//---- SpearmanRankCorrelation
int    rangeN = 14; //   = 30 maximum
double R2[];
double multiply;
int    PriceInt[];
int    SortInt[];
bool TurnedUp = false;
bool TurnedDown = false;

//+------------------------------------------------------------------+
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);
  break; }
for(Shift=Pos+SnakeRange+2;Shift>Pos;Shift--) { SnakeSum=0.0;
SnakeWeight=0; i=0; w=Shift+SnakeRange; ww=Shift-SnakeRange;
if(ww=Shift) { i++; SnakeSum=SnakeSum+i*SnakePrice(w); 
SnakeWeight=SnakeWeight+i; w--; }
while(w>=ww) { i--; SnakeSum=SnakeSum+i*SnakePrice(w);
SnakeWeight=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(WindowExpertName()+"( SR:"+SnakeRange+", FP:"+FilterPeriod+", MA:"+MaPeriod+" )");
multiply=MathPow(10,Digits); return(0); }
//+------------------------------------------------------------------+
int deinit() { return(0); }
//+------------------------------------------------------------------+
int start() { int i,k,limit,limit2,limit3;
   int LastSignal;

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)
  {
  if(FirstTickInBar())
    limit=MathMin(Bars-counted_bars+1+Nrecalc,Bars-(rangeN+FilterPeriod+SnakeRange+4) );
    else
      limit=Bars-counted_bars+1;
  limit2=limit;
  limit3=limit;
  }
for(i=limit2;i>=0;i--) MartAxis(i);
for(i=limit3;i>=0;i--) SmoothOverMart(i);
for(i=limit;i>=0;i--)
  { 
  for(k=0;k1.0) SRCBuffer[i]=1.0; 
  if(SRCBuffer[i]<-1.0) SRCBuffer[i]=-1.0;
  }
 for(i=limit;i>=0;i--)
  { 

  Ma[i]=iMAOnArray(SRCBuffer,0,MaPeriod,0,MaMode,i);
  
  }
   for(i=limit;i>=0;i--)
  { 
  if (SRCBuffer[i]>Ma[i] && SRCBuffer[i+1]Ma[i+1]&& i!=0 && LastSignal!=-1){
     LastSignal=-1;

  Down[i]=Ma[i];
  if  (AlertOn  &&  i==1 &&!TurnedDown )
           { 
            Alert(WindowExpertName()+" is crossing DOWN on"+" "+Symbol()," ",Period()+" "+"minute charts");
                      
             TurnedUp =false ;
            TurnedDown = true;
     }       
  }
  }
return(0);
}
//+------------------------------------------------------------------+
//*********************************************************************  


//+------------------------------------------------------------------+
//|               Проверка на первый тик в текущем баре.             |
//|          (Проверка на запуск только один раз в одном баре).      |
//|          True - текущий тик - первый в баре. False - не первый.  |
//+------------------------------------------------------------------+
bool FirstTickInBar()  
{
static datetime prevtime=0;
 if(prevtime == Time[0])                //Текущий тик - не первый в баре
   return(False);
 else                                   //Текущий тик - первый в баре
   {
   prevtime = Time[0];
   return(True);
   }
}
//*********************************************************************           

Recommend