Creating A RSI-Heiken Ashi For ThinkOrSwim

Status
Not open for further replies.

High_Velocity

New member

This Question has been answered the New RSI-Heiken Ashi Indicator can be found: https://usethinkscript.com/threads/rsi-heiken-ashi-for-thinkorswim.7250/ This thread has been locked


Can somebody help me convert this indicator from Tradingview to Thinkorswim?
I am trying to display RSI Divergence as Heiken-Ashi Bars.....
https://www.tradingview.com/v/4VKd87zy/
https://www.tradingview.com/script/XjMpwsmg-RSI-Divergence-Candles-V0/
Cfe7ZDsh.png



study(title="RSI_Hist")
useHL = input(title='Use high/low series for mapping the wicks?', type=bool, defval=false)
src = input(title='Source Series:', type=source, defval=close)
fast_length = input(title='Fast Length:', type=integer, defval=8)
slow_length = input(title='Slow Length:', type=integer, defval=55)
smooth = input(title='Smooth:', type=integer, defval=10)
overbought = input(title='Overbought Level:', type=float, defval=70)
oversold = input(title='Oversold Level:', type=float, defval=30)

fast_rsi = rsi(src, fast_length)
slow_rsi = rsi(src, slow_length)

smooth_fast_rsi = sma(fast_rsi, smooth)
smooth_slow_rsi = sma(slow_rsi, smooth)

