1 registered members (AbrahamR),
717
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: LowPass filter formula
[Re: jcl]
#410767
11/08/12 14:37
11/08/12 14:37
|
Joined: Nov 2012
Posts: 19 Texas, US
deweymcg
Newbie
|
Newbie
Joined: Nov 2012
Posts: 19
Texas, US
|
George on Steve Hopwood's forum was kind enough to supply this for Metatrader:
#property copyright "Copyright © 2012, George Heitman" #property link "http://www.stevehopwoodforex.com"
#property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Black
//---- input parameters extern int Per=20; extern int Price=PRICE_CLOSE;
//---- buffers double LP[];
//+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; //---- additional buffers are used for counting. IndicatorBuffers(1); SetIndexBuffer(0,LP);
//---- indicator lines SetIndexStyle(0,DRAW_LINE);
//---- name for DataWindow label short_name=StringConcatenate("LowPass Filter (",Per,")"); IndicatorShortName(short_name); SetIndexLabel(0,short_name); //---- SetIndexDrawBegin(0,Per); //---- return(0); }
int start() { int i,limit; int counted_bars=IndicatorCounted(); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; double a = 2.0/(Per+1.0); double a2 = a*a; double p1, p2, p3;
for(i=limit; i>=0; i--) {
switch(Price) { case PRICE_CLOSE: p1 = Close[i]; p2 = Close[i+1];p3 = Close[i+2];break; case PRICE_OPEN: p1 = Open[i]; p2 = Open[i+1];p3 = Open[i+2];break; case PRICE_HIGH: p1 = High[i]; p2 = High[i+1];p3 = High[i+2];break; case PRICE_LOW: p1 = Low[i]; p2 = Low[i+1];p3 = Low[i+2];break; case PRICE_MEDIAN: p1 = (High[i]+Low[i])/2; p2 = (High[i+1]+Low[i+1])/2;p3 = (High[i+2]+Low[i+2])/2;break; case PRICE_TYPICAL: p1 = (High[i]+Low[i]+Close[i])/3; p2 = (High[i+1]+Low[i+1]+Close[i+1])/3;p3 = (High[i+2]+Low[i+2]+Close[i+2])/3;break; case PRICE_WEIGHTED: p1 = (High[i]+Low[i]+2*Close[i])/4; p2 = (High[i+1]+Low[i+1]+2*Close[i+1])/4;p3 = (High[i+2]+Low[i+2]+2*Close[i+2])/4;break; default: p1 = Close[i]; p2 = Close[i+1];p3 = Close[i+2]; }
LP[i] = (a-0.25*a2)*p1 + 0.5*a2*p2 - (a-0.75*a2)*p3 + 2*(1.0-a)*LP[i+1] - (1.0-a)*(1.0-a)*LP[i+2]; } return(0); } //+------------------------------------------------------------------+
|
|
|
Re: LowPass filter formula
[Re: deweymcg]
#459734
06/02/16 08:06
06/02/16 08:06
|
Joined: May 2016
Posts: 16 USA
JerryS
Newbie
|
Newbie
Joined: May 2016
Posts: 16
USA
|
From: http://www.financial-hacker.com/trend-delusion-or-reality/var LowPass(var *Data,int Period) { var* LP = series(Data[0]); var a = 2.0/(1+Period); return LP[0] = (a-0.25*a*a)*Data[0] + 0.5*a*a*Data[1] - (a-0.75*a*a)*Data[2] + 2*(1.-a)*LP[1] - (1.-a)*(1.-a)*LP[2]; } I'm having trouble actually finding this function in the files that came with Zorro though... and I'm not sure what the Data is (i'm new to Zorro--is it ever defined in the code or it's just a variable you can replace with anything?)
Last edited by JerryS; 06/02/16 08:17.
|
|
|
Re: LowPass filter formula
[Re: JerryS]
#459737
06/02/16 10:45
06/02/16 10:45
|
Joined: Jul 2000
Posts: 27,986 Frankfurt
jcl
Chief Engineer
|
Chief Engineer
Joined: Jul 2000
Posts: 27,986
Frankfurt
|
|
|
|
Re: LowPass filter formula
[Re: jcl]
#459766
06/03/16 13:01
06/03/16 13:01
|
Joined: Jun 2013
Posts: 1,609
DdlV
Serious User
|
Serious User
Joined: Jun 2013
Posts: 1,609
|
Hi JerryS. No idea what your computer/science/math background is, but I'll try to help. To expand on what jcl said, recursive is not the same as circular. Circular means the calculation is in some way using itself. Recursive means a prior value is being used. The classic example is factorial: n! = n * (n-1)!. In the case of Zorro, this is done with series() (for simplicity to start think of them as time series). Perhaps the missing element is that on the first bar the value of y[n] with n>0 is 0 - only y[0] has a value. But on the next bar y[1] does also (the value of y[0] at the end of the previous bar), and so on. In this way the series is populated. If you add debug prints to your code, you can see this happening (as well as find other issues ). HTH.
|
|
|
|