Absolute Strength Indicator (ASI) For ThinkOrSwim

mbarcala

Active member
Here I bring you ASI, (Absolute Strength Indicator). I saw it in Trading view. I tried simultaneously while I operating in TOS platform, and now finally get it converted with the HELP a friend IgorF. You can change and play with the settings as you like and try the 3 option that come inside as RSI, Stochastic and ADX.

Original trading view link: https://www.tradingview.com/script/WbkLdhzL-Absolute-Strength-MTF-Indicator/

Photos:

Script:
Code:
# Absolute Strength Indicator converter to TOS by mbarcala and IgorF
# Original TradingView Code: https://www.tradingview.com/script/WbkLdhzL-Absolute-Strength-MTF-Indicator/ by alexgrover

declare lower;

input length = 20;
input Smooth = 5;
input Mode = {default RSI, STOCHASTIC, ADX};
input Ma = {default SMA, EMA, LSMA};

def Bulls;
def Bears;

switch (Mode) {
case RSI:
    Bulls = 0.5 * (AbsValue(close - close[1]) + (close - close[1]));
    Bears = 0.5 * (AbsValue(close - close[1]) - (close - close[1]));
case Stochastic:
    Bulls = close - Lowest(close, length);
    Bears = Highest(close, length) - close;
case ADX:
    Bulls = 0.5 * (AbsValue(high - high[1]) + (high - high[1]));
    Bears = 0.5 * (AbsValue(low[1] - low) + (low[1] - low));
}

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

switch (Ma) {
    case SMA:
        AvgBulls = SimpleMovingAvg(Bulls, length);
        AvgBears = SimpleMovingAvg(Bears, length);
        SmthBulls = SimpleMovingAvg(AvgBulls, Smooth);
        SmthBears = SimpleMovingAvg(AvgBears, Smooth);
    case EMA:
        AvgBulls = ExpAverage(Bulls, length);
        AvgBears = ExpAverage(Bears, length);
        SmthBulls = ExpAverage(AvgBulls, Smooth);
        SmthBears = ExpAverage(AvgBears, Smooth);
    case LSMA:
        AvgBulls = InertiaAll(Bulls, length, 0);
        AvgBears = InertiaAll(Bears, length, 0);
        SmthBulls = InertiaAll(AvgBulls, Smooth, 0);
        SmthBears = InertiaAll(AvgBears, Smooth, 0);
}

def trend = if SmthBulls > SmthBears then 1 else -1;

plot sgnBull = SmthBulls;
sgnBull.SetDefaultColor(CreateColor(0, 101, 255));
sgnBull.SetLineWeight(5);
sgnBull.HideBubble();
sgnBull.HideTitle();

plot sgnBear = SmthBears;
sgnBear.SetDefaultColor(CreateColor(230,15,88));
sgnBear.SetLineWeight(5);
sgnBear.HideBubble();
sgnBear.HideTitle();

AddCloud(SmthBulls, SmthBears, CreateColor(0, 101, 255), CreateColor(230,17,125));

plot cDot = if SmthBulls crosses above SmthBears then SmthBulls else if SmthBulls crosses below SmthBears then SmthBears else Double.NaN;
cDot.SetPaintingStrategy(paintingStrategy.POINTS);
cDot.SetDefaultColor(Color.WHITE);
cDot.SetLineWeight(2);
cDot.HideBubble();
cDot.HideTitle();

#for scanner purpose only, you need to change the other plots on top as def and uncomment this to at the bottom!
#plot upBull = sgnBull crosses above sgnBear;
#plot dnBear = sgnBull crosses below sgnBear;

As I always think if you try please share your experience!
 
Last edited:
Here I bring you ASI, (Absolute Strength Indicator). I saw it in Trading view. I tried simultaneously while I operating in TOS platform, and now finally get it converted with the HELP a friend IgorF. You can change and play with the settings as you like and try the 3 option that come inside as RSI, Stochastic and ADX.

Original trading view link: https://www.tradingview.com/script/WbkLdhzL-Absolute-Strength-MTF-Indicator/

Photos:

Script:
Code:
# Absolute Strength Indicator converter to TOS by mbarcala and IgorF
# Original TradingView Code: https://www.tradingview.com/script/WbkLdhzL-Absolute-Strength-MTF-Indicator/ by alexgrover

declare lower;

input Length = 20;
input Smooth = 5;
input Mode = {default RSI, STOCHASTIC, ADX};
input Ma = {default SMA, EMA, LSMA};