rsi_high = useHL ? max(rsi(high, fast_length), rsi(high, slow_length)) : max(fast_rsi, slow_rsi)
rsi_low = useHL ? min(rsi(low, fast_length), rsi(low, slow_length)) : min(fast_rsi, slow_rsi)
//#ff59a3//#00f6e8
isBull=smooth_fast_rsi>=smooth_slow_rsi
isExp=abs(smooth_fast_rsi-smooth_slow_rsi)>=abs(smooth_fast_rsi[1]-smooth_slow_rsi[1])
plotcandle(smooth_slow_rsi, rsi_high, rsi_low, smooth_fast_rsi, title='rsi bars', color=isBull and isExp?#2aff00:isBull and not isExp?#ff59a3:not isBull and isExp?#ff0000:#00f6e8)
 
Last edited by a moderator:

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

Did not understand "short when yellow RSI line touches" the red zone? or something else, thx.
There are 2 zones shown - Overbought - Red Zone top, Oversold - Green Zone - bottom; The Yellow line is the RSI line and the author says Short when RSI line penetrates in to OS Zone - you can find the HARSI indicator on TV.
 
I cannot answer any questions on this indicator other than to say I put it on TV and tested it a little bit - doesn't look all that good as at the end of the day - you are just trading an RSI on OB or OS conditions
 
This look better?

Not sure how accurate I have this. Trying to play with the isBull and isExp variables to make sure colors match. Had to add 4x AddChart()

Updated Image
hUqZ7kF.jpg


Version 1.1 of RSI_Div_Candles per @High_Velocity request.
(Thx @germanburrito for AddChart() logic)
Fixed/Added the following:
  1. Fixed hollow UP Candles - fix provided by @SleepyZ
  2. Adjusted OB/OS option to turn on/off
  3. Added Visual Divergence Lines - credit @SuryaKiranC

Ruby:
## RSI_DIV_CANDLES
##
##
## CREDITS
## Requested by @High_Velocity from orignal source https://www.tradingview.com/v/4VKd87zy/
##
##
## Removing the header Credit credits and description is not permitted, any modification needs to be shared.
##
## V 1.1 :    @cos251 - @SleepyZ provided fix for hollow UP candles.  @SuryaKiranC provided Divergence line identifier
##                      Added option to turn on/off OB/OS lines.
##
## V 1.0 :    @cos251 - Initial release per request from usethinkscript forum.  Logic appears to match, Candle wicks may need additional
##       :    tweaking; thanks to @germanburrito for sharing AddChart() logic

declare lower;

input useHL          = no;
input price          = close;
input fastLength     = 8;
input slowLength     = 55;
input smooth         = 10;
input overBought     = 70;
input overSold       = 30;
input showOBOS       = no;
input showDivergence = yes;

def fastRSI = reference RSI(length = fastLength, price = price);
def slowRSI = reference RSI(length = slowLength, price = price);

def smoothFastRSI = MovingAverage(AverageType.WILDERS,fastRSI,smooth);
def smoothSlowRSI = MovingAverage(AverageType.WILDERS,slowRSI,smooth);

def rsiHigh = if useHL then Max(RSI(length = fastLength, price = high),RSI(length=slowLength,price = high)) else MAX(fastRSI,slowRSI);
def rsiLow = if useHL then MIN(RSI(length=fastLength,price=low),RSI(length=slowLength,price=low)) else MIN(fastRSI,slowRSI);

def isBull = smoothFastRSI >= smoothSlowRSI;
def isExp = AbsValue(smoothFastRSI-smoothSlowRSI) >= AbsValue(smoothFastRSI[1]-smoothSlowRSI[1]);

def o = smoothSlowRSI;
def h = rsiHigh;
def l = rsiLow;
def c = smoothFastRSI;

# Plot UP candle with isBull only
def UpO1;
def UpH1;
def UpL1;
def UpC1;
if o < c and isBull
then {
    UpO1 = o;
    UpH1 = h;
    UpL1 = l;
    UpC1 = c;
} else {
    UpO1 = Double.NaN;
    UpH1 = Double.NaN;
    UpL1 = Double.NaN;
    UpC1 = Double.NaN;
}

# Plot UP candle with isBull and isExp
def UpO;
def UpH;
def UpL;
def UpC;
if o < c and isBull and isExp
then {
    UpO = o;
    UpH = h;
    UpL = l;
    UpC = c;
} else {
    UpO = Double.NaN;
    UpH = Double.NaN;
    UpL = Double.NaN;
    UpC = Double.NaN;
}

# Plot DOWN candle
def DnO;
def DnH;
def DnL;
def DnC;
if o > c
then {
    DnO = o;
    DnH = h;
    DnL = l;
    DnC = c;
} else {
    DnO = Double.NaN;
    DnH = Double.NaN;
    DnL = Double.NaN;
    DnC = Double.NaN;
}


# Plot DOWN candle with !isBull and !isExp
def DnO1;
def DnH1;
def DnL1;
def DnC1;
if o > c and !isBull and !isExp
then {
    DnO1 = o;
    DnH1 = h;
    DnL1 = l;
    DnC1 = c;
} else {
    DnO1 = Double.NaN;
    DnH1 = Double.NaN;
    DnL1 = Double.NaN;
    DnC1 = Double.NaN;
}

# Plot the new Chart
#AddChart(high = UpH1, low = UpL1, open = UpO1, close = UpC1, type = ChartType.CANDLE, growcolor = Color.PINK);
#AddChart(high = UpH, low = UpL, open = UpO, close = UpC, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = UpH1, low = UpL1, open = Upc1, close = Upo1, type = ChartType.CANDLE, growcolor = Color.PINK);
AddChart(high = UpH, low = UpL, open = Upc, close = Upo, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = Color.RED);
AddChart(high = DnH1, low = DnL1, open = DnO1, close = DnC1, type = ChartType.CANDLE, growcolor = Color.CYAN);

plot ob = if showOBOS then overBought else Double.NaN;
ob.SetDefaultColor(COLOR.RED);
plot os = if showOBOS then overSold else Double.NaN;
os.SetDefaultColor(COLOR.GREEN);

def BN = barnumber();

#Divergence Code

def RSI_H = if fastRSI > overBought then fold Ri = 1 to Floor(fastLength / 2) with Rp = 1 while Rp do fastRSI > GetValue(fastRSI, -Ri) else 0;
def RSI_PivotH = if (BN > fastLength and fastRSI == Highest(fastRSI, Floor(fastLength / 2)) and RSI_H) then fastRSI else Double.NaN;
def RSI_L = if fastRSI < overSold then fold Rj = 1 to Floor(fastLength / 2) with Rq = 1 while Rq do fastRSI < GetValue(fastRSI, -Rj) else 0;
def RSI_PivotL = if (BN > fastLength and fastRSI == Lowest(fastRSI, Floor(fastLength / 2)) and RSI_L) then fastRSI else Double.NaN;
def RSI_PHBar = if !IsNaN(RSI_PivotH) then BN else RSI_PHBar[1];
def RSI_PLBar = if !IsNaN(RSI_PivotL) then BN else RSI_PLBar[1];
def RSI_PHPoint = if !IsNaN(RSI_PivotH) then RSI_PivotH else RSI_PHPoint[1];
def RSI_LastPHBar = if RSI_PHPoint != RSI_PHPoint[1] then RSI_PHBar[1] else RSI_LastPHBar[1];
def RSI_PLPoint = if !IsNaN(RSI_PivotL) then RSI_PivotL else RSI_PLPoint[1];
def RSI_LastPLBar = if RSI_PLPoint != RSI_PLPoint[1] then RSI_PLBar[1] else RSI_LastPLBar[1];

def RSI_HighPivots = BN >= HighestAll(RSI_LastPHBar);
def RSI_LowPivots = BN >= HighestAll(RSI_LastPLBar);
def RSI_pivotHigh = if RSI_HighPivots then RSI_PivotH else Double.NaN;

plot RSI_plotHline = if showDivergence then RSI_pivotHigh else Double.NaN;
RSI_plotHline.EnableApproximation();
RSI_plotHline.SetDefaultColor(Color.LIME);
RSI_plotHline.SetStyle(Curve.SHORT_DASH);

plot RSI_pivotLow = if showDivergence and RSI_LowPivots then RSI_PivotL else Double.NaN;
RSI_pivotLow.EnableApproximation();
RSI_pivotLow.SetDefaultColor(Color.LIME);
RSI_pivotLow.SetStyle(Curve.SHORT_DASH);

plot RSI_pivotDot = if !IsNaN(RSI_pivotHigh) then RSI_pivotHigh else if !IsNaN(RSI_pivotLow) then RSI_pivotLow else Double.NaN;
RSI_pivotDot.SetDefaultColor(Color.LIME);
RSI_pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
RSI_pivotDot.SetLineWeight(3);

AddLabel(yes,"RSI:",Color.YELLOW);
@cos251 Thank you for this indicator! Is there a way to turn this into an upper study with the candles colored? Like with AssignPriceColor? I would try to do it myself but I'm not a coder. It would also be nice to see the divergence line in the upper chart. Thanks!
 
Status
Not open for further replies.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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