RSI Momentum Acceleration For ThinkOrSwim

Veasna

New member
This indicator appears to be helpful to see the range the price move in weekly time frame.

The author states:
It plots the momentum acceleration oscillators from price and RSI, rescaled and with areas above/below highlighted.

Usage: in a nutshell, when the background is green, it's bearish (RSI decelerates faster than price), whereas when the background is plum, it's bullish (RSI accelerates faster than price). It appears to detect early some reversals that are otherwise difficult to detect.

D9S6viS.png


Here is the link to the original Tradingview code.
https://www.tradingview.com/script/lOKosgxd-RSI-Momentum-Acceleration-by-Tartigradia/
The new ThinkOrSwim script can be found in the next post.
 
Last edited by a moderator:

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

this is mostly converted
in the middle is code to pick rsi or custom. i didn't do that part. just used the defaults of close

this is a lower that draws 2 lines and clouds

Code:
#convert_rsi_momen

#https://usethinkscript.com/threads/convert-tradingview-rsi-momentum-acceleration.19465/
#Conversion Requests
#Convert TradingView RSI Momentum Acceleration
#Veasna  9/2

# I would like to ask for your help in converting the Tradingview script (in the link below) to TOS. It would be #helpful to see the range the price move in weekly time frame.
#However, if there is one that is similar, please let me know.

#Here is the link to the open source in Trading view:
#https://www.tradingview.com/script/lOKosgxd-RSI-Momentum-Acceleration-by-Tartigradia/



#https://www.tradingview.com/script/lOKosgxd-RSI-Momentum-Acceleration-by-Tartigradia/


#// RSI Momentum Acceleration (RSIMomAcc) by Tartigradia
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// Authors: Tartigradia, using a core routine from DGT (dgtrd)
#//
#// Description:
#// Plots the momentum acceleration oscillators from price and RSI, rescaled and with areas above/below highlighted.
#// Usage: in a nutshell, when the background is yellow, it's bearish (RSI decelerates faster than price), whereas when the background is green, it's bullish (RSI accelerates faster than price).
#// Note: it supports using any other indicator's output as the second source input, instead of RSI. PineScript does not allow for more than one source to receive input from other indicators, all the others must only use price as an input.
#// This indicator uses the core routine to calculate Momentum Acceleration Oscillators by DGT:
# https://www.tradingview.com/script/BmXmwmnE-Momentum-Acceleration-by-DGT/
#// This indicator is based on the idea of stinkbug
#  https://www.tradingview.com/script/BmXmwmnE-Momentum-Acceleration-by-DGT/#tc8337441
# "RSI is a good momentum indicator showing how excited ppl are on a move, this is why divergences on it work so well. I would like to see the change accelerating or slowing on a move up or down.."

#//@version=5
#indicator('RSI Momentum Acceleration by Tartigradia', 'RSIMomAcc', overlay=false, timeframe="")


declare lower;

def na = double.nan;
def bn = barnumber();


#f_speedy(_d, _t) =>
#    // Function by DGTRD, props to them! https://www.tradingview.com/script/BmXmwmnE-Momentum-Acceleration-by-DGT/
#    v = ta.sma(ta.change(_d, _t) / _t, 3)
#    a = ta.change(v, _t) / _t
#    v - a

#  ta.change(src , len)
#  Compares the current source value to its value length bars ago and returns the difference.
#  x = _d - getvalue(_d, _t)


script f_speedy {
 input _d = 0;
 input _t = 0;
 def chg = _d - getvalue(_d, _t);
 def len = 3;
 # v = ta.sma(chg / _t, len)
 def v =  MovingAverage( AverageType.Simple, (chg / _t), len );
 # a = ta.change(v, _t) / _t
 def a = v - getvalue(v, _t)/_t;
 plot z = v - a;
}


#f_featurescale(x, a, b) =>
#    // Rescale x to be between minimum a and maximum b values
#    a + ((x - ta.min(x)) * (b - a) / (ta.max(x) - ta.min(x)))
#   ta.min()
#   Returns the all-time low value of source from the beginning of the chart up to the current bar.

script f_featurescale {
 input x = 0;
 input a = 0;
 input b = 0;
 plot z = a + ((x - lowestall(x)) * (b - a) / (highestall(x) - lowestall(x)));
}


#// Parameters
#var grp1 = 'Momentum parameters'
#t = input.int(13, 'Momentum length', minval=1, group=grp1)
#frescale = input.bool(true, 'Rescale', inline='R1', group=grp1, tooltip='Rescale momentum values so that both plots overlap and #crosses nicely on the same scale.')
#rangemin = input(0.0, 'Min', inline='R1', group=grp1)
#rangemax = input(100.0, 'Max', inline='R1', group=grp1)

