ARSI - Adaptive Relative Strength Index for ThinkorSwim

rad14733

Well-known member
VIP
I finished coding this indicator due to a conversion request from a member which reminded me that I had started working on it a while back but got distracted from it... The ARSI is an upper indicator that works like a moving average but based on RSI... It works well for scalping which is what drew my original interest... While the standard RSI uses a length of 14 it is recommended to use a shorter length for this indicator and 3 is a good length for scalping on lower timeframes...

I will be adding more details as well as more images as time allows...

Ruby:
# ARSI
#hint: Adaptive Relative Strength Index Indicator for Thinkscript
# Created by rad14733 for usethinkscript.com
# Based on Tradingview ARSI @ https://www.tradingview.com/script/tSpy2kw2-Adaptive-RSI/
# Plots a colored line on the upper chart based on trend direction.
# v1.0 : 2021-03-28 : Initial Release
# v1.1 : 2021-05-13 : Added trend indicating ARSI value chart label
# v1.2 : 2021-07-07 : Added reversal arrows - credit to @je®emy & @SleepyZ

input length = 14;
input price = close;
input averageType = AverageType.WILDERS;
input showLabel = no;
input showReversals = no;

def rsi = 2 * AbsValue(rsi(length, price, averageType) / 100 - 0.5);

def arsiData = rsi * price + (1 - rsi) * (if isNaN(arsiData[1]) then 0 else arsiData[1]);

plot arsi = arsiData;
arsi.DefineColor("UpTrend", Color.GREEN); #GREEN
arsi.DefineColor("DownTrend", Color.RED); #RED
arsi.SetLineWeight(3);
arsi.SetPaintingStrategy(PaintingStrategy.LINE);
arsi.SetStyle(Curve.FIRM);
arsi.AssignValueColor(if arsi > arsi[1] then arsi.Color("UpTrend") else arsi.Color("DownTrend"));

AddLabel(showLabel, "ARSI: " + arsi, if arsi > arsi[1] then arsi.Color("UpTrend") else arsi.Color("DownTrend"));

plot bull = arsi[2] > arsi[1] and arsi > arsi[1];
bull.SetDefaultColor(Color.GREEN);
bull.SetlineWeight(1);
bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bull.SetHiding(!showReversals);

plot bear = arsi[2] < arsi[1] and arsi < arsi[1];
bear.SetDefaultColor(Color.RED);
bear.SetLineWeight(1);
bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bear.SetHiding(!showReversals);

# END - ARSI

CL1ciE4.png
 
Last edited:

je®emy

New member
Thanks @rad14733, I like this! I tried to insert an arrow at the bar where the color flips, my code is below, but of course is places the arrows accross the entire stretch of color. What can I change in order to just have the arrow under the color flipped bar?

Code:
plot Bull = arsi > arsi[1];
plot Bear = arsi < arsi[1];
Bull.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
Bear.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
Bull.setdefaultColor(color.green);
Bear.setdefaultColor(color.red);
Bear.setlineWeight(1);
Bear.setlineWeight(1);
 

SleepyZ

Well-known member
Thanks @rad14733, I like this! I tried to insert an arrow at the bar where the color flips, my code is below, but of course is places the arrows accross the entire stretch of color. What can I change in order to just have the arrow under the color flipped bar?

Code:
plot Bull = arsi > arsi[1];
plot Bear = arsi < arsi[1];
Bull.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
Bear.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
Bull.setdefaultColor(color.green);
Bear.setdefaultColor(color.red);
Bear.setlineWeight(1);
Bear.setlineWeight(1);

Try changing the following plots

Code:
plot Bull = (arsi[2] > arsi[1]) and arsi > arsi[1];
plot Bear = (arsi[2] < arsi[1]) and arsi < arsi[1];
 

rad14733

Well-known member
VIP
@je®emy @SleepyZ You two must have been reading my mind because I've entertained adding the reversals several times recently... I have updated the code in Post #1 to include the optional reversal arrows and trend indicating ARSI value chart label.
 

je®emy

New member
@rad14733 I thought that MTF aggregations may be useful, and frankly I need the practice. This is mostly copy and paste on my part based on the MTF RSI by @horserider, with (I hope) the necessary adjustments. The code may not be as elegant as some, so feel free to polish it up if you see fit. Thank you very much for the education!

Ruby:
# ARSI
#hint: Adaptive Relative Strength Index Indicator for Thinkscript
# Created by rad14733 for usethinkscript.com
# Based on Tradingview ARSI @ https://www.tradingview.com/script/tSpy2kw2-Adaptive-RSI/
# Plots a colored line on the upper chart based on trend direction.
# v1.0 : 2021-03-28 : Initial Release
# v1.1 : 2021-05-13 : Added trend indicating ARSI value chart label
# v1.2 : 2021-07-07 : Added reversal arrows - credit to @je®emy & @SleepyZ
# v1.3 : 2021-07-08 : Added MTF Aggregations - @je®emy

input length = 14;
input price = close;
input averageType = AverageType.WILDERS;
input showLabel = no;
input showReversals = no;

def rsi = 2 * AbsValue(rsi(length, price, averageType) / 100 - 0.5);

def arsiData = rsi * price + (1 - rsi) * (if isNaN(arsiData[1]) then 0 else arsiData[1]);

