Heikin Ashi RSI Oscillator for TOS?

Here is a screenshot of HARSI on TV

The strategy is -

Long when candles close into Green zone or Short when Yellow RSI line touches - simplistic yes - but tests ok

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


Well-known member
Thank you for your comment - this doesn't seem to do what the TV HARSI does - IMO - as the TV Harsi has zones to easily see when to go Long or Short - that is too simplistic of course - but it is Backtesting pretty well on TV
Try this. I wanted to test doing AddChart again so I took a stab at this one as well. I did not include the RSI histogram or the Stochastic plot. Both were unnecessary. Feel free to add if you like.

QUICK UPDATE - Added divergence code provided by @SuryaKiranC


## HARSI_Oscillator
## Requested by @MatthewTherrien from orignal source https://www.tradingview.com/script/1o4oWbEx-Heikin-Ashi-RSI-Oscillator/
## Removing the header Credit credits and description is not permitted, any modification needs to be shared.
## V 1.1 :    @cos251 - Added divergence code provided by @SuryaKiranC
## V 1.0 :    @cos251 - Initial release per request from usethinkscript forum. 
##       :    Did not include stochasitc plots

declare lower;

input i_upper        = 20;
input i_upperx       = 30;
input i_lenRSI       = 7;
input i_lenHARSI     = 14;
input i_smoothing    = 1;
input showDivergence = yes;
input showOBOS       = yes;
input i_RSISmooth    = yes;
input cType          = ChartType.CANDLE;

# --- RSI Line Plot (Orange)
def _zrsi = reference RSI(price = ohlc4, length = i_lenRSI) - 50;
def _smooth = if IsNaN(_smooth[1]) then _zrsi else (_smooth[1] + _zrsi) / 2;
def rsivar = if i_RSISmooth then _smooth else _zrsi;
plot RSI = rsivar;
# --- End RSI Line Plot

# --- Heikin Ashi RSI O,H,L,C Calculations
def closeRSI = reference RSI(price = close, length = i_lenHARSI) - 50;
def openRSI = if IsNaN(closeRSI[1]) then closeRSI else closeRSI[1];
def highRSI_raw = reference RSI(price = high, length = i_lenHARSI) - 50;
def lowRSI_raw = reference RSI(price = low, length = i_lenHARSI) - 50;
def highRSI = Max(highRSI_raw, lowRSI_raw);
def lowRSI = Min(highRSI_raw, lowRSI_raw);
def _close = (openRSI + highRSI + lowRSI + closeRSI) / 4;
def _open = if IsNaN(_open[i_smoothing]) then (openRSI + closeRSI) / 2 else ((_open[1] * i_smoothing) + _close[1]) / (i_smoothing + 1);
def _high = Max( highRSI, Max( _open, _close ) );
def _low = Min( lowRSI,  Min( _open, _close ) );

def o = _open;
def h = _high;
def l = _low;
def c = _close;

# --- End Heikin Ashi O,H,L,C

# OHLC UP candle
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;

# OHLC 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 OB/OS areas
plot ob = if showOBOS then i_upper else Double.NaN;
plot obextreme = if showOBOS then i_upperx else Double.NaN;
plot os = if showOBOS then -i_upper else Double.NaN;
plot osextreme = if showOBOS then -i_upperx else Double.NaN;
AddCloud(if showOBOS then ob else Double.NaN, if showOBOS then Double.POSITIVE_INFINITY else Double.NaN, Color.RED);
AddCloud(if showOBOS then os else Double.NaN, if showOBOS then Double.NEGATIVE_INFINITY else Double.NaN, Color.GREEN);
plot z = 0;

# Plot the new Chart
AddChart(high = UpH, low = UpL, open = UpC, close = UpO, type = cType, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = cTYpe, growcolor = Color.RED);

def BN = barnumber();

#Divergence Code

def RSI_H = if RSI > ob then fold Ri = 1 to Floor(i_lenRSI / 2) with Rp = 1 while Rp do RSI > GetValue(RSI, -Ri) else 0;
def RSI_PivotH = if (BN > i_lenRSI and RSI == Highest(RSI, Floor(i_lenRSI / 2)) and RSI_H) then RSI else Double.NaN;
def RSI_L = if RSI < os then fold Rj = 1 to Floor(i_lenRSI / 2) with Rq = 1 while Rq do RSI < GetValue(RSI, -Rj) else 0;
def RSI_PivotL = if (BN > i_lenRSI and RSI == Lowest(RSI, Floor(i_lenRSI / 2)) and RSI_L) then RSI 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;

plot RSI_pivotLow = if showDivergence and RSI_LowPivots then RSI_PivotL else Double.NaN;

plot RSI_pivotDot = if !IsNaN(RSI_pivotHigh) then RSI_pivotHigh else if !IsNaN(RSI_pivotLow) then RSI_pivotLow else Double.NaN;
Last edited:


New member
Folks - my humble suggestion is to use the HA RSI for trend following trades rather than for reversals.
Try to keep the candles without the smoothening setting. Look to go long when the candles cross the zero line from below and the opposite for shorts...you may add a macd histogram (with an 8/13/21 setting) or another indicator for a double confirmation..

Trying to finding the bottom and trade reversals using this indicator or any other for that matter is a trade that
looks tempting and simple, but is not worth it!!

Similar threads