input t = 13;
input frescale = yes;
input rangemin = 0.0;
input rangemax = 100.0;

#var grp2 = 'Source 1'

#source1 = input.string('close', title='Source 1', options=['close', 'open', 'high', 'low', 'hl2', 'hlc3', 'hlcc4'], tooltip='Source for the first momentum oscillator', group=grp2) // workaround to only use one input.source(), so that PineScript then allows to use other indicators outputs as input here, otherwise with more than 1 input.source() then we can only select price as input for all sources.

#input source1 = { delault "close", "open", "high", "low", "hl2", "hlc3', 'hlcc4'], tooltip='Source for the first momentum oscillator', group=grp2) // workaround to only use one input.source(), so that PineScript then allows to use other indicators outputs as input here, otherwise with more than 1 input.source() then we can only select price as input for all sources.
input source1 = close;



#var grp3 = 'Source 2'
#source2 = input.string('RSI', 'Source', options=['RSI', 'Custom'], tooltip='Source for the second momentum oscillator. Default to RSI, but can be set to Custom, then can select any source under Source 2 Custom.', group=grp3)

#rsisource = input.string('close', title='RSI Source', options=['close', 'open', 'high', 'low', 'hl2', 'hlc3', 'hlcc4'], tooltip='Source for the RSI if used for Source 2.', group=grp3)

#rsilength = input.int(14, 'RSI Length', minval=1, group=grp3)

#source2_custom = input.source(open, title='Source 2 Custom', tooltip='Custom source for the second momentum oscillator instead of the default RSI. This can be data from any other indicator.', group=grp3)


def rsisource = close;



#// Workaround to use only one source: we manually input each possible price source from an input.string()
#s1 = switch source1
#    'close' => close
#    'open' => open
#    'high' => high
#    'low' => low
#    'hl2' => hl2
#    'hlc3' => hlc3
#    'hlcc4' => hlcc4
#s2 = switch rsisource
#    'close' => close
#    'open' => open
#    'high' => high
#    'low' => low
#    'hl2' => hl2
#    'hlc3' => hlc3
#    'hlcc4' => hlcc4


def s1 = source1;
def s2 = rsisource;


#// Switch between native RSI and custom source for Source 2
#source2_d = source2 == 'RSI' ? ta.rsi(s2, rsilength) : source2_custom
def source2_d = RSI();


#// Calculate momentum oscillator from each data source
#d1 = f_speedy(s1, t)
#d2 = f_speedy(source2_d, t)
def d1 = f_speedy(s1, t);
def d2 = f_speedy(source2_d, t);


#// Rescale data so that they overlap nicely
#fd1 = frescale ? f_featurescale(d1, rangemin, rangemax) : d1
#fd2 = frescale ? f_featurescale(d2, rangemin, rangemax) : d2
def fd1 = if frescale then f_featurescale(d1, rangemin, rangemax) else d1;
def fd2 = if frescale then f_featurescale(d2, rangemin, rangemax) else d2;


#// Plot
#plot(fd1, color=color.new(color.aqua, 0), title='Momentum Acceleration Oscillator 1')
#plot(fd2, color=color.new(color.red, 0), title='Momentum Acceleration Oscillator 2')
plot z1 = fd1;
plot z2 = fd2;
z1.SetDefaultColor(Color.cyan);
z1.setlineweight(1);
z1.hidebubble();
z2.SetDefaultColor(Color.red);
z2.setlineweight(1);
z2.hidebubble();


#bgcolor(fd1 < fd2 ? color.new(color.green, 80) : color.new(color.yellow, 80), title='Highlight background when oscillator 1 above or below oscillator 2')
def pos = double.POSITIVE_INFINITY;
def neg = double.negative_INFINITY;
def grn = if fd2 > fd1 then pos else na;
def red = if fd2 < fd1 then pos else na;
addcloud(grn, neg, color.green);
addcloud(red, neg, color.yellow);

#
added the second Source.

CSS:
# Indicator for TOS
#convert_rsi_momen
#https://usethinkscript.com/threads/convert-tradingview-rsi-momentum-acceleration.19465/
#Conversion Requests
#Convert TradingView RSI Momentum Acceleration
#Veasna  9/2

