thinkScript

declare upper; 

 

#Inputs:  

input nFE = 8;#hint nFE: length for Fractal Energy calculation. Mobius default is 8 

input Glength  = 13;#hint Glength: length for Gaussian Price Filter. Mobius default is 13 

input betaDev =  4;#hint BetaDev: length for ???. Mobius default is 4 

input RSI_BullTrigger = 0.1; ## 10.13.2018 JQ added this input 

input RSI_BearTrigger = 0.9; ## 10.13.2018 JQ added this inpur 

input GaussianLinearity = 0.382; #hint GaussianLinearity: Default 0.382 

input GaussianNonLinearity = .612; #hint GaussianNonLinearity: Default 0.612 

input data = close; 

input AlertOn = no; 

 

 

def w = (2 * Double.Pi / Glength); 

def beta = (1 – Cos(w)) / (Power(1.414, 2.0 / betaDev) – 1 ); 

def alpha = (-beta + Sqrt(beta * beta + 2 * beta)); 

def Go = Power(alpha, 4) * open +  

             4 * (1 – alpha) * Go[1] – 6 * Power( 1 – alpha, 2 ) * Go[2] +  

             4 * Power( 1 – alpha, 3 ) * Go[3] – Power( 1 – alpha, 4 ) * Go[4]; 

def Gh = Power(alpha, 4) * high +  

             4 * (1 – alpha) * Gh[1] – 6 * Power( 1 – alpha, 2 ) * Gh[2] +  

             4 * Power( 1 – alpha, 3 ) * Gh[3] – Power( 1 – alpha, 4 ) * Gh[4]; 

def Gl = Power(alpha, 4) * low +  

             4 * (1 – alpha) * Gl[1] – 6 * Power( 1 – alpha, 2 ) * Gl[2] +  

             4 * Power( 1 – alpha, 3 ) * Gl[3] – Power( 1 – alpha, 4 ) * Gl[4]; 

def Gc = Power(alpha, 4) * data +  

             4 * (1 – alpha) * Gc[1] – 6 * Power( 1 – alpha, 2 ) * Gc[2] +  

             4 * Power( 1 – alpha, 3 ) * Gc[3] – Power( 1 – alpha, 4 ) * Gc[4]; 

# 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; 

def RSI; 

#plot OS; 

#plot OB; 

#plot M; 

 

# Calculations 

o = (Go + Gc[1]) / 2; 

h = Max(Gh, Gc[1]); 

l = Min(Gl, Gc[1]); 

c = (o + h + l + Gc) / 4; 

def gamma = Log(Sum((Max(Gh, Gc[1]) – Min(Gl, Gc[1])), nFE) /  

        (Highest(gh, nFE) – Lowest(Gl, nFE))) 

            / Log(nFE); 

#gamma.SetDefaultColor(Color.Yellow); 

L0 = (1 – gamma) * Gc + 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; 

} 

 

    # Plot RSI 

RSI = if CU + CD <> 0 then CU / (CU + CD) else 0; 

 

Alert(AlertOn and RSI crosses below RSI_BearTrigger, “”, Alert.BAR, Sound.Bell);  # 10.13.2018 JQ swapped RSI_BearTrigger for 0.9 

Alert(AlertOn and RSI crosses above RSI_BullTrigger, “”, Alert.BAR, Sound.Bell);   # 10.132018 JQ swapped RSI_BullTrigger for 0.1 

 

    # Spaced arrow plots 

 

def Y_axisRange = highestall(high) – lowestall(low); 

#addlabel(1,”Y axis range: ” + y_axisRange, color.LIME); 

input AlertLineSpacer = .3; #hint AlertLineSpacer: paint line ? percent lower than Lowest Low 

 

Plot BullArrowLine = LowestAll(low) – (y_axisRange/100); 

BullArrowLine.hide(); 

plot CenterLine = BullArrowLine – (5.5 * y_axisRange/100); 

CenterLine.hide(); 

plot BearArrowLine = CenterLine – (5.5 * y_axisRange/100); 

BearArrowLine.hide(); 

plot BubbleLine = CenterLine – (4.5 * y_axisRange/100); 

BubbleLine.hide(); 

 

addchartbubble( barnumber() == 1, BubbleLine ,”G-RSI-L nFE:” + nfe + ” Glength:” +  Glength + ” BetaDev:” + BetaDev + ” “,Color.WHITE,yes); 

 

plot RSIBullArrow = if RSI crosses above rsi_bullTrigger then BullArrowLine else double.NaN; 

RSIBullArrow.setPaintingStrategy(PaintingStrategy.ARROW_UP); 

RSIBullArrow.setDefaultColor(color.GREEN); 

RSIBullArrow.setlineWeight(5); 

 

plot RSIBull2 = if RSI >=rsi_bullTrigger and rsi >= rsi[1] and rsi[1] >= rsi[2] then Centerline else double.NaN; 

RSIBull2.setPaintingStrategy(PaintingStrategy.SQUARES); 

RSIBull2.assignValueColor(RSIBUllArrow.takevaluecolor()); 

RSIBull2.setlineWeight(3); 

 

plot RSIBearArrow = if RSI crosses below rsi_bearTrigger then BearArrowLine else double.NaN; 

RSIBearArrow.setPaintingStrategy(PaintingStrategy.ARROW_DOWN); 

RSIBearArrow.setDefaultColor(color.RED); 

RSIBearArrow.setlineWeight(5); 

 

plot BearLine2 = if RSI <= RSI_bearTrigger and rsi <= Rsi[1] and rsi[1] <= rsi[2]  

then Centerline else double.NaN; 

BearLine2.setPaintingStrategy(PaintingStrategy.SQUARES); 

BearLine2.assignValueColor(RSIBearArrow.takevaluecolor()); 

BearLine2.setlineWeight(3); 

 

 

 

 

 

##rsilowerAlertLine2.hide(); 

 

 

 

#addverticalLine(if RSI crosses above rsi_BullTrigger then RSIlowerAlertLine3 else double.NaN, “Gaussian RSI-L”, #color.LIME, stroke = Curve.FIRM); 

#addverticalLine(if RSI crosses below rsi_bearTrigger then RSIlowerAlertLine3 else double.NaN, “Gaussian RSI-L”, #color.PINK, stroke = Curve.FIRM); 

 

 

 

# End Code RSI_Laguerre Self Adjusting with Fractal Energy 

 

Leave a Reply