indicator Laguerre_RSI;
input price = close, Gamma = 0.5, High_Baseline = 0.80, Low_Baseline = 0.20;
draw LaguerreRSI("Laguerre RSI", solid_line,dark_magenta,1),
     line_high("HIGH Baseline",dot_line,dark_red,1),
     line_low("LOW Baseline",dot_line,dark_red,1);
vars i(number),
     f(number),
     line_hi(series),
     line_lo(series),
     L0(series),
   L1(series),
   L2(series),
   L3(series),
   CU(number),
   CD(number),
   RSI(series);
begin
 f := front(price);
 L0[f] := 0;
 L1[f] := 0;
 L2[f] := 0;
 L3[f] := 0;
 RSI[f] := 0;
 CU:= 0;
 CD:= 0;
for i:=f + 1 to back(price) do
begin  
line_hi[i] := high_baseline;
line_lo[i] := low_baseline;
L0[i] := (1 - gamma) * price[i] + 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];

If L0[i] >= L1[i] then CU := L0[i] - L1[i] Else CD:= L1[i] - L0[i];
If L1[i] >= L2[i] then CU := CU + L1[i] - L2[i] Else CD := CD + L2[i] - L1[i];
If L2[i] >= L3[i] then CU := CU + L2[i] - L3[i] Else CD := CD + L3[i] - L2[i];
If (CU + CD) <> 0 then RSI[i] := CU / (CU + CD) ;
end;
LaguerreRSI:=RSI;
line_high:=line_hi;
line_low:=line_lo;
end.