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:
@rad14733


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)
Code:
input length = 8;
input length2 = 55;

input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI =average( 50 * (ChgRatio + 1),10);
def NetChgAvg2 = MovingAverage(averageType, price - price[1], length2);
def TotChgAvg2 = MovingAverage(averageType, AbsValue(price - price[1]), length2);
def ChgRatio2 = if TotChgAvg2 != 0 then NetChgAvg2 / TotChgAvg2 else 0;

def RSI2 = average(50 * (ChgRatio2 + 1),10);

plot diff= rsi-rsi2;


plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);


Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.cyan);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.violet);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));



thats not what you want because it doesnt display the wicks but you mightlike it
 
Anybody willing to help? please.
I have this started but still needs a lot of work. The wicks need to be fixed and my colors are not matching. Still working on the color change on trend conditions. If I make some decent progress this week I'll post a test version.
 
Last edited:
I have this started but still needs a lot of work. The wicks need to be fixed and my colors are not matching. Still working on the color change on trend conditions. If I make some decent progress this week I'll post a test version.

9xCkdGS.jpg
Changing the color might be tricky on the add chart command. Of you need help with that I might be able to help.
 
Changing the color might be tricky on the add chart command. Of you need help with that I might be able to help.
You are right. I was using this:

Ruby:
AddChart(GrowColor = Color.GREEN, FallColor = Color.RED, NeutralColor = Color.CURRENT, high=rsiHigh, low=rsiLow, open=smoothSlowRSI, close=smoothFastRSI, Type = ChartType.CANDLE_TREND);

System didn't allow me to use if statements for the color, but also the RED is not applying for the FallColor. Any tips or suggestions would definitely be appreciated sir. Thx
 
You are right. I was using this:

Ruby:
AddChart(GrowColor = Color.GREEN, FallColor = Color.RED, NeutralColor = Color.CURRENT, high=rsiHigh, low=rsiLow, open=smoothSlowRSI, close=smoothFastRSI, Type = ChartType.CANDLE_TREND);

System didn't allow me to use if statements for the color, but also the RED is not applying for the FallColor. Any tips or suggestions would definitely be appreciated sir. Thx
i had the same problem look at how this code was able to paint different colors on the add chart command.
Code:
declare lower;
# hide the default candles
#HidePricePlot();


input length = 21;

input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);


input BarsBetween = 0;

# calculate the offset
def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
def offset = BarsBetween * ((lastBar - BarNumber()) / (BarsBetween + 1));

# build the candle
def o;
def h;
def l;
def c;

def R = RSI();


if offset % 1 == 0
then {

    o = (R + R[1]) / 2;

    h = Max(R, R[1]);

    l = Min(R, R[1]);

    c = R;

} else {
    o = Double.NaN;
    h = Double.NaN;
    l = Double.NaN;
    c = Double.NaN;
}

# just the UP candles
def UpO;
def UpH;
def UpL;
def UpC;
if o <= c
then {
    UpO = o;
    UpH = h;
    UpL = l;
    UpC = c;
} else {
    UpO = Double.NaN;
    UpH = Double.NaN;
    UpL = Double.NaN;
    UpC = Double.NaN;
}

# just the DOWN candles
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 the new Chart
AddChart(high = UpH, low = UpL, open = UpO, close = UpC, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = Color.RED);
 
i had the same problem look at how this code was able to paint different colors on the add chart command.
Code:
declare lower;
# hide the default candles
#HidePricePlot();


input length = 21;

input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);


input BarsBetween = 0;

# calculate the offset
def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
def offset = BarsBetween * ((lastBar - BarNumber()) / (BarsBetween + 1));

# build the candle
def o;
def h;
def l;
def c;

def R = RSI();


if offset % 1 == 0
then {

    o = (R + R[1]) / 2;

    h = Max(R, R[1]);

    l = Min(R, R[1]);

    c = R;

} else {
    o = Double.NaN;
    h = Double.NaN;
    l = Double.NaN;
    c = Double.NaN;
}

# just the UP candles
def UpO;
def UpH;
def UpL;
def UpC;
if o <= c
then {
    UpO = o;
    UpH = h;
    UpL = l;
    UpC = c;
} else {
    UpO = Double.NaN;
    UpH = Double.NaN;
    UpL = Double.NaN;
    UpC = Double.NaN;
}

# just the DOWN candles
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 the new Chart
AddChart(high = UpH, low = UpL, open = UpO, close = UpC, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = Color.RED);
so I guess what it did was divide the chart and add two add charts.
 
You are right. I was using this:

Ruby:
AddChart(GrowColor = Color.GREEN, FallColor = Color.RED, NeutralColor = Color.CURRENT, high=rsiHigh, low=rsiLow, open=smoothSlowRSI, close=smoothFastRSI, Type = ChartType.CANDLE_TREND);

System didn't allow me to use if statements for the color, but also the RED is not applying for the FallColor. Any tips or suggestions would definitely be appreciated sir.
how is it going. message me. add me on tweeter @GermanBrito17
 
Did you have a chance to compare it to same chart on Tradingview?
Quick stare and compare looks very close. The wicks on the UP candles may still needs some work.
I've posted what I have so far. Big thanks to @germanburrito for the help on AddChart Logic.

Please take a look, happy to take more input and assistance in correcting any errors and improving it. Very nice indicator.

See Fresh Code in post #20
https://usethinkscript.com/threads/rsi-histogram.7250/post-70605

Cheers!
 
This should help fix the hollow candles. To do that you reverse the open and close for those hollow candles.

Ruby:
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);
FANTASTIC @SleepyZ. You come through again. Nice fix!

I've updated post #20 with the changes. Added the hollow candle fix, on/off for OB/OS and added Divergence line (thx @SuryaKiranC ). Take a peek and let me know what other changes we can add.

https://usethinkscript.com/threads/rsi-histogram.7250/post-70605
 
Status
Not open for further replies.

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
421 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