script linreg {
    input src = close;
    input length = 2;
    input offset = 0;

    def sumX = fold i = 0 to length with p = 0 do p + i + 1;
    def sumY = fold i2 = 0 to length with p2 = 0 do p2 + src[i2];
    def sumXSqr = fold i3 = 0 to length with p3 = 0 do p3 + (i3 + 1) * (i3 + 1);
    def sumXY = fold i4 = 0 to length with p4 = 0 do p4 + src[i4] * (i4 + 1);

    def slope = (length * sumXY - sumX * sumY) / (length * sumXSqr - sumX * sumX);
    def average = sumY / length;
    def intercept = average - slope * (sumX / length - 1 - offset);
    plot d = intercept;
}

def Price1;
def Price2;

def Bulls0 = 0.5 * (AbsValue(Price1 - Price2) + (Price1 - Price2));
def Bears0 = 0.5 * (AbsValue(Price1 - Price2) - (Price1 - Price2));

def Bulls1 = Price1 - Lowest(Price1, length);
def Bears1 = Highest(Price1, length) - Price1;
def Bulls2 = 0.5 * (AbsValue(high - high[1]) + (high - high[1]));
def Bears2 = 0.5 * (AbsValue(low[1] - low) + (low[1] - low));

def Bulls = if Mode == Mode."RSI" then Bulls0 else if Mode == Mode."STOCHASTIC" then Bulls1 else Bulls2;
def Bears = if Mode == Mode."RSI" then Bears0 else if Mode == Mode."STOCHASTIC" then Bears1 else Bears2;

def AvgBulls;
def AvgBears;
def SmthBulls;
def SmthBears;
if Ma == Ma.SMA
then
{
    Price1 = SimpleMovingAvg(close, Length);
    Price2 = SimpleMovingAvg(close, Length)[1];
    AvgBulls = SimpleMovingAvg(Bulls, Length);
    AvgBears = SimpleMovingAvg(Bears, Length);
    SmthBulls = SimpleMovingAvg(AvgBulls, Smooth);
    SmthBears = SimpleMovingAvg(AvgBears, Smooth);
}
else if Ma == Ma.EMA
then
{
    Price1 = ExpAverage(close, length);
    Price2 = ExpAverage(close, length)[1];
    AvgBulls = ExpAverage(Bulls, length);
    AvgBears = ExpAverage(Bears, length);
    SmthBulls = ExpAverage(AvgBulls, Smooth);
    SmthBears = ExpAverage(AvgBears, Smooth);
}
else
{
    Price1 = linreg(close, Length, 0);
    Price2 = linreg(close, Length, 0)[1];
    AvgBulls = linreg(Bulls, Length, 0);
    AvgBears = linreg(Bears, Length, 0);
    SmthBulls = linreg(AvgBulls, Smooth, 0);
    SmthBears = linreg(AvgBears, Smooth, 0);
}

def trend = if SmthBulls > SmthBears then 1 else -1;

plot sgnBull = SmthBulls;
sgnBull.SetDefaultColor(CreateColor(0, 101, 255));
sgnBull.SetLineWeight(5);
sgnBull.HideBubble();
sgnBull.HideTitle();

plot sgnBear = SmthBears;
sgnBear.SetDefaultColor(CreateColor(230,15,88));
sgnBear.SetLineWeight(5);
sgnBear.HideBubble();
sgnBear.HideTitle();

AddCloud(SmthBulls, SmthBears, CreateColor(0, 101, 255), CreateColor(230,17,125));

plot cDot = if SmthBulls crosses above SmthBears then SmthBulls else if SmthBulls crosses below SmthBears then SmthBears else Double.NaN;
cDot.SetPaintingStrategy(paintingStrategy.POINTS);
cDot.SetDefaultColor(Color.WHITE);
cDot.SetLineWeight(2);
cDot.HideBubble();
cDot.HideTitle();

As I always think if you try please share your experience!
Thank you...It does work better on the Daily I discovered. Good Indicator.
 
for scanner add these 2 lines at the bottom of the script, select from the input your signal and make true!

Code:
plot upBull = sgnBull crosses above sgnBear;

plot dnBear = sgnBull crosses below sgnBear;
 
This works just fine for me...

Code:
# Absolute Strength Indicator converter to TOS by mbarcala and IgorF
# Original TradingView Code: https://www.tradingview.com/script/WbkLdhzL-Absolute-Strength-MTF-Indicator/ by alexgrover

