RSI Laguerre self adjusting gamma with Fractals Energy
Created at 11 Apr 2020, 03:23
AA
RSI Laguerre self adjusting gamma with Fractals Energy
11 Apr 2020, 03:23
Hi there, I'm attempting to replicate a RSI Laguerre with a self adjusting Gamma - based on some code from ProRealCode:
www.prorealcode.com/prorealtime-indicators/rsi-laguerre-adjusting-gamma-fractals-energy/
I can get the Laguerre RSI to work fine using gamma as a standard input, but when attempting to generate a "self adjusting" gamma value, I'm struggling to get the Laguerre RSI output. Not sure what I am missing here, any help greatly appreciated.
PS - This is my first post - so hopefully I have attached the code correcty?
using System;
using cAlgo.API;
using System.Linq;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None, ScalePrecision = 2)]
public class LaguerreRSI_SelfAdjusting : Indicator
{
[Parameter("Fractal Period", DefaultValue = 13)]
public int Period { get; set; }
[Output("LagRSI", LineColor = "DodgerBlue", LineStyle = LineStyle.Solid, Thickness = 2)]
public IndicatorDataSeries LagRSI { get; set; }
[Output("Fractal Energy/Gamma", LineColor = "Red", LineStyle = LineStyle.Solid, Thickness = 2)]
public IndicatorDataSeries FE { get; set; }
//Raw Laguerre
private IndicatorDataSeries L0;
private IndicatorDataSeries L1;
private IndicatorDataSeries L2;
private IndicatorDataSeries L3;
private double cd;
private double cu;
//Gamma
private double o;
private double hh;
private double ll;
private double c;
private double Gamma;
//MarketDepth Series
private double price;
protected override void Initialize()
{
//Lag RSI
L0 = CreateDataSeries();
L1 = CreateDataSeries();
L2 = CreateDataSeries();
L3 = CreateDataSeries();
}
public override void Calculate(int index)
{
if (index < Period)
return;
// Calculate value at specified index
double sumHH = Bars.HighPrices.Sum(Period);
double sumLL = Bars.LowPrices.Sum(Period);
double max = Bars.HighPrices.Maximum(Period);
double min = Bars.LowPrices.Minimum(Period);
//Calulate the Gamma value for the Laguerre RSI - Based on Fractal Energy (Choppiness Index)
FE[index] = (Math.Log10((sumHH - sumLL) / (max-min))) / Math.Log10(Period);
Gamma = FE[index];
//Calculate Price
o = (Bars.OpenPrices.Last(1) + Bars.ClosePrices.Last(1)) / 2;
hh = Bars.HighPrices.Last(1);
ll = Bars.LowPrices.Last(1);
c = Bars.ClosePrices.Last(1);
price = (o + hh + ll + c) / 4;
//Raw Laguerre RSI
if (index <= 6)
{
L0[index] = (1 - Gamma) * price;
L1[index] = -Gamma * L0[index] + L0[index-1];
L2[index] = -Gamma * L1[index] + L1[index-1];
L3[index] = -Gamma * L2[index] + L2[index-1];
}
if (index > 6)
{
L0[index] = (1 - Gamma) * price + Gamma * L0[index-1];
L1[index] = -Gamma * L0[index] + L0[index - 1] + Gamma * L1[index - 1];
L2[index] = -Gamma * L1[index] + L1[index - 1] + Gamma * L2[index - 1];
L3[index] = -Gamma * L2[index] + L2[index - 1] + Gamma * L3[index - 1];
}
//Generate Laguerre Trends
cu = 0;
cd = 0;
if (L0[index] >= L1[index])
{
cu = L0[index] - L1[index];
}
else
{
cd = L1[index] - L0[index];
}
if (L1[index] >= L2[index])
{
cu = cu + L1[index] - L2[index];
}
else
{
cd = cd + L2[index] - L1[index];
}
if (L2[index] >= L3[index])
{
cu = cu + L2[index] - L3[index];
}
else
{
cd = cd + L3[index] - L2[index];
}
if (cu + cd != 0)
{
//LagSLOWrsi[index] = (cu - cd) / (cu + cd);
LagRSI[index] = cu / (cu + cd);
}
else
LagRSI[index] = 0;
Print(" Gamma: ", Gamma, " price: ", price, " L0: ", L0[index], " L1: ", L1[index],
" L2: ", L2[index], " L3: ", L3[index], " LagRSI: ", LagRSI[index]);