Mightymorphinchris
Active member
I wanted to create an upgraded version of the Colored Candles RSI study (Original).
Recent Updates:
10/12/2021 - Corrected else if statement for painting bars with "Single" timeSpan input selected so that it doesn't matter if the rsiPaintType is set to Simple or Weighted.
Overview:
The study has multiple modes as such:
time span: Single/Multi - Single time frame (the one your chart is set to) or Multiple time frames (5 additional time frames that are greater than the one your chart is set to).
rsi paint type: Simple/Weighted - Only matters if time span is set to Multi and if so, it will either weight all time frames the same or the greater time frames will have an exponential weight
time mode: Normal/Shorter - Some of the shorter time frames (like 1m) have shorter options for the greater time frames (ex. Shorter: 1m/2m/4m/5m/10m/15m or Normal: 1m/2m/4m/5m/15m/20m)
Code:
Share Link:
http://tos.mx/z17RBQ8
Screenshot:
Recent Updates:
10/12/2021 - Corrected else if statement for painting bars with "Single" timeSpan input selected so that it doesn't matter if the rsiPaintType is set to Simple or Weighted.
Overview:
The study has multiple modes as such:
time span: Single/Multi - Single time frame (the one your chart is set to) or Multiple time frames (5 additional time frames that are greater than the one your chart is set to).
rsi paint type: Simple/Weighted - Only matters if time span is set to Multi and if so, it will either weight all time frames the same or the greater time frames will have an exponential weight
time mode: Normal/Shorter - Some of the shorter time frames (like 1m) have shorter options for the greater time frames (ex. Shorter: 1m/2m/4m/5m/10m/15m or Normal: 1m/2m/4m/5m/15m/20m)
Code:
Ruby:
################################################################
########## Input #########
################################################################
input paintBars = {OFF, default ON};
input timeSpan = {Single, default Multi};
input rsiPaintType = {Simple, default Weighted};
input timeMode = { "Shorter", default "Normal"};
# RSI
input rsiLength = 16;
input rsiAverageType = AverageType.WILDERS;
################################################################
########## TIME #########
################################################################
def timeFrame = GetAggregationPeriod();
def lowestAggregation;
def middleAggregation;
def highestAggregation;
def extraHighAggregation;
def xxlAggregation;
def xxxlAggregation;
if timeFrame == AggregationPeriod.MIN and timeMode == timeMode.Shorter {
lowestAggregation = AggregationPeriod.MIN;
middleAggregation = AggregationPeriod.TWO_MIN;
highestAggregation = AggregationPeriod.FOUR_MIN;
extraHighAggregation = AggregationPeriod.FIVE_MIN;
xxlAggregation = AggregationPeriod.TEN_MIN;
xxxlAggregation = AggregationPeriod.FIFTEEN_MIN;
} else if timeFrame == AggregationPeriod.MIN {
lowestAggregation = AggregationPeriod.MIN;
middleAggregation = AggregationPeriod.TWO_MIN;
highestAggregation = AggregationPeriod.FOUR_MIN;
extraHighAggregation = AggregationPeriod.FIVE_MIN;
xxlAggregation = AggregationPeriod.FIFTEEN_MIN;
xxxlAggregation = AggregationPeriod.TWENTY_MIN;
} else if timeFrame == AggregationPeriod.TWO_MIN and timeMode == timeMode.Shorter {
lowestAggregation = AggregationPeriod.TWO_MIN;
middleAggregation = AggregationPeriod.FOUR_MIN;
highestAggregation = AggregationPeriod.FIVE_MIN;
extraHighAggregation = AggregationPeriod.TEN_MIN;
xxlAggregation = AggregationPeriod.FIFTEEN_MIN;
xxxlAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.TWO_MIN and timeMode == timeMode.Shorter {
lowestAggregation = AggregationPeriod.TWO_MIN;
middleAggregation = AggregationPeriod.FOUR_MIN;
highestAggregation = AggregationPeriod.FIVE_MIN;
extraHighAggregation = AggregationPeriod.TEN_MIN;
xxlAggregation = AggregationPeriod.FIFTEEN_MIN;
xxxlAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.TWO_MIN {
lowestAggregation = AggregationPeriod.TWO_MIN;
middleAggregation = AggregationPeriod.FIVE_MIN;
highestAggregation = AggregationPeriod.TEN_MIN;
extraHighAggregation = AggregationPeriod.FIFTEEN_MIN;
xxlAggregation = AggregationPeriod.THIRTY_MIN;
xxxlAggregation = AggregationPeriod.HOUR;
} else if timeFrame == AggregationPeriod.THREE_MIN and timeMode == timeMode.Shorter {
lowestAggregation = AggregationPeriod.THREE_MIN;
middleAggregation = AggregationPeriod.FOUR_MIN;
highestAggregation = AggregationPeriod.FIVE_MIN;
extraHighAggregation = AggregationPeriod.TEN_MIN;
xxlAggregation = AggregationPeriod.FIFTEEN_MIN;
xxxlAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.THREE_MIN {
lowestAggregation = AggregationPeriod.THREE_MIN;
middleAggregation = AggregationPeriod.FIVE_MIN;
highestAggregation = AggregationPeriod.TEN_MIN;
extraHighAggregation = AggregationPeriod.FIFTEEN_MIN;
xxlAggregation = AggregationPeriod.THIRTY_MIN;
xxxlAggregation = AggregationPeriod.HOUR;
} else if timeFrame == AggregationPeriod.FOUR_MIN and timeMode == timeMode.Shorter {
lowestAggregation = AggregationPeriod.FOUR_MIN;
middleAggregation = AggregationPeriod.FIVE_MIN;
highestAggregation = AggregationPeriod.TEN_MIN;
extraHighAggregation = AggregationPeriod.FIFTEEN_MIN;
xxlAggregation = AggregationPeriod.TWENTY_MIN;
xxxlAggregation = AggregationPeriod.THIRTY_MIN;
} else if timeFrame == AggregationPeriod.FOUR_MIN {
lowestAggregation = AggregationPeriod.FOUR_MIN;
middleAggregation = AggregationPeriod.FIVE_MIN;
highestAggregation = AggregationPeriod.TEN_MIN;
extraHighAggregation = AggregationPeriod.FIFTEEN_MIN;
xxlAggregation = AggregationPeriod.THIRTY_MIN;
xxxlAggregation = AggregationPeriod.HOUR;
} else if timeFrame == AggregationPeriod.FIVE_MIN {
lowestAggregation = AggregationPeriod.FIVE_MIN;
middleAggregation = AggregationPeriod.TEN_MIN;
highestAggregation = AggregationPeriod.FIFTEEN_MIN;
extraHighAggregation = AggregationPeriod.THIRTY_MIN;
xxlAggregation = AggregationPeriod.HOUR;
xxxlAggregation = AggregationPeriod.TWO_HOURS;
} else if timeFrame == AggregationPeriod.TEN_MIN {
lowestAggregation = AggregationPeriod.TEN_MIN;
middleAggregation = AggregationPeriod.FIFTEEN_MIN;
highestAggregation = AggregationPeriod.THIRTY_MIN;
extraHighAggregation = AggregationPeriod.HOUR;
xxlAggregation = AggregationPeriod.TWO_HOURS;
xxxlAggregation = AggregationPeriod.FOUR_HOURS;
} else if timeFrame == AggregationPeriod.FIFTEEN_MIN {
lowestAggregation = AggregationPeriod.FIFTEEN_MIN;
middleAggregation = AggregationPeriod.THIRTY_MIN;
highestAggregation = AggregationPeriod.HOUR;
extraHighAggregation = AggregationPeriod.TWO_HOURS;
xxlAggregation = AggregationPeriod.FOUR_HOURS;
xxxlAggregation = AggregationPeriod.DAY;
} else if timeFrame == AggregationPeriod.THIRTY_MIN {
lowestAggregation = AggregationPeriod.THIRTY_MIN;
middleAggregation = AggregationPeriod.HOUR;
highestAggregation = AggregationPeriod.TWO_HOURS;
extraHighAggregation = AggregationPeriod.FOUR_HOURS;
xxlAggregation = AggregationPeriod.DAY;
xxxlAggregation = AggregationPeriod.TWO_DAYS;
} else if timeFrame == AggregationPeriod.HOUR {
lowestAggregation = AggregationPeriod.HOUR;
middleAggregation = AggregationPeriod.TWO_HOURS;
highestAggregation = AggregationPeriod.FOUR_HOURS;
extraHighAggregation = AggregationPeriod.DAY;
xxlAggregation = AggregationPeriod.TWO_DAYS;
xxxlAggregation = AggregationPeriod.FOUR_DAYS;
} else if timeFrame == AggregationPeriod.TWO_HOURS {
lowestAggregation = AggregationPeriod.TWO_HOURS;
middleAggregation = AggregationPeriod.FOUR_HOURS;
highestAggregation = AggregationPeriod.DAY;
extraHighAggregation = AggregationPeriod.TWO_DAYS;
xxlAggregation = AggregationPeriod.FOUR_DAYS;
xxxlAggregation = AggregationPeriod.WEEK;
} else if timeFrame == AggregationPeriod.FOUR_HOURS {
lowestAggregation = AggregationPeriod.FOUR_HOURS;
middleAggregation = AggregationPeriod.DAY;
highestAggregation = AggregationPeriod.TWO_DAYS;
extraHighAggregation = AggregationPeriod.FOUR_DAYS;
xxlAggregation = AggregationPeriod.WEEK;
xxxlAggregation = AggregationPeriod.MONTH;
} else if timeFrame == AggregationPeriod.DAY {
lowestAggregation = AggregationPeriod.DAY;
middleAggregation = AggregationPeriod.TWO_DAYS;
highestAggregation = AggregationPeriod.FOUR_DAYS;
extraHighAggregation = AggregationPeriod.WEEK;
xxlAggregation = AggregationPeriod.MONTH;
xxxlAggregation = AggregationPeriod.QUARTER;
} else {
lowestAggregation = AggregationPeriod.TWO_DAYS;
middleAggregation = AggregationPeriod.FOUR_DAYS;
highestAggregation = AggregationPeriod.WEEK;
extraHighAggregation = AggregationPeriod.MONTH;
xxlAggregation = AggregationPeriod.QUARTER;
xxxlAggregation = AggregationPeriod.YEAR;
}
################################################################
########## Calc #########
################################################################
# Low
def rsiClose = close;
def NetChgAvg = MovingAverage(rsiAverageType, rsiClose - rsiClose[1], rsiLength);
def TotChgAvg = MovingAverage(rsiAverageType, AbsValue(rsiClose - rsiClose[1]), rsiLength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
# Middle
def rsiClose_m = close(period = middleAggregation);
def NetChgAvg_m = MovingAverage(rsiAverageType, rsiClose_m - rsiClose_m[1], rsiLength);
def TotChgAvg_m = MovingAverage(rsiAverageType, AbsValue(rsiClose_m - rsiClose_m[1]), rsiLength);
def ChgRatio_m = if TotChgAvg_m != 0 then NetChgAvg_m / TotChgAvg_m else 0;
def RSI_m = 50 * (ChgRatio_m + 1);
# High
def rsiClose_h = close(period = highestAggregation);
def NetChgAvg_h = MovingAverage(rsiAverageType, rsiClose_h - rsiClose_h[1], rsiLength);
def TotChgAvg_h = MovingAverage(rsiAverageType, AbsValue(rsiClose_h - rsiClose_h[1]), rsiLength);
def ChgRatio_h = if TotChgAvg_h != 0 then NetChgAvg_h / TotChgAvg_h else 0;
def RSI_h = 50 * (ChgRatio_h + 1);
# Extra High
def rsiClose_xh = close(period = extraHighAggregation);
def NetChgAvg_xh = MovingAverage(rsiAverageType, rsiClose_xh - rsiClose_xh[1], rsiLength);
def TotChgAvg_xh = MovingAverage(rsiAverageType, AbsValue(rsiClose_xh - rsiClose_xh[1]), rsiLength);
def ChgRatio_xh = if TotChgAvg_xh != 0 then NetChgAvg_xh / TotChgAvg_xh else 0;
def RSI_xh = 50 * (ChgRatio_xh + 1);
# XXL
def rsiClose_xxl = close(period = xxlAggregation);
def NetChgAvg_xxl = MovingAverage(rsiAverageType, rsiClose_xxl - rsiClose_xxl[1], rsiLength);
def TotChgAvg_xxl = MovingAverage(rsiAverageType, AbsValue(rsiClose_xxl - rsiClose_xxl[1]), rsiLength);
def ChgRatio_xxl = if TotChgAvg_xxl != 0 then NetChgAvg_xxl / TotChgAvg_xxl else 0;
def RSI_xxl = 50 * (ChgRatio_xxl + 1);
# XXXL
def rsiClose_xxxl = close(period = xxxlAggregation);
def NetChgAvg_xxxl = MovingAverage(rsiAverageType, rsiClose_xxxl - rsiClose_xxxl[1], rsiLength);
def TotChgAvg_xxxl = MovingAverage(rsiAverageType, AbsValue(rsiClose_xxxl - rsiClose_xxxl[1]), rsiLength);
def ChgRatio_xxxl = if TotChgAvg_xxxl != 0 then NetChgAvg_xxxl / TotChgAvg_xxxl else 0;
def RSI_xxxl = 50 * (ChgRatio_xxxl + 1);
# Sum Total
def RSITotal;
if RSIPaintType == RSIPaintType.Weighted {
RSITotal = RSI + (RSI_m * 2) + (RSI_h * 4) + (RSI_xh * 8) + (RSI_xxl * 16) + (RSI_xxxl * 32);
} else {
RSITotal = RSI + RSI_m + RSI_h + RSI_xh + RSI_xxl + RSI_xxxl;
}
AssignPriceColor(if !paintBars then Color.CURRENT
else if RSIPaintType == RSIPaintType.Weighted and timeSpan == timeSpan.Multi then
if RSITotal < 1750 then
CreateColor(0, 0, 255)
else if RSITotal > 1750 and RSITotal < 2500 then
CreateColor(0, 255, 255)
else if RSITotal > 2500 and RSITotal < 3250 then
CreateColor(0, 255, 0)
else if RSITotal > 3250 and RSITotal < 4000 then
CreateColor(255, 255, 0)
else if RSITotal > 4000 and RSITotal < 4750 then
CreateColor(255, 128, 0)
else
CreateColor(255, 0, 0)
else if RSIPaintType == RSIPaintType.Simple and timeSpan == timeSpan.Multi then
if RSITotal < 175 then
CreateColor(0, 0, 255)
else if RSITotal > 175 and RSITotal < 250 then
CreateColor(0, 255, 255)
else if RSITotal > 250 and RSITotal < 325 then
CreateColor(0, 255, 0)
else if RSITotal > 325 and RSITotal < 400 then
CreateColor(255, 255, 0)
else if RSITotal > 400 and RSITotal < 475 then
CreateColor(255, 153, 51)
else
CreateColor(255, 0, 0)
else if (RSIPaintType == RSIPaintType.Simple or RSIPaintType == RSIPaintType.Weighted) and timeSpan == timeSpan.Single then
if RSI < 25 then
CreateColor(0, 0, 255)
else if RSI > 25 and RSI < 35 then
CreateColor(0, 255, 255)
else if RSI > 35 and RSI < 50 then
CreateColor(0, 255, 0)
else if RSI > 50 and RSI < 65 then
CreateColor(255, 255, 0)
else if RSI > 65 and RSI < 75 then
CreateColor(255, 153, 51)
else
CreateColor(255, 0, 0)
else Color.GRAY);
Share Link:
http://tos.mx/z17RBQ8
Screenshot:
Last edited: