```
#########################################
declare lower;
input period = AggregationPeriod.DAY;
input nFE = 13;#hint nFE: length for Fractal Energy calculation.
input RSI_BullishTrigger = .1;
input RSI_BearishTrigger = .9;
DefineGlobalColor("Long", Color.Green);
DefineGlobalColor("Short", Color.RED);
DefineGlobalColor("Neutral", Color.Yellow);
DefineGlobalColor("arrow Buy", Color.Cyan);
DefineGlobalColor("arrow Sell", Color.Orange);
Script SymbolHK_RSI_L{
input period = AggregationPeriod.DAY;
def OP = Open(period= period);
def CP = Close(Period= period);
def HP = High(period= period);
def LP = Low(Period= period);
input nFE = 13;#hint nFE: length for Fractal Energy calculation.
input RSI_BullishTrigger = .1;
input RSI_BearishTrigger = .9;
# Variables:
def o;
def h;
def l;
def c;
def CU1;
def CU2;
def CU;
def CD1;
def CD2;
def CD;
def L0;
def L1;
def L2;
def L3;
# Calculations
o = (OP + CP[1]) / 2;
h = Max(HP, CP[1]);
l = Min(LP, CP[1]);
c = (OP + HP + LP + CP) / 4;
#Self adjusting Gamma code
Def gamma = Log(Sum((Max(HP, CP[1]) - Min(LP, CP[1])), nFE) /
(Highest(HP, nFE) - Lowest(LP, nFE)))
/ Log(nFE);
L0 = (1 – gamma) * c + gamma * L0[1];
L1 = -gamma * L0 + L0[1] + gamma * L1[1];
L2 = -gamma * L1 + L1[1] + gamma * L2[1];
L3 = -gamma * L2 + L2[1] + gamma * L3[1];
if L0 >= L1 then { CU1 = L0 - L1;
CD1 = 0; } else { CD1 = L1 - L0; CU1 = 0; }
if L1 >= L2 then { CU2 = CU1 + L1 - L2; CD2 = CD1; } else {
CD2 = CD1 + L2 - L1; CU2 = CU1; }
if L2 >= L3 then { CU = CU2 + L2 - L3; CD = CD2; } else {
CU = CU2; CD = CD2 + L3 - L2; }
Def RSIL = if CU + CD <> 0 then CU / (CU + CD) else 0;
Plot result =
if (RSIL > RSI_BearishTrigger) or ((RSIL >= RSIL[1]) and (RSIL > RSI_BullishTrigger))
then 1
else if (RSIL < RSI_BullishTrigger) or ((RSIL < RSIL[1]) and (RSIL < RSI_BearishTrigger))
then -1 else 0;}
Script SymbolHK_RSI_LArrows{
input period = AggregationPeriod.DAY;
def OP = Open(period= period);
def CP = Close(Period= period);
def HP = High(period= period);
def LP = Low(Period= period);
input nFE = 13;#hint nFE: length for Fractal Energy calculation.
input RSI_BullishTrigger = .1;
input RSI_BearishTrigger = .9;
# Variables:
def o;
def h;
def l;
def c;
def CU1;
def CU2;
def CU;
def CD1;
def CD2;
def CD;
def L0;
def L1;
def L2;
def L3;
# Calculations
o = (OP + CP[1]) / 2;
h = Max(HP, CP[1]);
l = Min(LP, CP[1]);
c = (OP + HP + LP + CP) / 4;
#Self adjusting Gamma code
Def gamma = Log(Sum((Max(HP, CP[1]) - Min(LP, CP[1])), nFE) /
(Highest(HP, nFE) - Lowest(LP, nFE)))
/ Log(nFE);
L0 = (1 – gamma) * c + gamma * L0[1];
L1 = -gamma * L0 + L0[1] + gamma * L1[1];
L2 = -gamma * L1 + L1[1] + gamma * L2[1];
L3 = -gamma * L2 + L2[1] + gamma * L3[1];
if L0 >= L1 then { CU1 = L0 - L1;
CD1 = 0; } else { CD1 = L1 - L0; CU1 = 0; }
if L1 >= L2 then { CU2 = CU1 + L1 - L2; CD2 = CD1; } else {
CD2 = CD1 + L2 - L1; CU2 = CU1; }
if L2 >= L3 then { CU = CU2 + L2 - L3; CD = CD2; } else {
CU = CU2; CD = CD2 + L3 - L2; }
Def RSI = if CU + CD <> 0 then CU / (CU + CD) else 0;
Plot result =
if (RSI Crosses Above RSI_BullishTrigger) or ((RSI[2] > RSI[1]) and (RSI[1] <= RSI))
then 1
else if (RSI Crosses below RSI_BearishTrigger) or ((RSI[2] < RSI[1]) and (RSI[1] > RSI))
then -1 else 0;}
def currentPeriod = GetAggregationPeriod();
def s1;
def h1;
if period >= currentPeriod {
s1 = SymbolHK_RSI_L(period = period ,nFE = nFE, RSI_BullishTrigger = RSI_BullishTrigger, RSI_BearishTrigger = RSI_BearishTrigger);
h1 = SymbolHK_RSI_LArrows(period = period, nFE = nFE, RSI_BullishTrigger = RSI_BullishTrigger, RSI_BearishTrigger = RSI_BearishTrigger);
} else {
s1 = Double.NaN;
h1 = DOuble.Nan;
}
AddLabel(!IsNaN(s1), "RSIL:" + (if period == AggregationPeriod.MONTH then "M"
else
if period == AggregationPeriod.WEEK then "W"
else
if period == AggregationPeriod.FOUR_DAYS then "4D"
else
if period == AggregationPeriod.THREE_DAYS then "3D"
else
if period == AggregationPeriod.TWO_DAYS then "2D"
else
if period == AggregationPeriod.DAY then "D"
else
if period == AggregationPeriod.FOUR_HOURS then "4H"
else
if period == AggregationPeriod.TWO_HOURS then "2H"
else
if period == AggregationPeriod.HOUR then "60m"
else
if period == AggregationPeriod.THIRTY_MIN then "30m"
else
if period == AggregationPeriod.TWENTY_MIN then "20m"
else
if period == AggregationPeriod.FIFTEEN_MIN then "15m"
else
if period == AggregationPeriod.TEN_MIN then "10m"
else
if period == AggregationPeriod.FIVE_MIN then "5m"
else
if period == AggregationPeriod.FOUR_MIN then "4m"
else
if period == AggregationPeriod.THREE_MIN then "3m"
else
if period == AggregationPeriod.TWO_MIN then "2m"
else
if period == AggregationPeriod.MIN then "1m"
else ""), if s1 == 1 then GlobalColor("Long") else if s1 == -1 then GlobalColor("Short") else GlobalColor("Neutral"));
AddLabel(!IsNaN(h1) and h1 != 0, If h1 == 1 then "B" else if h1 == -1 then "S" else "-", if h1 == 1 then GlobalColor("arrow Buy") else if h1 == -1 then GlobalColor("arrow Sell") else color.gray);
```