plot arsi = arsiData;
arsi.DefineColor("UpTrend", Color.LIGHT_GREEN);
arsi.DefineColor("DownTrend", Color.LIGHT_RED);
arsi.SetLineWeight(1);
arsi.SetPaintingStrategy(PaintingStrategy.LINE);
arsi.SetStyle(Curve.FIRM);
arsi.AssignValueColor(if arsi > arsi[1] then arsi.Color("UpTrend") else arsi.Color("DownTrend"));

AddLabel(showLabel, "ARSI: " + arsi, if arsi > arsi[1] then arsi.Color("UpTrend") else arsi.Color("DownTrend"));

plot bull = arsi[2] > arsi[1] and arsi > arsi[1];
bull.SetDefaultColor(Color.LIGHT_GREEN);
bull.SetlineWeight(1);
bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bull.SetHiding(!showReversals);

plot bear = arsi[2] < arsi[1] and arsi < arsi[1];
bear.SetDefaultColor(Color.LIGHT_RED);
bear.SetLineWeight(1);
bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bear.SetHiding(!showReversals);

#ARSI2
input length2 = 14;
input price2 = close;
input averageType2 = AverageType.WILDERS;
input agg = AggregationPeriod.DAY;
input showLabel2 = no;
input showReversals2 = no;

def c = close(period = agg);

def rsi2 = 2 * AbsValue(rsi(length, c, averageType) / 100 - 0.5);

def arsi2Data = rsi2 * c + (1 - rsi2) * (if isNaN(arsi2Data[1]) then 0 else arsi2Data[1]);

plot arsi2 = arsi2Data;
arsi2.DefineColor("UpTrend", Color.GREEN);
arsi2.DefineColor("DownTrend", Color.RED);
arsi2.SetLineWeight(3);
arsi2.SetPaintingStrategy(PaintingStrategy.LINE);
arsi2.SetStyle(Curve.FIRM);
arsi2.AssignValueColor(if arsi2 > arsi2[1] then arsi2.Color("UpTrend") else arsi2.Color("DownTrend"));

AddLabel(showLabel, "ARSI2: " + arsi2, if arsi2 > arsi2[1] then arsi2.Color("UpTrend") else arsi2.Color("DownTrend"));

plot bull2 = arsi2[2] > arsi2[1] and arsi2 > arsi2[1];
bull2.SetDefaultColor(Color.GREEN);
bull2.SetlineWeight(3);
bull2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bull2.SetHiding(!showReversals);

plot bear2 = arsi2[2] < arsi2[1] and arsi2 < arsi2[1];
bear2.SetDefaultColor(Color.RED);
bear2.SetLineWeight(3);
bear2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bear2.SetHiding(!showReversals);

#ARSI3
input length3 = 14;
input price3 = close;
input averageType3 = AverageType.WILDERS;
input agg3 = AggregationPeriod.DAY;
input showLabel3 = no;
input showReversals3 = no;

def c3 = close(period = agg3);

def rsi3 = 2 * AbsValue(rsi(length, c3, averageType) / 100 - 0.5);

def arsi3Data = rsi3 * c3 + (1 - rsi3) * (if isNaN(arsi3Data[1]) then 0 else arsi3Data[1]);

plot arsi3 = arsi3Data;
arsi3.DefineColor("UpTrend", Color.DARK_GREEN);
arsi3.DefineColor("DownTrend", Color.DARK_RED);
arsi3.SetLineWeight(5);
arsi3.SetPaintingStrategy(PaintingStrategy.LINE);
arsi3.SetStyle(Curve.FIRM);
arsi3.AssignValueColor(if arsi3 > arsi3[1] then arsi3.Color("UpTrend") else arsi3.Color("DownTrend"));

AddLabel(showLabel, "ARSI3: " + arsi3, if arsi3 > arsi3[1] then arsi3.Color("UpTrend") else arsi3.Color("DownTrend"));

plot bull3 = arsi3[2] > arsi3[1] and arsi3 > arsi3[1];
bull3.SetDefaultColor(Color.DARK_GREEN);
bull3.SetlineWeight(5);
bull3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bull3.SetHiding(!showReversals);

plot bear3 = arsi3[2] < arsi3[1] and arsi3 < arsi3[1];
bear3.SetDefaultColor(Color.DARK_RED);
bear3.SetLineWeight(5);
bear3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bear3.SetHiding(!showReversals);

# END - ARSI
 

rad14733

Well-known member
VIP
@je®emy Can you post an image of what your chart looks like with your MTF modifications... On my chart is is simply three plotted lines, the same as one would get by loading the standard ARSI three times and editing the settings... Not a true MTF implementation...
 

je®emy

New member
Perhaps my understanding of MTF is incorrect. In this example I have lines for ARSI in D, Wk, and Mo timeframes. I did also notice that the toggles for Show Reversals and Show Labels does not work for aggs 2 and 3.

dzRHnfz.jpg
 

rad14733

Well-known member
VIP
Perhaps my understanding of MTF is incorrect. In this example I have lines for ARSI in D, Wk, and Mo timeframes. I did also notice that the toggles for Show Reversals and Show Labels does not work for aggs 2 and 3.

Yeah, I actually have no use for the MTF concept for this indicator because it is more intended for short term intraday trading rather than long term or swing trading... MTF usually displays a band/ribbon... I updated the initial post before fully testing and may revert it back to v1.2 until MTF is working as expected...
 

Similar threads

Top