-wmmm-GaussianFilter_v1

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

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 DodgerBlue
#property indicator_color3 Tomato
#property indicator_color4 Blue
#property indicator_color5 Red
//---- buffers
double fil[];
double fil_u[];
double fil_d[];
double fil_f_u[];
double fil_f_d[];
color lc[]={Yellow,Gold,Orange,DarkOrange,OrangeRed,Red,OrangeRed,DarkOrange,Orange,Gold};
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

double     pi=3.1415926535;

extern int FilterPeriod=12;

double fil_alfa;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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()
  {
   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);
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,fil);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   SetIndexBuffer(1,fil_u);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
   SetIndexBuffer(2,fil_d);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,159);
   SetIndexBuffer(3,fil_f_u);
   SetIndexEmptyValue(3,0.0);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,159);
   SetIndexBuffer(4,fil_f_d);
   SetIndexEmptyValue(4,0.0);
   fil_alfa=getAlfa(FilterPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| GSMOOTH                                                          |
//+------------------------------------------------------------------+
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);

  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

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

   //int    counted_bars=IndicatorCounted();
   
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars > 0)   counted_bars--;
   int limit = Bars - counted_bars;
   if(counted_bars==0) limit-=1+4;
      
//----
   for(int i=limit;i>=0;i--)
     {
      fil[i]=GSMOOTH(Close[i+1],fil,fil_alfa,i);
      if(fil[i]>fil[i+1])
        {
         fil_u[i]=fil[i];
         fil_u[i+1]=fil[i+1];
        }
      if(fil[i]<fil[i+1])
        {
         fil_d[i]=fil[i];
         fil_d[i+1]=fil[i+1];
        }
      double s2=fil[i+2]-fil[i+1];
      double s1=fil[i+1]-fil[i];
      if(s1<s2)
        {
         fil_f_u[i]=fil[i];

        }
      if(s1>s2)
        {
         fil_f_d[i]=fil[i];

        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---