HARSI Indicator conversion from tradingview
Forums › ProRealTime English forum › ProBuilder support › HARSI Indicator conversion from tradingview
- This topic has 7 replies, 7 voices, and was last updated 1 year ago by robertogozzi.
Tagged: HARSI, RSI, Stochastic
-
-
01/07/2022 at 8:56 PM #184852
Hello everyone,
I’d like to use this HARSI Indicator (from JayRogers) from tradingview on Prorealtime as I find it very useful. Does someone know how to convert the code from tradingview to prorealtime? Or by any chance is there the exact same indicator already existing on the forum (couldn’t seem to find it though).
Thanks
Here is the Tradingview code :
HARSI Indicator (for Tradingview by JayRogers)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249// This source code is free to use, copy, and alter in any way you choose.// ...but credit is always nice :)//@version=4//@author=JayRogersstudy( "Heikin Ashi RSI Oscillator", "HARSI •", false, format.price, 2 )////////////////////////////////////////////////////////////////////////////////// //// ====== ABOUT THIS INDICATOR //// //// - RSI based Heikin Ashi candle oscillator //// //// ====== ARTICLES and FURTHER READING //// //// - https://www.investopedia.com/terms/h/heikinashi.asp //// //// "Heikin-Ashi is a candlestick pattern technique that aims to reduce //// some of the market noise, creating a chart that highlights trend //// direction better than typical candlestick charts" //// //// ====== REASON FOR STUDY //// //// - Mostly experimental. I wanted to see if I could translate RSI into a //// Heikin Ashi function and retain it's oscillating nature. That goal //// was met more easily than I anticipated with quite delightful results. //// //// ====== DISCLAIMER //// //// Any trade decisions you make are entirely your own responsibility. //// I've made an effort to squash all the bugs, but you never know! //// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //// ====== TOOLTIPS ====== //// //////////////////////////////////////////////////////////////////////////////////string TT_HARSI = "Period for the RSI calculations used to generate the" +"candles. This seperate from the RSI plot/histogram length."string TT_PBIAS = "Smoothing feature for the OPEN of the HARSI candles." +"\n\nIncreases bias toward the prior open value which can" +" help provide better visualisation of trend strength." +"\n\n** By changing the Open values, High and Low can also" +" be distorted - however Close will remain unchanged."string TT_SMRSI = "This option smoothes the RSI in a manner similar to HA" +" open, but uses the realtime rsi rather than the prior" +" close value."string TT_STOCH = "Uses the RSI generated by the above settings, and as such" +" will be affected by the smoothing option."string TT_STFIT = "Adjusts the vertical scaling of the stochastic, can help" +" to prevent distortion of other data in the channel." +"\n\nHas no impact cross conditions."////////////////////////////////////////////////////////////////////////////////// //// ====== INPUTS ====== //// //////////////////////////////////////////////////////////////////////////////////// -- Candle configstring GROUP_CAND = "Config » HARSI Candles"i_lenHARSI = input( 14, "Length", input.integer, group = GROUP_CAND,minval = 1, tooltip = TT_HARSI )i_smoothing = input( 1, "Open Smoothing", input.integer, group = GROUP_CAND,minval = 1, maxval = 100, tooltip = TT_PBIAS )string INLINE_COL = "Colour Pallette"i_colUp = input( color.teal, "Colour Pallette ", input.color, group = GROUP_CAND, inline = INLINE_COL )i_colDown = input( color.red, " ", input.color, group = GROUP_CAND, inline = INLINE_COL )i_colWick = input( color.gray, " ", input.color, group = GROUP_CAND, inline = INLINE_COL )// -- RSI plot configstring GROUP_PLOT = "Config » RSI Plot"i_source = input( ohlc4, "Source", input.source, group = GROUP_PLOT )i_lenRSI = input( 7, "Length", input.integer, group = GROUP_PLOT,minval = 1 )i_mode = input( true, "Smoothed Mode RSI?", input.bool, group = GROUP_PLOT,tooltip = TT_SMRSI )i_showPlot = input( true, "Show RSI Plot?", input.bool, group = GROUP_PLOT )i_showHist = input( true, "Show RSI Histogram?", input.bool, group = GROUP_PLOT )// -- Stochastic RSI plots configstring GROUP_STOCH = "Config » Stochastic RSI Plot"string INLINE_STDS = "Stoch Draw States"i_showStoch = input( false, "Show Stochastic? ", input.bool, group = GROUP_STOCH, inline = INLINE_STDS,tooltip = TT_STOCH )i_ribbon = input( true, "Ribbon?", input.bool, group = GROUP_STOCH, inline = INLINE_STDS )i_smoothK = input( 3, "Smoothing K", input.integer, group = GROUP_STOCH,minval = 1 )i_smoothD = input( 3, "Smoothing D", input.integer, group = GROUP_STOCH,minval = 1 )i_stochLen = input( 14, "Stochastic Length", input.integer, group = GROUP_STOCH,minval = 1 )i_stochFit = input( 80, "Stoch Scaling %", input.integer, group = GROUP_STOCH,minval = 1, maxval = 100, tooltip = TT_STFIT )// -- Channel OB/OS configstring GROUP_CHAN = "Config » OB/OS Boundaries"i_upper = input( 20, "OB", input.integer, group = GROUP_CHAN, inline = "OB",minval = 1, maxval = 50 )i_upperx = input( 30, "OB Extreme", input.integer, group = GROUP_CHAN, inline = "OB",minval = 1, maxval = 50 )i_lower = input( -20, "OS", input.integer, group = GROUP_CHAN, inline = "OS",minval = -50, maxval = -1 )i_lowerx = input( -30, "OS Extreme", input.integer, group = GROUP_CHAN, inline = "OS",minval = -50, maxval = -1 )////////////////////////////////////////////////////////////////////////////////// //// ====== FUNCTIONS ====== //// //////////////////////////////////////////////////////////////////////////////////// zero median rsi helper function, just subtracts 50.f_zrsi( _source, _length ) => rsi( _source, _length ) - 50// zero median stoch helper function, subtracts 50 and includes % scalingf_zstoch( _source, _length, _smooth, _scale ) =>float _zstoch = stoch( _source, _source, _source, _length) - 50float _smoothed = sma( _zstoch, _smooth )float _scaled = ( _smoothed / 100 ) * _scale// mode selectable rsi function for standard, or smoothed outputf_rsi( _source, _length, _mode ) =>// get base rsifloat _zrsi = f_zrsi( _source, _length )// smoothing in a manner similar to HA open, but rather using the realtime// rsi in place of the prior close value.var float _smoothed = na_smoothed := na( _smoothed[1] ) ? _zrsi : ( _smoothed[1] + _zrsi ) / 2// return the requested mode_mode ? _smoothed : _zrsi// RSI Heikin-Ashi generation functionf_rsiHeikinAshi( _length ) =>// get close rsifloat _closeRSI = f_zrsi( close, _length )// emulate "open" simply by taking the previous close rsi valuefloat _openRSI = nz( _closeRSI[1], _closeRSI )// the high and low are tricky, because unlike "high" and "low" by// themselves, the RSI results can overlap each other. So first we just go// ahead and get the raw results for high and low, and then..float _highRSI_raw = f_zrsi( high, _length )float _lowRSI_raw = f_zrsi( low, _length )// ..make sure we use the highest for high, and lowest for lowfloat _highRSI = max( _highRSI_raw, _lowRSI_raw )float _lowRSI = min( _highRSI_raw, _lowRSI_raw )// ha calculation for closefloat _close = ( _openRSI + _highRSI + _lowRSI + _closeRSI ) / 4// ha calculation for open, standard, and smoothed/laggedvar float _open = na_open := na( _open[ i_smoothing ] ) ? ( _openRSI + _closeRSI ) / 2 :( ( _open[1] * i_smoothing ) + _close[1] ) / ( i_smoothing + 1 )// ha high and low min-max selectionsfloat _high = max( _highRSI, max( _open, _close ) )float _low = min( _lowRSI, min( _open, _close ) )// return the OHLC values[ _open, _high, _low, _close ]////////////////////////////////////////////////////////////////////////////////// //// ====== SERIES, LINES and LABELS ====== //// //////////////////////////////////////////////////////////////////////////////////// standard, or ha smoothed rsi for the line plot and/or histogramfloat RSI = f_rsi( i_source, i_lenRSI, i_mode )// stoch stufffloat StochK = f_zstoch( RSI, i_stochLen, i_smoothK, i_stochFit )float StochD = sma( StochK, i_smoothD )// get OHLC values to use in the plotcandle()[ O, H, L, C ] = f_rsiHeikinAshi( i_lenHARSI )// candle body colouringcolor bodyColour = C > O ? i_colUp : i_colDowncolor wickColour = i_colWick// shadow, invisiblecolor colShadow = color.rgb( 0, 0, 0, 20 )color colNone = color.rgb( 0, 0, 0, 100 )// rsi colorcolor colRSI = color.rgb( 250, 200, 50, 0 )// stoch ribbon fillcolor colStochK = color.new( #0094FF, 0 )color colStochD = color.new( #FF6A00, 0 )color colStochFill = StochK >= StochD ? color.new( colStochK, 50 ) : color.new( colStochD, 50 )////////////////////////////////////////////////////////////////////////////////// //// ====== DRAWING and PLOTTING ====== //// //////////////////////////////////////////////////////////////////////////////////// zero median RSI channel hlinesupperx = hline( i_upperx, "OB Extreme", color.new( color.silver, 60 ) )upper = hline( i_upper, "OB", color.new( color.silver, 80 ) )median = hline( 0, "Median", color.orange, hline.style_dotted )lower = hline( i_lower, "OS", color.new( color.silver, 80 ) )lowerx = hline( i_lowerx, "OS Extreme", color.new( color.silver, 60 ) )// channel fillfill( upper, upperx, color.new( color.red, 90 ), title = "Background Fill OB" )fill( upper, lower, color.new( color.blue, 90 ), title = "Background Channel" )fill( lower, lowerx, color.new( color.green, 90 ), title = "Background Fill OS" )// histogram first, so it is on the bottom of the plot/candle draw stackplot( i_showHist ? RSI : na, "RSI Histogram", color.new( color.silver, 80 ), 1, plot.style_histogram )// make our HA rsi candlesplotcandle( O, H, L, C, "HARSI", bodyColour, wickColour, bordercolor = bodyColour )// RSI overlay plotplot( i_showPlot ? RSI : na, "RSI Shadow", colShadow, 3 )plot_rsi = plot( i_showPlot ? RSI : na, "RSI Overlay", colRSI, 1 )// Stochastic RSI plots and fillplot( i_showStoch ? StochK : na, "Stoch K Shadow", not i_ribbon ? colShadow : colNone, 3 )plot( i_showStoch ? StochD : na, "Stoch D Shadow", not i_ribbon ? colShadow : colNone, 3 )plot_stochK = plot( i_showStoch ? StochK : na, "Stoch K", not i_ribbon ? colStochK : colNone, 1 )plot_stochD = plot( i_showStoch ? StochD : na, "Stoch D", not i_ribbon ? colStochD : colNone, 1 )fill( plot_stochK, plot_stochD, i_ribbon ? colStochFill : na )// -- PEANUT01/11/2022 at 8:23 PM #18518506/03/2022 at 9:19 AM #194528I translated the RSI part and skipped the Stochastics. Hope this helps.
HARSI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455//variables: rsip=7, smoothing=1, halength=14rsihelp= RSI[rsip]((high+close+low+open)/4)-50rsihelp2= RSI[halength]((high+close+low+open)/4)-50closersi2= rsi[halength](close)-50if barindex>0 thenopenrsi2=rsi[halength](close[1])-50elseopenrsi2=rsi[halength](close)-50endifrsihighraw2= rsi[halength](high)-50rslowraw2= rsi[halength](low)-50rsihigh2= max(rsihighraw2,rslowraw2)rsilow2=min(rsihighraw2,rslowraw2)haclose= (closersi2+openrsi2+rsihigh2+rsilow2)/4if barindex > halength+2 thenhaopen = ((haopen[1]*smoothing) +haclose[1])/(smoothing+1)elsehaopen = (closersi2 +openrsi2)/2endifhahigh= max(rsihigh2, max(haopen,haclose))halow = min(rsilow2 , min( haopen, haclose))if haclose > haopen thenr=0g=153b=153elser=238g=73b=73endifDRAWCANDLE(haopen, hahigh, halow, haclose) COLOURED(r,g,b) BORDERCOLOR(R,G,B)if barindex > rsip thenrsismoothed = (rsismoothed[1]+ rsihelp)/2elsersismoothed = rsihelpendifreturn rsismoothed as "RSI-Smoothed", 0 as "0", 30 as "30", 20 as "20", -20 as "-20", -30 as "-30"3 users thanked author for this post.
06/07/2022 at 9:39 PM #19487110/01/2023 at 10:37 PM #22191710/02/2023 at 6:42 AM #22191810/02/2023 at 1:54 PM #221945Le même mais avec l’échelle de 0 à 100 comme un RSI conventionnel, ainsi on peut le coller dans d’autres indicateurs de même échelle.The same but with the scale from 0 to 100 like a conventional RSI, so it can be pasted into other indicators of the same scale.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455// HARSI by JS le 02.10.2023 modifié 02.10.2023defparam calculateonlastbars = 150//variables:rsip=7smoothing=1halength=14rsihelp= RSI[rsip]((high+close+low+open)/4)//-50rsihelp2= RSI[halength]((high+close+low+open)/4)//-50closersi2= rsi[halength](close)//-50if barindex>0 thenopenrsi2=rsi[halength](close[1])//-50elseopenrsi2=rsi[halength](close)//-50endifrsihighraw2= rsi[halength](high)//-50rslowraw2= rsi[halength](low)//-50rsihigh2= max(rsihighraw2,rslowraw2)rsilow2=min(rsihighraw2,rslowraw2)haclose= (closersi2+openrsi2+rsihigh2+rsilow2)/4if barindex > halength+2 thenhaopen = ((haopen[1]*smoothing) +haclose[1])/(smoothing+1)elsehaopen = (closersi2 +openrsi2)/2endifhahigh= max(rsihigh2, max(haopen,haclose))halow = min(rsilow2 , min( haopen, haclose))if haclose > haopen thenr=0g=153b=153elser=238g=73b=73endifDRAWCANDLE(haopen, hahigh, halow, haclose) COLOURED(r,g,b) BORDERCOLOR(R,G,B)if barindex > rsip thenrsismoothed = (rsismoothed[1]+ rsihelp)/2elsersismoothed = rsihelpendifreturn rsismoothed as "RSI-Smoothed", 20 as "20", 30 as "30", 70 as "70", 80 as "80"1 user thanked author for this post.
10/02/2023 at 3:43 PM #221952Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums
Thank you 🙂
-
AuthorPosts
Find exclusive trading pro-tools on