this is my mod script for TV - Heikin Ashi RSI Oscillator.
below review on YouTubeIntroducing HARSI - the RSI based Heikin Ashi candle oscillator.
...that's right, you read it correctly. This is Heikin Ashi candles in an oscillator
format derived from RSI calculations, aimed at smoothing out some of the
inherent noise seen with standard RSI indicators.
Ruby:
#// This source code is free to use, copy, and alter in any way you choose.
#// ...but credit is always nice :)
#//@version=4
#//@author=JayRogers
#https://www.tradingview.com/script/1o4oWbEx-Heikin-Ashi-RSI-Oscillator/
#study( "Heikin Ashi RSI Oscillator", "HARSI •", false, format.price, 2 )
# Converted by SAM4COK@ 06/2022 - Not exact code
declare lower;
def na = Double.NaN;
########## Colors ########
DefineGlobalColor("UPTICK" , CreateColor( 0,120,120));
DefineGlobalColor("UP" , CreateColor( 0,80 , 80));
DefineGlobalColor("DOWNTICK" , CreateColor(173, 0, 20));
DefineGlobalColor("DOWN" , CreateColor(117, 0, 14));
DefineGlobalColor("RSI" , CreateColor(250, 200, 50));
#DefineGlobalColor("UPTICK" , CreateColor( 0,166, 50));
#DefineGlobalColor("UP" , CreateColor( 0,110, 33));
#////////////////////////////////////////////////////////////////////////////////
#// //
#// ====== INPUTS ====== //
#// //
#////////////////////////////////////////////////////////////////////////////////
#// -- Candle config
input i_lenHARSI = 14; #"Length RSI calculations"
input i_smoothing = 1; #"Open Smoothing"
#// -- RSI plot config
input i_source = ohlc4; # "Source",
input i_lenRSI = 7; # "Length",
input i_mode = yes; # "Smoothed Mode RSI?"
input i_showPlot = yes; # "Show RSI Plot?"
input i_showHist = yes; # "Show RSI Histogram?"
#// -- Channel OB/OS config
input i_upper = 20; # "OB"
input i_upperx = 30; # "OB Extreme"
input i_lower = -20; # "OS"
input i_lowerx = -30; # "OS Extreme"
#////////////////////////////////////////////////////////////////////////////////
#// ====== FUNCTIONS ====== //
#////////////////////////////////////////////////////////////////////////////////
#// zero median rsi helper function, just subtracts 50.
script f_zrsi {
input _source = ohlc4;
input _length = 0;
def RSI = RSI(PRICE = _source, LENGTH = _length ) - 50;
plot return = RSI;
}
script f_rsi { #f_rsi( i_source, i_lenRSI, i_mode )
input _source = ohlc4;
input _length = 0;
input _mode = yes;
def _zrsi = f_zrsi( _source, _length );
def _smoothed = if IsNaN( _smoothed[1] ) then _zrsi else ( _smoothed[1] + _zrsi ) / 2;
def f_rsi = if _mode then _smoothed else _zrsi;
plot return = f_rsi;
}
#// RSI Heikin-Ashi generation function
script nz {
input data = 0;
input replacement = 0;
def ret_val = if IsNaN(data) then replacement else data;
plot return = ret_val;
}
script f_Close { #f_Close(i_lenHARSI)
input _length = 0;
def _closeRSI = f_zrsi( close, _length);
def _openRSI = nz( _closeRSI[1], _closeRSI );
def _highRSI_raw = f_zrsi( high, _length );
def _lowRSI_raw = f_zrsi( low, _length );
def _highRSI = Max( _highRSI_raw, _lowRSI_raw );
def _lowRSI = Min( _highRSI_raw, _lowRSI_raw );
def _close = ( _openRSI + _highRSI + _lowRSI + _closeRSI ) / 4;
plot return = _close;
}
script f_Open { #f_Open(i_lenHARSI, i_smoothing)
input _length = 0;
input _smoothing = 1;
def _closeRSI = f_zrsi( close, _length);
def _openRSI = nz( _closeRSI[1], _closeRSI );
def _open = if IsNaN ( _open[_smoothing]) then ( _openRSI + _closeRSI ) / 2 else
(( _open[1] * _smoothing ) + f_Close(_length)[1]) / (_smoothing + 1 );
plot return = _open;
}
script f_High { #f_High(i_lenHARSI , i_smoothing)
input _length = 0;
input _smoothing = 1;
def _highRSI_raw = f_zrsi( high, _length );
def _lowRSI_raw = f_zrsi( low, _length );
def _highRSI = Max( _highRSI_raw, _lowRSI_raw );
def _high = Max( _highRSI, Max(f_Open(_length, _smoothing), f_Close(_length)));
plot return = _high;
}
script f_Low { #f_Low(i_lenHARSI , i_smoothing)
input _length = 0;
input _smoothing = 1;
def _highRSI_raw = f_zrsi( high, _length );
def _lowRSI_raw = f_zrsi( low, _length );
def _lowRSI = Min( _highRSI_raw, _lowRSI_raw );
def _low = Min( _lowRSI, Min(f_Open(_length, _smoothing), f_Close(_length)));
plot return = _low ;
}
#////////////////////////////////////////////////////////////////////////////////
#// ====== SERIES, LINES and LABELS ====== //
#////////////////////////////////////////////////////////////////////////////////
#// standard, or ha smoothed rsi for the line plot and/or histogram
def RSI = f_rsi( i_source, i_lenRSI, i_mode );
plot RSI_OL = if i_showPlot then RSI else na;
RSI_OL.setDefaultColor(GlobalColor("RSI"));
def o = f_Open(i_lenHARSI, i_smoothing);
def h = f_High(i_lenHARSI , i_smoothing);
def l = f_Low(i_lenHARSI , i_smoothing);
def c = f_Close(i_lenHARSI);
def isExp = AbsValue( c - o ) >= AbsValue( c[1] - o[1]);
# Plot UP candle with isBull only
def UpO1; def UpH1; def UpL1; def UpC1;
if o < c then {UpO1 = o ; UpH1 = h ; UpL1 = l ; UpC1 = c; } else
{UpO1 = na; UpH1 = na; UpL1 = na; UpC1 = na;}
# Plot UP candle with isBull and isExp
def UpO; def UpH; def UpL; def UpC;
if o < c and isExp then {UpO = o ; UpH = h ; UpL = l ; UpC = c; } else
{UpO = na; UpH = na; UpL = na; UpC = na;}
# Plot DOWN candle
def DnO; def DnH; def DnL; def DnC;
if o > c and !isExp then {DnO = o ; DnH = h ; DnL = l ; DnC = c; } else
{DnO = na; DnH = na; DnL = na; DnC = na;}
# Plot DOWN candle with !isBull and !isExp
def DnO1; def DnH1; def DnL1; def DnC1;
if o > c then {DnO1 = o ; DnH1 = h ; DnL1 = l ; DnC1 = c; } else
{DnO1 = na; DnH1 = na; DnL1 = na; DnC1 = na;}
# Plot the new Chart
AddChart(high = UpH1, low = UpL1, open = UpC1, close = UpO1,
type = ChartType.CANDLE, growcolor = GlobalColor("UPTICK"));
AddChart(high = UpH , low = UpL , open = UpC, close = UpO,
type = ChartType.CANDLE, growcolor = GlobalColor("UP"));
AddChart(high = DnH1, low = DnL1, open = DnO1, close = DnC1,
type = ChartType.CANDLE, growcolor = GlobalColor("DOWNTICK"));
AddChart(high = DnH , low = DnL , open = DnO, close = DnC,
type = ChartType.CANDLE, growcolor = GlobalColor("DOWN"));
#####
def upperx = i_upperx;
#upperx.SetDefaultColor(Color.DARK_RED);
#upperx.SetStyle(Curve.FIRM);
def upper = i_upper;
#upper.SetDefaultColor(Color.DARK_RED);
#upper.SetStyle(Curve.SHORT_DASH);
plot median = 0;
#median.SetDefaultColor(Color.DARK_GRAY);
#median.SetStyle(Curve.LONG_DASH);
def lower = i_lower;
#lower.SetDefaultColor(Color.DARK_GREEN);
#lower.SetStyle(Curve.SHORT_DASH);
def lowerx = i_lowerx;
#lowerx.SetDefaultColor(Color.DARK_GREEN);
#lowerx.SetStyle(Curve.FIRM);
addcloud (upperx, upper, color.dark_red,color.dark_red,no);
addcloud (lower, lowerx, color.dark_green,color.dark_green,no);
Last edited by a moderator: