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.7
https://www.prorealcode.com/prorealtime-indicators/laguerre-filter-price/ (link to the original indicator PRT)
Laguerre Filter price ProRealTime
//parameters :
//length = 20
//Elements = 5
Price = (High+Low+Open+Close)/4
Diff = ABS(Price - Filt[1])
HH = Diff
LL = Diff
FOR count = 0 TO Length - 1
IF Diff[count] > HH THEN
HH = Diff[count]
ENDIF
IF Diff[count] < LL THEN
LL = Diff[count]
ENDIF
NEXT
If Barindex > Length AND HH - LL <> 0 THEN
Calcul = (Diff - LL) / (HH - LL)
// Calculate MEDIAN with 5 Elements. Vary at will
Data = Calcul
NrElements = Elements
FOR X = 0 TO NrElements-1
M = Data[X]
SmallPart = 0
LargePart = 0
FOR Y = 0 TO NrElements-1
IF Data[Y] < M THEN
SmallPart = SmallPart + 1
ELSIF Data[Y] > M THEN
LargePart = LargePart + 1
ENDIF
IF LargePart = SmallPart AND Y = NrElements-1 THEN
Median = M
BREAK
ENDIF
NEXT
NEXT
alpha = Median
L0 = 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) / 6
ENDIF
IF Barindex < 1 THEN
FILT = Price
ENDIF
RETURN Filt AS "Laguerre1"
Laguerre Filter price MetaTrader4
//+------------------------------------------------------------------+
//| 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 parameters
extern double gamma = 0.7;
extern int Price_Type = 0;
//---- buffers
double Filter[];
double L0[];
double L1[];
double L2[];
double L3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(5);
//---- indicators
SetIndexStyle(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 recounted
if (counted_bars>0)
counted_bars--;
else
counted_bars = 1;
limit = Bars - counted_bars;
//---- computations for RSI
for (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];
else
CD = L1[i] - L0[i];
if (L1[i] >= L2[i])
CU = CU + L1[i] - L2[i];
else
CD = CD + L2[i] - L1[i];
if (L2[i] >= L3[i])
CU = CU + L2[i] - L3[i];
else
CD = 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
I recoded it from scratch from the MT4 version, here it is:
//parameters :
gamma = 0.7
Price = customclose
If Barindex > 2 THEN
L0 = (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 = 0
CD = 0
if (L0 >= L1) then
CU = L0[0] - L1[0]
else
CD = L1[0] - L0[0]
endif
if (L1[0] >= L2[0]) then
CU = CU + L1[0] - L2[0]
else
CD = CD + L2[0] - L1[0]
endif
if (L2[0] >= L3[0]) then
CU = CU + L2[0] - L3[0]
else
CD = CD + L3[0] - L2[0]
endif
if (CU + CD <> 0) then
Filter = (L0[0] + 2 * L1[0] + 2 * L2[0] + L3[0]) / 6.0
ENDIF
endif
RETURN Filter AS "Laguerre1"
You can now adjust the gamma as desired.