• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

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:
Thanks in advance:)
 

tomsk

Well-known member
VIP
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:

tomsk

Well-known member
VIP
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.
 

netarchitech

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

prc-absolute-strength-issue.png


STOCH seems to be fine...

Good Luck and Good Trading :)
 

diazlaz

Well-known member
2019 Donor
VIP
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.
 

diazlaz

Well-known member
2019 Donor
VIP
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.

mZFtJES.png
 

diazlaz

Well-known member
2019 Donor
VIP
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);
}
 

diazlaz

Well-known member
2019 Donor
VIP
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
);
 

ba1960

New member
2019 Donor
VIP
@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
 

Similar threads

Top