Modification of gamma parameter in Laguerre Filter
Forums › ProRealTime English forum › ProBuilder support › Modification of gamma parameter in Laguerre Filter
- This topic has 1 reply, 2 voices, and was last updated 5 years ago by Nicolas.
Viewing 2 posts - 1 through 2 (of 2 total)
-
-
05/10/2019 at 11:08 AM #98165
Hi,
Does anyone know how you could modify the code of this indicator to parameterize the gamma you want as you can do that in the version of this indicator in metatrader4?
for example, gamma = 0.7https://www.prorealcode.com/prorealtime-indicators/laguerre-filter-price/ (link to the original indicator PRT)
Laguerre Filter price ProRealTime
Laguerre Filter on price1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556//parameters ://length = 20//Elements = 5Price = (High+Low+Open+Close)/4Diff = ABS(Price - Filt[1])HH = DiffLL = DiffFOR count = 0 TO Length - 1IF Diff[count] > HH THENHH = Diff[count]ENDIFIF Diff[count] < LL THENLL = Diff[count]ENDIFNEXTIf Barindex > Length AND HH - LL <> 0 THENCalcul = (Diff - LL) / (HH - LL)// Calculate MEDIAN with 5 Elements. Vary at willData = CalculNrElements = ElementsFOR X = 0 TO NrElements-1M = Data[X]SmallPart = 0LargePart = 0FOR Y = 0 TO NrElements-1IF Data[Y] < M THENSmallPart = SmallPart + 1ELSIF Data[Y] > M THENLargePart = LargePart + 1ENDIFIF LargePart = SmallPart AND Y = NrElements-1 THENMedian = MBREAKENDIFNEXTNEXTalpha = MedianL0 = alpha*Price + (1 - alpha)*L0[1]L1 = -(1 - alpha)*L0 + L0[1] + (1 - alpha)*L1[1]L2 = -(1 - alpha)*L1 + L1[1] + (1 - alpha)*L2[1]L3 = -(1 - alpha)*L2 + L2[1] + (1 - alpha)*L3[1]FILT = (L0 + 2*L1 + 2*L2 + L3) / 6ENDIFIF Barindex < 1 THENFILT = PriceENDIFRETURN Filt AS "Laguerre1"Laguerre Filter price MetaTrader4
Laguerre Filter MT4123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596//+------------------------------------------------------------------+//| LaguerreFilter.mq4 |//| Copyright © 2006, Forex-TSD.com |//| Written by IgorAD,igorad2003@yahoo.co.uk |//| http://finance.groups.yahoo.com/group/TrendLaboratory |//+------------------------------------------------------------------+#property copyright "Copyright © 2006, Forex-TSD.com "#property link "http://www.forex-tsd.com/"#property indicator_chart_window#property indicator_color1 Yellow//---- input parametersextern double gamma = 0.7;extern int Price_Type = 0;//---- buffersdouble Filter[];double L0[];double L1[];double L2[];double L3[];//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+int init(){IndicatorBuffers(5);//---- indicatorsSetIndexStyle(0, DRAW_LINE);SetIndexDrawBegin(0, 1);SetIndexLabel(0, "LaguerreFilter");SetIndexBuffer(0, Filter);SetIndexBuffer(1, L0);SetIndexBuffer(2, L1);SetIndexBuffer(3, L2);SetIndexBuffer(4, L3);//----string short_name="LaguerreFilter(" + DoubleToStr(gamma, 2) + ")";IndicatorShortName(short_name);return(0);}//+------------------------------------------------------------------+//| Custor indicator deinitialization function |//+------------------------------------------------------------------+int deinit(){return(0);}//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+int start(){int limit;int counted_bars = IndicatorCounted();double CU, CD;//---- last counted bar will be recountedif (counted_bars>0)counted_bars--;elsecounted_bars = 1;limit = Bars - counted_bars;//---- computations for RSIfor (int i=limit; i>=0; i--){double Price=iMA(NULL,0,1,0,0,Price_Type,i);L0[i] = (1.0 - gamma)*Price + gamma*L0[i+1];L1[i] = -gamma*L0[i] + L0[i+1] + gamma*L1[i+1];L2[i] = -gamma*L1[i] + L1[i+1] + gamma*L2[i+1];L3[i] = -gamma*L2[i] + L2[i+1] + gamma*L3[i+1];CU = 0;CD = 0;if (L0[i] >= L1[i])CU = L0[i] - L1[i];elseCD = L1[i] - L0[i];if (L1[i] >= L2[i])CU = CU + L1[i] - L2[i];elseCD = CD + L2[i] - L1[i];if (L2[i] >= L3[i])CU = CU + L2[i] - L3[i];elseCD = CD + L3[i] - L2[i];if (CU + CD != 0)Filter[i] = (L0[i] + 2 * L1[i] + 2 * L2[i] + L3[i]) / 6.0;}return(0);}//+------------------------------------------------------------------+Many thanks
05/10/2019 at 1:59 PM #98171I recoded it from scratch from the MT4 version, here it is:
123456789101112131415161718192021222324252627282930313233343536//parameters :gamma = 0.7Price = customcloseIf Barindex > 2 THENL0 = (1.0 - gamma)*Price + gamma*L0[1]L1 = -gamma*L0[0] + L0[1] + gamma*L1[1]L2 = -gamma*L1[0] + L1[1] + gamma*L2[1]L3 = -gamma*L2[0] + L2[1] + gamma*L3[1]CU = 0CD = 0if (L0 >= L1) thenCU = L0[0] - L1[0]elseCD = L1[0] - L0[0]endifif (L1[0] >= L2[0]) thenCU = CU + L1[0] - L2[0]elseCD = CD + L2[0] - L1[0]endifif (L2[0] >= L3[0]) thenCU = CU + L2[0] - L3[0]elseCD = CD + L3[0] - L2[0]endifif (CU + CD <> 0) thenFilter = (L0[0] + 2 * L1[0] + 2 * L2[0] + L3[0]) / 6.0ENDIFendifRETURN Filter AS "Laguerre1"You can now adjust the gamma as desired.
1 user thanked author for this post.
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
Find exclusive trading pro-tools on
Similar topics: