Absolute Strength Histogram for TOS

S

superbvictory

New member
Hello guys,

I'm new to this forum! I'm not a coding expert - so just wonder if any thinkscript expert here can help convert this absolute strength histogram indicator code into thinkscript?

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

Thanks in advance:)
 
T

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:
C

chillc15

New member
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);
I just get a flat red line for the SmoothedBears.

Suggestions?

Thanks.
 
BenTen

BenTen

Administrative
Staff
VIP
@chillc15 Switch to the Stoch settings.
 
T

tomsk

Well-known member
VIP
That is because the formula in the original source code evaluates to zero, as described in
 
T

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

netarchitech

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

Good Luck and Good Trading :)
 
T

tomsk

Well-known member
VIP
Exactly - read my comments above, or check with the original author of the indicator
 
D

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.
 
netarchitech

netarchitech

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

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.

 
netarchitech

netarchitech

Well-known member
@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 :(
 
D

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);
}
 
netarchitech

netarchitech

Well-known member
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?
 
D

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
);
 
netarchitech

netarchitech

Well-known member
@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
 

Top