# I would like to ask for your help in converting the Tradingview script (in the link below) to TOS. It would be #helpful to see the range the price move in weekly time frame.
#However, if there is one that is similar, please let me know.

#Here is the link to the open source in Trading view:
#https://www.tradingview.com/script/lOKosgxd-RSI-Momentum-Acceleration-by-Tartigradia/

#https://www.tradingview.com/script/lOKosgxd-RSI-Momentum-Acceleration-by-Tartigradia/


#// RSI Momentum Acceleration (RSIMomAcc) by Tartigradia
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// Authors: Tartigradia, using a core routine from DGT (dgtrd)
#//
#// Description:
#// Plots the momentum acceleration oscillators from price and RSI, rescaled and with areas above/below highlighted.
#// Usage: in a nutshell, when the background is yellow, it's bearish (RSI decelerates faster than price), whereas when the background is green, it's bullish (RSI accelerates faster than price).
#// Note: it supports using any other indicator's output as the second source input, instead of RSI. PineScript does not allow for more than one source to receive input from other indicators, all the others must only use price as an input.
#// This indicator uses the core routine to calculate Momentum Acceleration Oscillators by DGT:
# https://www.tradingview.com/script/BmXmwmnE-Momentum-Acceleration-by-DGT/
#// This indicator is based on the idea of stinkbug
#  https://www.tradingview.com/script/BmXmwmnE-Momentum-Acceleration-by-DGT/#tc8337441
# "RSI is a good momentum indicator showing how excited ppl are on a move, this is why divergences on it work so well. I would like to see the change accelerating or slowing on a move up or down.."

#//@version=5
#indicator('RSI Momentum Acceleration by Tartigradia', 'RSIMomAcc', overlay=false, timeframe="")


declare lower;

input timeframe = AggregationPeriod.MIN;
input MomentumLength = 13;
input Rescale = yes;
input rescaleLookback = 200;
input rangemin = 0.0;
input rangemax = 100.0;
input source1 = FundamentalType.CLOSE;
input source2 = {Default "RSI", "Custom"}; #tooltip='Source for the second momentum oscillator. Default to RSI, but can be set to Custom, then can select any source under Source 2 Custom.'
input rsiSource = FundamentalType.CLOSE; #Source'
input rsiLength = 14; #, 'RSI Length'
input source2Custom = FundamentalType.OPEN; #(open, title='Source 2 Custom', to


def na = double.nan;
def current = GetAggregationPeriod();
def tf = Max(current, timeframe);
def src1 = Fundamental(FundamentalType= source1, Period = tf);
def src2 = Fundamental(FundamentalType= source2Custom, Period = tf);
def rsiSrc = Fundamental(FundamentalType= rsiSource, Period = tf);
Script f_speedy {
input _d = close;
input _t = 13;
    def chg = _d - _d[_t];
    def v = Average(chg / _t, 3);
    def a = (v - v[_t]) / _t;
 plot z = v - a;
}
Script f_featurescale {
 input src = close;
 input min = 0;
 input mxx = 100;
 input rescaleLookback = 300;
    def hh = highest(src, rescaleLookback);
    def ll = lowest(src,  rescaleLookback);
    def f_featurescale = min + ((src - ll) * (mxx - min) / (hh - ll));
 plot z = f_featurescale;
}

#// Switch between native RSI and custom source for Source 2
def source2_d;
Switch (source2) {
Case "Custom" : source2_d = src2;
Default : source2_d = rsi(Price = rsiSrc, Length = rsilength);
}
#// Calculate momentum oscillator from each data source
def d1 = f_speedy(src1, MomentumLength);
def d2 = f_speedy(source2_d, MomentumLength);

#// Rescale data so that they overlap nicely
def fd1 = if Rescale then f_featurescale(d1, rangemin, rangemax, rescaleLookback) else d1;
def fd2 = if Rescale then f_featurescale(d2, rangemin, rangemax, rescaleLookback) else d2;

#// Plot
plot MomOsc1 = fd1; #'Momentum Acceleration Oscillator 1'
plot MomOsc2 = fd2; # 'Momentum Acceleration Oscillator 2'
MomOsc1.SetDefaultColor(Color.CYAN);
MomOsc2.SetDefaultColor(Color.MAGENTA);

#-- BG
def pos = double.POSITIVE_INFINITY;
def neg = double.negative_INFINITY;
def grn = fd1 < fd2;

addcloud(if (grn or grn[-1]) then pos else na, neg, color.DARK_GREEN);
addcloud(if (!grn or !grn[-1]) then pos else na, neg, color.DARK_RED);

#
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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