Declare Lower;
input powerFactor = 1.5; # Power factor for scaling
input secondarySmoothLength = 3; # Length for secondary smoothing of the RSI
# GLOBAL DEFINITIONS
DefineGlobalColor("TrendUp", Color.Cyan);
DefineGlobalColor("TrendDown", Color.Magenta);
DefineGlobalColor("TrendUp2", Color.Blue);
DefineGlobalColor("TrendDown2", Color.Red);
input DotSize = 2;
INPUT APC = 0;
def rsiA = RSI(3); def maRsiA = MovingAverage(averagetype.HULL,rsiA, 3);
def rsiB = RSI(6); def maRsiB = MovingAverage(averagetype.HULL,rsiB, 6);
def rsiC = RSI(9); def maRsiC = MovingAverage(averagetype.HULL,rsiC, 9);
def rsiD = RSI(12); def maRsiD = MovingAverage(averagetype.HULL,rsiD, 12);
def rsiE = RSI(15); def maRsiE = MovingAverage(averagetype.HULL,rsiE, 15);
def rsiF = RSI(18); def maRsiF = MovingAverage(averagetype.HULL,rsiF, 18);
def rsiG = RSI(21); def maRsiG = MovingAverage(averagetype.HULL,rsiG, 21);
def rsiH = RSI(24); def maRsiH = MovingAverage(averagetype.HULL,rsiH, 24);
def rsiI = RSI(27); def maRsiI = MovingAverage(averagetype.HULL,rsiI, 27);
def rsiJ = RSI(30); def maRsiJ = MovingAverage(averagetype.HULL,rsiJ, 30);
def rawNormalizedRsiA = rsiA - maRsiA;
def rawNormalizedRsiB = rsiB - maRsiB;
def rawNormalizedRsiC = rsiC - maRsiC;
def rawNormalizedRsiD = rsiD - maRsiD;
def rawNormalizedRsiE = rsiE - maRsiE;
def rawNormalizedRsiF = rsiF - maRsiF;
def rawNormalizedRsiG = rsiG - maRsiG;
def rawNormalizedRsiH = rsiH - maRsiH;
def rawNormalizedRsiI = rsiI - maRsiI;
def rawNormalizedRsiJ = rsiJ - maRsiJ;
def maxNormalizedRsiA = HighestAll(rawNormalizedRsiA);
def minNormalizedRsiA = LowestAll(rawNormalizedRsiA);
def maxNormalizedRsiB = HighestAll(rawNormalizedRsiB);
def minNormalizedRsiB = LowestAll(rawNormalizedRsiB);
def maxNormalizedRsiC = HighestAll(rawNormalizedRsiC);
def minNormalizedRsiC = LowestAll(rawNormalizedRsiC);
def maxNormalizedRsiD = HighestAll(rawNormalizedRsiD);
def minNormalizedRsiD = LowestAll(rawNormalizedRsiD);
def maxNormalizedRsiE = HighestAll(rawNormalizedRsiE);
def minNormalizedRsiE = LowestAll(rawNormalizedRsiE);
def maxNormalizedRsiF = HighestAll(rawNormalizedRsiF);
def minNormalizedRsiF = LowestAll(rawNormalizedRsiF);
def maxNormalizedRsiG = HighestAll(rawNormalizedRsiG);
def minNormalizedRsiG = LowestAll(rawNormalizedRsiG);
def maxNormalizedRsiH = HighestAll(rawNormalizedRsiH);
def minNormalizedRsiH = LowestAll(rawNormalizedRsiH);
def maxNormalizedRsiI = HighestAll(rawNormalizedRsiI);
def minNormalizedRsiI = LowestAll(rawNormalizedRsiI);
def maxNormalizedRsiJ = HighestAll(rawNormalizedRsiJ);
def minNormalizedRsiJ = LowestAll(rawNormalizedRsiJ);
def maxAbsNormalizedRsiA = Max(AbsValue(maxNormalizedRsiA), AbsValue(minNormalizedRsiA));
def maxAbsNormalizedRsiB = Max(AbsValue(maxNormalizedRsiB), AbsValue(minNormalizedRsiB));
def maxAbsNormalizedRsiC = Max(AbsValue(maxNormalizedRsiC), AbsValue(minNormalizedRsiC));
def maxAbsNormalizedRsiD = Max(AbsValue(maxNormalizedRsiD), AbsValue(minNormalizedRsiD));
def maxAbsNormalizedRsiE = Max(AbsValue(maxNormalizedRsiE), AbsValue(minNormalizedRsiE));
def maxAbsNormalizedRsiF = Max(AbsValue(maxNormalizedRsiF), AbsValue(minNormalizedRsiF));
def maxAbsNormalizedRsiG = Max(AbsValue(maxNormalizedRsiG), AbsValue(minNormalizedRsiG));
def maxAbsNormalizedRsiH = Max(AbsValue(maxNormalizedRsiH), AbsValue(minNormalizedRsiH));
def maxAbsNormalizedRsiI = Max(AbsValue(maxNormalizedRsiI), AbsValue(minNormalizedRsiI));
def maxAbsNormalizedRsiJ = Max(AbsValue(maxNormalizedRsiJ), AbsValue(minNormalizedRsiJ));
def normalizationRangeA = maxAbsNormalizedRsiA * 1.2;
def normalizationRangeB = maxAbsNormalizedRsiB * 1.2;
def normalizationRangeC = maxAbsNormalizedRsiC * 1.2;
def normalizationRangeD = maxAbsNormalizedRsiD * 1.2;
def normalizationRangeE = maxAbsNormalizedRsiE * 1.2;
def normalizationRangeF = maxAbsNormalizedRsiF * 1.2;
def normalizationRangeG = maxAbsNormalizedRsiG * 1.2;
def normalizationRangeH = maxAbsNormalizedRsiH * 1.2;
def normalizationRangeI = maxAbsNormalizedRsiI * 1.2;
def normalizationRangeJ = maxAbsNormalizedRsiJ * 1.2;
def normalizedRsiA = (rawNormalizedRsiA / normalizationRangeA) * 100;
def normalizedRsiB = (rawNormalizedRsiB / normalizationRangeB) * 100;
def normalizedRsiC = (rawNormalizedRsiC / normalizationRangeC) * 100;
def normalizedRsiD = (rawNormalizedRsiD / normalizationRangeD) * 100;
def normalizedRsiE = (rawNormalizedRsiE / normalizationRangeE) * 100;
def normalizedRsiF = (rawNormalizedRsiF / normalizationRangeF) * 100;
def normalizedRsiG = (rawNormalizedRsiG / normalizationRangeG) * 100;
def normalizedRsiH = (rawNormalizedRsiH / normalizationRangeH) * 100;
def normalizedRsiI = (rawNormalizedRsiI / normalizationRangeI) * 100;
def normalizedRsiJ = (rawNormalizedRsiJ / normalizationRangeJ) * 100;
def validNormalizedRsiA = if normalizationRangeA != 0 then normalizedRsiA else 0;
def validNormalizedRsiB = if normalizationRangeB != 0 then normalizedRsiB else 0;
def validNormalizedRsiC = if normalizationRangeC != 0 then normalizedRsiC else 0;
def validNormalizedRsiD = if normalizationRangeD != 0 then normalizedRsiD else 0;
def validNormalizedRsiE = if normalizationRangeE != 0 then normalizedRsiE else 0;
def validNormalizedRsiF = if normalizationRangeF != 0 then normalizedRsiF else 0;
def validNormalizedRsiG = if normalizationRangeG != 0 then normalizedRsiG else 0;
def validNormalizedRsiH = if normalizationRangeH != 0 then normalizedRsiH else 0;
def validNormalizedRsiI = if normalizationRangeI != 0 then normalizedRsiI else 0;
def validNormalizedRsiJ = if normalizationRangeJ != 0 then normalizedRsiJ else 0;
def adjustedPowerFactor = if powerFactor != 0 then 1 / powerFactor else 1;
def powerNormalizedRsiA = Power(AbsValue(validNormalizedRsiA), adjustedPowerFactor) * Sign(validNormalizedRsiA);
def powerNormalizedRsiB = Power(AbsValue(validNormalizedRsiB), adjustedPowerFactor) * Sign(validNormalizedRsiB);
def powerNormalizedRsiC = Power(AbsValue(validNormalizedRsiC), adjustedPowerFactor) * Sign(validNormalizedRsiC);
def powerNormalizedRsiD = Power(AbsValue(validNormalizedRsiD), adjustedPowerFactor) * Sign(validNormalizedRsiD);
def powerNormalizedRsiE = Power(AbsValue(validNormalizedRsiE), adjustedPowerFactor) * Sign(validNormalizedRsiE);
def powerNormalizedRsiF = Power(AbsValue(validNormalizedRsiF), adjustedPowerFactor) * Sign(validNormalizedRsiF);
def powerNormalizedRsiG = Power(AbsValue(validNormalizedRsiG), adjustedPowerFactor) * Sign(validNormalizedRsiG);
def powerNormalizedRsiH = Power(AbsValue(validNormalizedRsiH), adjustedPowerFactor) * Sign(validNormalizedRsiH);
def powerNormalizedRsiI = Power(AbsValue(validNormalizedRsiI), adjustedPowerFactor) * Sign(validNormalizedRsiI);
def powerNormalizedRsiJ = Power(AbsValue(validNormalizedRsiJ), adjustedPowerFactor) * Sign(validNormalizedRsiJ);
def maxTransformedValue = Power(100, adjustedPowerFactor);
def scaledPowerNormalizedRsiA = powerNormalizedRsiA * (100 / maxTransformedValue);
def scaledPowerNormalizedRsiB = powerNormalizedRsiB * (100 / maxTransformedValue);
def scaledPowerNormalizedRsiC = powerNormalizedRsiC * (100 / maxTransformedValue);
def scaledPowerNormalizedRsiD = powerNormalizedRsiD * (100 / maxTransformedValue);
def scaledPowerNormalizedRsiE = powerNormalizedRsiE * (100 / maxTransformedValue);
def scaledPowerNormalizedRsiF = powerNormalizedRsiF * (100 / maxTransformedValue);
def scaledPowerNormalizedRsiG = powerNormalizedRsiG * (100 / maxTransformedValue);
def scaledPowerNormalizedRsiH = powerNormalizedRsiH * (100 / maxTransformedValue);
def scaledPowerNormalizedRsiI = powerNormalizedRsiI * (100 / maxTransformedValue);
def scaledPowerNormalizedRsiJ = powerNormalizedRsiJ * (100 / maxTransformedValue);
def smoothedPowerNormalizedRsiA = MovingAverage(AverageType.hull, scaledPowerNormalizedRsiA, secondarySmoothLength);
def smoothedPowerNormalizedRsiB = MovingAverage(AverageType.hull, scaledPowerNormalizedRsiB, secondarySmoothLength);
def smoothedPowerNormalizedRsiC = MovingAverage(AverageType.hull, scaledPowerNormalizedRsiC, secondarySmoothLength);
def smoothedPowerNormalizedRsiD = MovingAverage(AverageType.hull, scaledPowerNormalizedRsiD, secondarySmoothLength);
def smoothedPowerNormalizedRsiE = MovingAverage(AverageType.hull, scaledPowerNormalizedRsiE, secondarySmoothLength);
def smoothedPowerNormalizedRsiF = MovingAverage(AverageType.hull, scaledPowerNormalizedRsiF, secondarySmoothLength);
def smoothedPowerNormalizedRsiG = MovingAverage(AverageType.hull, scaledPowerNormalizedRsiG, secondarySmoothLength);
def smoothedPowerNormalizedRsiH = MovingAverage(AverageType.hull, scaledPowerNormalizedRsiH, secondarySmoothLength);
def smoothedPowerNormalizedRsiI = MovingAverage(AverageType.hull, scaledPowerNormalizedRsiI, secondarySmoothLength);
def smoothedPowerNormalizedRsiJ = MovingAverage(AverageType.hull, scaledPowerNormalizedRsiJ, secondarySmoothLength);
plot R1_Dot = if IsNaN(close) then Double.NaN else 1;
R1_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R1_Dot.SetLineWeight(DotSize);
R1_Dot.AssignValueColor(if smoothedPowerNormalizedRsiA < 0 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
R1_Dot.HideBubble();
plot R2_Dot = if IsNaN(close) then Double.NaN else 2;
R2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R2_Dot.SetLineWeight(DotSize);
R2_Dot.AssignValueColor(if smoothedPowerNormalizedRsiB < 0 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
R2_Dot.HideBubble();
plot R3_Dot = if IsNaN(close) then Double.NaN else 3;
R3_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R3_Dot.SetLineWeight(DotSize);
R3_Dot.AssignValueColor(if smoothedPowerNormalizedRsiC < 0 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
R3_Dot.HideBubble();
plot R4_Dot = if IsNaN(close) then Double.NaN else 4;
R4_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R4_Dot.SetLineWeight(DotSize);
R4_Dot.AssignValueColor(if smoothedPowerNormalizedRsiD < 0 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
R4_Dot.HideBubble();
plot R5_Dot = if IsNaN(close) then Double.NaN else 5;
R5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R5_Dot.SetLineWeight(DotSize);
R5_Dot.AssignValueColor(if smoothedPowerNormalizedRsiE < 0 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
R5_Dot.HideBubble();
plot R6_Dot = if IsNaN(close) then Double.NaN else 6;
R6_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R6_Dot.SetLineWeight(DotSize);
R6_Dot.AssignValueColor(if smoothedPowerNormalizedRsiF < 0 then GlobalColor("TrendDown2") else GlobalColor("TrendUp2"));
R6_Dot.HideBubble();
plot R7_Dot = if IsNaN(close) then Double.NaN else 7;
R7_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R7_Dot.SetLineWeight(DotSize);
R7_Dot.AssignValueColor(if smoothedPowerNormalizedRsiG < 0 then GlobalColor("TrendDown2") else GlobalColor("TrendUp2"));
R7_Dot.HideBubble();
plot R8_Dot = if IsNaN(close) then Double.NaN else 8;
R8_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R8_Dot.SetLineWeight(DotSize);
R8_Dot.AssignValueColor(if smoothedPowerNormalizedRsiH < 0 then GlobalColor("TrendDown2") else GlobalColor("TrendUp2"));
R8_Dot.HideBubble();
plot R9_Dot = if IsNaN(close) then Double.NaN else 9;
R9_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R9_Dot.SetLineWeight(DotSize);
R9_Dot.AssignValueColor(if smoothedPowerNormalizedRsiI < 0 then GlobalColor("TrendDown2") else GlobalColor("TrendUp2"));
R9_Dot.HideBubble();
plot R10_Dot = if IsNaN(close) then Double.NaN else 10;
R10_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R10_Dot.SetLineWeight(DotSize);
R10_Dot.AssignValueColor(if smoothedPowerNormalizedRsiJ < 0 then GlobalColor("TrendDown2") else GlobalColor("TrendUp2"));
R10_Dot.HideBubble();
#assignPriceColor
assignPriceColor( if apc == 1 then if smoothedPowerNormalizedRsiA < 0 then GlobalColor("TrendDown") else GlobalColor("TrendUp") else
if apc == 2 then if smoothedPowerNormalizedRsiB < 0 then GlobalColor("TrendDown") else GlobalColor("TrendUp") else
if apc == 3 then if smoothedPowerNormalizedRsiC < 0 then GlobalColor("TrendDown") else GlobalColor("TrendUp") else
if apc == 4 then if smoothedPowerNormalizedRsiD < 0 then GlobalColor("TrendDown") else GlobalColor("TrendUp") else
if apc == 5 then if smoothedPowerNormalizedRsiE < 0 then GlobalColor("TrendDown") else GlobalColor("TrendUp") else
if apc == 6 then if smoothedPowerNormalizedRsiF < 0 then GlobalColor("TrendDown2") else GlobalColor("TrendUp2") else
if APC == 7 THEN IF smoothedPowerNormalizedRsiG < 0 then GlobalColor("TrendDown2") else GlobalColor("TrendUp2") else
if APC == 8 THEN IF smoothedPowerNormalizedRsiH < 0 then GlobalColor("TrendDown2") else GlobalColor("TrendUp2") else
if APC == 9 THEN IF smoothedPowerNormalizedRsiI < 0 then GlobalColor("TrendDown2") else GlobalColor("TrendUp2") else
if APC == 10 THEN IF smoothedPowerNormalizedRsiJ < 0 then GlobalColor("TrendDown2") else GlobalColor("TrendUp2") else Color.current);