RSI Colored Candles Upgraded For ThinkOrSwim

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:
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:
Pe7SPBo.png
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@Mightymorphinchris
You did a great work here. I was wondering if the issues ever solved and the code is good to use? Because when I pit it on 2M chart coloring are opposite of direction! It’s red for going up and green for going down.
I love the coloring and I am hoping to have it on the chart for /ES (S&P 500 E-Mini Futures)
Thank you in advance
 
It should be updated now @SuryaKiranC @mikson

I also modified the color ranges after making the time correction. Thanks again!
Thank you for your response. Can you please check my set up and chart in the picture? Is this the way it should be on 2M chart?


I added pictures for Hull and Wilders set up. I have a filling the colors for Hull should be opposite.
I am sorry to bother you. This is a great tool and I would love tp use it.
 
Last edited by a moderator:
Thank you for your response. Can you please check my set up and chart in the picture? Is this the way it should be on 2M chart?

I added pictures for Hull and Wilders set up. I have a filling the colors for Hull should be opposite.
I am sorry to bother you. This is a great tool and I would love tp use it.
RSI works on all timeframes. The colors in this script are correct.

No one can tell you how it will work with your strategy.
Recommend you put it on your chart. Nothing beats personal experience ;) The only way you will know what works best for you is to play with the settings and see how the indicator line up w/ your strategy and with your other indicators. To determine if this indicator brings value, analyze it over different timeframes, across history and with multiple instruments.
 
RSI works on all timeframes. The colors in this script are correct.

No one can tell you how it will work with your strategy.
Recommend you put it on your chart. Nothing beats personal experience ;) The only way you will know what works best for you is to play with the settings and see how the indicator line up w/ your strategy and with your other indicators. To determine if this indicator brings value, analyze it over different timeframes, across history and with multiple instruments.
I appreciate your comment and understand your point. But my questions is more about the coding and color sequence, it's not about strategy.
 
I appreciate your comment and understand your point. But my questions is more about the coding and color sequence, it's not about strategy.
In regards to your question about the timeframe and the candle color, it's irrelevant what timeframe you're on. Remember though this is taking mtiple time frames and aggregating the RSI data. The timeframes used are dependent on the normal/shorter setting for each individual time frame and the rsi can simply be an avg of the various time frames or weighted.

In the end though, I personally like this Multi TimeFrame RSI Strategy & Indicator For ThinkOrSwim version of the code better but, as @MerryDay stated, you should test these with your personal strategy and do what works for you. If you find something that works really well, please come back amd share it with us and the community.
 
In regards to your question about the timeframe and the candle color, it's irrelevant what timeframe you're on. Remember though this is taking mtiple time frames and aggregating the RSI data. The timeframes used are dependent on the normal/shorter setting for each individual time frame and the rsi can simply be an avg of the various time frames or weighted.

In the end though, I personally like this Multi TimeFrame RSI Strategy & Indicator For ThinkOrSwim version of the code better but, as @MerryDay stated, you should test these with your personal strategy and do what works for you. If you find something that works really well, please come back amd share it with us and the community.
Thank you so much for your response and thank you very much for sharing that version. I really like it. Great work
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
346 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top