-wmmm-Gaussian Bands

Author: zzuegg
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
-wmmm-Gaussian Bands
//+------------------------------------------------------------------+
//|                                                       GBands.mq4 |
//|                                                           zzuegg |
//|                                       when-money-makes-money.com |
//+------------------------------------------------------------------+
#property copyright "zzuegg"
#property link      "when-money-makes-money.com"

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Blue

//---- buffers
double center[];
double up.1[];
double do.1[];
double up.2[];
double do.2[];
double var[];
double var1[];
double var2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
extern int centerPeriod=12;
extern int dev.1.Period=12;
extern double dev.1.Multi=2;
extern int dev.2.Period=12;
extern double dev.2.Multi=4;

double center.alfa,dev.1.alfa,dev.2.alfa;
double     pi = 3.1415926535;

color lc[]={Yellow,Gold,Orange,DarkOrange,OrangeRed,Red,OrangeRed,DarkOrange,Orange,Gold};


double getAlfa(int p){

   double w = 2*pi/p;
	double beta = (1 - MathCos(w))/(MathPow(1.414,2.0/3) - 1);
	double alfa = -beta + MathSqrt(beta*beta + 2*beta);
	return (alfa);
}


int init()
  {
//---- indicators


     ObjectCreate("logo",OBJ_LABEL,0,0,0);
   ObjectSetText("logo","when-money-makes-money.com",20);
   ObjectSet("logo",OBJPROP_XDISTANCE,0);
   ObjectSet("logo",OBJPROP_YDISTANCE,30);

   center.alfa=getAlfa(centerPeriod);
   dev.1.alfa=getAlfa(dev.1.Period);
   dev.2.alfa=getAlfa(dev.2.Period);
   IndicatorBuffers(8);
   SetIndexStyle(0,DRAW_LINE,STYLE_DOT,1);
   SetIndexBuffer(0,center);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,up.1);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,do.1);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,3);
   SetIndexBuffer(3,up.2);
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,3);
   SetIndexBuffer(4,do.2);
   SetIndexBuffer(5,var);
   SetIndexBuffer(6,var1);
   SetIndexBuffer(7,var2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
     ObjectDelete("logo"); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
double GSMOOTH(double price,double arr[],double alfa,int i){
	    double ret = MathPow(alfa,4)*price + 4*(1-alfa)*arr[i+1] - 6*MathPow(1-alfa,2)*arr[i+2] + 4*MathPow(1-alfa,3)*arr[i+3] - MathPow(1-alfa,4)*arr[i+4];
       return (ret);     

}


int start()
  {
   int    counted_bars=IndicatorCounted();
//----

     static int currc=0;
   ObjectSet("logo",OBJPROP_COLOR,lc[currc]);
   currc++;
   if(currc>=ArraySize(lc))currc=0;


   for(int i=Bars-counted_bars-1;i>=0;i--){
      center[i]=GSMOOTH(Close[i],center,center.alfa,i);
      var[i]=MathAbs(Close[i]-center[i]);
      if(var[i]>0){
      var1[i]=GSMOOTH(var[i],var1,dev.1.alfa,i);
      var2[i]=GSMOOTH(var[i],var2,dev.2.alfa,i);
      }
      Print(var[i]);
      up.1[i]=center[i]+(var1[i]*dev.1.Multi);
      do.1[i]=center[i]-(var1[i]*dev.1.Multi);
      up.2[i]=center[i]+(var2[i]*dev.2.Multi);
      do.2[i]=center[i]-(var2[i]*dev.2.Multi);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments