# Absolute Strength Histogram for ThinkorSwim

#### superbvictory

##### New member
I have a question to see if anyone knows if Thinkorswim has a preset function to set up an absolute strength indicator? They are two lines cross confirmation indicators. One is called absolute strength oscillator and the other is absolute strength histogram. If they already exists, where do I find them to test them out and if not how can I start working on building a custom script.

I tried to look for the codes and here is where I found some references:

Here is your requested study converted to TOS based upon the code as listed in https://www.prorealcode.com/prorealtime-indicators/absolute-strength/

Code:
``````# PRC Absolute Strength

# Converted to TOS
#
# https://www.prorealcode.com/prorealtime-indicators/absolute-strength/

declare lower;

input mode = {default RSI, STOCH};

def p0 = close;
def p1 = close[1];
def length = 9;    # Period
def smooth = 1;    # Smoothing Period

def bulls;
def bears;
if mode == mode.RSI then {
bulls = 0.5 * AbsValue((p0 - p1) + (p0 - p1));
bears = 0.5 * AbsValue((p0 - p1) - (p0 - p1));
}
else {
bulls = p0 - Lowest(low, length);
bears = Highest(high, length) - p0;
}

def AvgBulls = Average(bulls, length);
def AvgBears = Average(bears, length);

plot SmoothedBulls = Average(AvgBulls, smooth);
SmoothedBulls.SetDefaultColor(CreateColor(0,191,255));
SmoothedBulls.SetLineWeight(3);

plot SmoothedBears = Average(AvgBears, smooth);
SmoothedBears.SetDefaultColor(CreateColor(255,0,0));
SmoothedBears.SetLineWeight(3);``````

Last edited by a moderator:
The specific statement is Bears=0.5*(Abs(Price1-Price2)-(Price1-Price2)) Since that evaluates to zero, hence you'll see a zero line plotted on the RSI mode.

@tomsk Thanks for sharing the interesting indicator. In case you might not be aware, there seems to be a bug with the RSI output:

STOCH seems to be fine...

Exactly - read my comments above, or check with the original author of the indicator

good stuff everyone, so I did a minor port of it as well - the only update I would recommend the original indicator is using a WMA average instead of SMA. thanks for the port.

...I would recommend the original indicator is using a WMA average instead of SMA.

@diazlaz Unfortunately i tried using WMA's and got the same result I think the problem may stem from the following:

Any ideas?

hi @netarchitech, you're absolutely right very little changes. just compared WMA, EMA and SMA's and there is very little difference. not sure it will make a big difference unless you're scalping and using it for intraday trading at lower timeframes.

#### Attachments

• mZFtJES.png
282.5 KB · Views: 172
@diazlaz Thanks for the update. I agree with you. If only there was some way of incorporating the "ModeMA" setting, but TOS has a two parameter limitation apparently

yep - limitation of ToS. the way I tried to work around it was with switch. but to your point, it's probably not worth it or needed.

Ruby:
``````input modema = {default wma, exp, sma};

#...

def AvgBulls;
def AvgBears;
def SmthBulls;
def SmthBears;

switch (modema) {
case wma:
AvgBulls = WMA(Bulls, length);
AvgBears = WMA(Bears, length);
SmthBulls = WMA(AvgBulls, smooth);
SmthBears = WMA(AvgBears, smooth);
case exp:
AvgBulls = ExpAverage(Bulls, length);
AvgBears = ExpAverage(Bears, length);;
SmthBulls = ExpAverage(AvgBulls, smooth);
SmthBears = ExpAverage(AvgBears, smooth);
case sma:
AvgBulls = Average(Bulls, length);
AvgBears = Average(Bears, length);;
SmthBulls = Average(AvgBulls, smooth);
SmthBears = Average(AvgBears, smooth);
}``````

it's probably not worth it or needed.
Not to my way of looking at it...I think it's a good idea @diazlaz ...may not be the ultimate solution, but it is an important step along the way

Did you plug it in? If so, did it work?

I haven't tested it, but I think there is some value in the EXP version of the MA.

Here is my port:

Ruby:
``````#TITLE
#Absolute Strength Histogram for TOS
#PRC_Absolute Strength | indicator

#DESCRIPTION
#The Absolute Strength indicator indicates the current market “strength”
#in two different ways possible RSI Method and Stochastic Method
#and by separating the bulls and bears into 2 curves.
#
#The results are then averaged with the same “length” as the one used for
#these 2 above methods and smoothed a second time using the “Smooth” variable.
#The moving average mode used is by default the Weighted one.

#CREDITS
#https://www.prorealcode.com/prorealtime-indicators/absolute-strength/
#https://www.prorealcode.com/user/nicolas/

#CHANGELOG
#2019.11.01 @diazlaz Initial Port

declare lower;

#INPUT INDICATOR
input mode = {default RSI, Stoch}; #0-RSI method 1-Stoch method
input length = 9; #length
input smooth = 1; #period of smoothing factor
input modema = {default wma, exp, sma};
input price = close; # price data

#LOGIC
def price1 = price;
def price2 = price[1];

def Bulls;
def Bears;

switch (mode) {
case RSI:
Bulls = 0.5*(AbsValue(Price1-Price2)+(Price1-Price2));
Bears = 0.5*(AbsValue(Price1-Price2)-(Price1-Price2));
case Stoch:
Bulls = price1 - Lowest(low, length);
Bears = Highest(high, length) - price1;
}

def AvgBulls;
def AvgBears;
def SmthBulls;
def SmthBears;
switch (modema) {
case wma:
AvgBulls = WMA(Bulls, length);
AvgBears = WMA(Bears, length);
SmthBulls = WMA(AvgBulls, smooth);
SmthBears = WMA(AvgBears, smooth);
case exp:
AvgBulls = ExpAverage(Bulls, length);
AvgBears = ExpAverage(Bears, length);;
SmthBulls = ExpAverage(AvgBulls, smooth);
SmthBears = ExpAverage(AvgBears, smooth);
case sma:
AvgBulls = Average(Bulls, length);
AvgBears = Average(Bears, length);;
SmthBulls = Average(AvgBulls, smooth);
SmthBears = Average(AvgBears, smooth);
}

#PLOTS
plot pSmthBulls = SmthBulls;
pSmthBulls.AssignValueColor(COLOR.UPTICK);
pSmthBulls.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

plot pSmthBears = SmthBears;
pSmthBears.AssignValueColor(COLOR.DOWNTICK);
pSmthBears.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

plot pSmthBullsL = SmthBulls;
pSmthBullsL.AssignValueColor(COLOR.GREEN);
pSmthBullsL.SetLineWeight(2);

plot pSmthBearsL = SmthBears;
pSmthBearsL.AssignValueColor(COLOR.RED);
pSmthBearsL.SetLineWeight(2);

#COLORCANDLES
input showColorBars = yes;
AssignPriceColor(
if !showColorBars then
Color.CURRENT
else
if SmthBulls > SmthBears then COLOR.GREEN
else
COLOR.RED
);``````

@diazlaz Nicely done! I really like the structure you put together...Looking forward to plugging it in and seeing it in action this weekend Thanks @diazlaz

@diazlaz Thank you for the indicator. It works great.

Thank you. I always look at my WMAs first before anything else, and this is wonderful!

Last edited by a moderator:
@diazlaz - Definitely my favorite trend indicator. Appreciate the work. Question...I've been trying to build a scan for the flip from bullish to bearish and bearish to bullish and can't make it work. I've put hundreds of scans together, but can't figure out what I'm not doing with the Absolute Strength indicator. Any help would be appreciated. I keep getting an "Unexpected error has happened" message. Thanks again

Which histogram have you guys found to be most reliable, RSI or Stochastics?

87k+ Posts
369 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?