declare lower;

input length = 20;
input Smooth = 5;
input Mode = {default "RSI", "STOCHASTIC", "ADX"};
input Ma = {default "SMA", "EMA", "LSMA"};

def Bulls;
def Bears;

switch (Mode) {
case "RSI":
    Bulls = 0.5 * (AbsValue(close - close[1]) + (close - close[1]));
    Bears = 0.5 * (AbsValue(close - close[1]) - (close - close[1]));
case "STOCHASTIC":
    Bulls = close - Lowest(close, length);
    Bears = Highest(close, length) - close;
case "ADX":
    Bulls = 0.5 * (AbsValue(high - high[1]) + (high - high[1]));
    Bears = 0.5 * (AbsValue(low[1] - low) + (low[1] - low));
}

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

switch (Ma) {
    case "SMA":
        AvgBulls = SimpleMovingAvg(Bulls, length);
        AvgBears = SimpleMovingAvg(Bears, length);
        SmthBulls = SimpleMovingAvg(AvgBulls, Smooth);
        SmthBears = SimpleMovingAvg(AvgBears, Smooth);
    case "EMA":
        AvgBulls = ExpAverage(Bulls, length);
        AvgBears = ExpAverage(Bears, length);
        SmthBulls = ExpAverage(AvgBulls, Smooth);
        SmthBears = ExpAverage(AvgBears, Smooth);
    case "LSMA":
        AvgBulls = InertiaAll(Bulls, length, 0);
        AvgBears = InertiaAll(Bears, length, 0);
        SmthBulls = InertiaAll(AvgBulls, Smooth, 0);
        SmthBears = InertiaAll(AvgBears, Smooth, 0);
}

def trend = if SmthBulls > SmthBears then 1 else -1;

def sgnBull = SmthBulls;

def sgnBear = SmthBears;

#for scanner purpose only, you need to change the other plots on top as def and uncomment this to at the bottom!
plot upBull = sgnBull crosses above sgnBear;
#plot dnBear = sgnBull crosses below sgnBear;
 
This works just fine for me...

Code:
# Absolute Strength Indicator converter to TOS by mbarcala and IgorF
# Original TradingView Code: https://www.tradingview.com/script/WbkLdhzL-Absolute-Strength-MTF-Indicator/ by alexgrover

declare lower;

input length = 20;
input Smooth = 5;
input Mode = {default "RSI", "STOCHASTIC", "ADX"};
input Ma = {default "SMA", "EMA", "LSMA"};

def Bulls;
def Bears;

switch (Mode) {
case "RSI":
    Bulls = 0.5 * (AbsValue(close - close[1]) + (close - close[1]));
    Bears = 0.5 * (AbsValue(close - close[1]) - (close - close[1]));
case "STOCHASTIC":
    Bulls = close - Lowest(close, length);
    Bears = Highest(close, length) - close;
case "ADX":
    Bulls = 0.5 * (AbsValue(high - high[1]) + (high - high[1]));
    Bears = 0.5 * (AbsValue(low[1] - low) + (low[1] - low));
}

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

switch (Ma) {
    case "SMA":
        AvgBulls = SimpleMovingAvg(Bulls, length);
        AvgBears = SimpleMovingAvg(Bears, length);
        SmthBulls = SimpleMovingAvg(AvgBulls, Smooth);
        SmthBears = SimpleMovingAvg(AvgBears, Smooth);
    case "EMA":
        AvgBulls = ExpAverage(Bulls, length);
        AvgBears = ExpAverage(Bears, length);
        SmthBulls = ExpAverage(AvgBulls, Smooth);
        SmthBears = ExpAverage(AvgBears, Smooth);
    case "LSMA":
        AvgBulls = InertiaAll(Bulls, length, 0);
        AvgBears = InertiaAll(Bears, length, 0);
        SmthBulls = InertiaAll(AvgBulls, Smooth, 0);
        SmthBears = InertiaAll(AvgBears, Smooth, 0);
}

def trend = if SmthBulls > SmthBears then 1 else -1;

def sgnBull = SmthBulls;

def sgnBear = SmthBears;

#for scanner purpose only, you need to change the other plots on top as def and uncomment this to at the bottom!
plot upBull = sgnBull crosses above sgnBear;
#plot dnBear = sgnBull crosses below sgnBear;
yes it work now, thanks that you told me to change to a switch function, and I change the linreg to inertialAll, it work like a charm!
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
521 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