Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // Copyright (c) 2019-present, Eric Robinson (@CoffeeshopCrypto) https://www.tradingview.com/u/CoffeeshopCrypto/
- // CoffeeShopCrypto HARSI script may be freely distributed under the terms of the GPL-3.0 license.
- // This is an ongoing project that i will continue to develope so it can match more markets as an all in one.
- //Currently this is widely used for CRYPTO and FOREX markets.
- indicator(title="Heiken Ashi Algo Oscillator", shorttitle="Heiken Ashi Algo v3", format=format.price, precision=2, explicit_plot_zorder = true)
- //Plotting the HA Candles according to the RSI level
- //This is the new 2022 version of the HARSI Originally done by @JayRogers
- //Heiken Ashi
- // inputs for a later use
- //RSILengthInput = 14
- //RSILength2Input = 3.5 * 14
- //HAlengthInput = RSILengthInput
- //RSIMA2Lenth = RSILengthInput
- HAp1 = input(14, title = "Open Length", tooltip="Set each of these to the bar length for your trading style.", group="Heiken Ashi O-H-L-C Smoothing")
- HAp2 = input(14, title = "High Length", group="Heiken Ashi O-H-L-C Smoothing")
- HAp3 = input(14, title = "Low Length", group="Heiken Ashi O-H-L-C Smoothing")
- HAp4 = input(14, title = "Close Length", group="Heiken Ashi O-H-L-C Smoothing")
- //_____________________________________________________
- //calcs
- // 4 rsi calculations
- r1 = ta.rsi(close, HAp1)
- r2 = ta.rsi(close, HAp2)
- r3 = ta.rsi(close, HAp3)
- r4 = ta.rsi(close, HAp4)
- //array, stores rsi values, sorts them
- heikinarray = array.new_float(0, 0)
- array.push(heikinarray, r1)
- array.push(heikinarray, r2)
- array.push(heikinarray, r3)
- array.push(heikinarray, r4)
- array.sort(heikinarray, order.descending)
- // assign open, high, low, ,close
- h = array.get(heikinarray, 1)
- c = array.get(heikinarray, 3)
- o = array.get(heikinarray, 0)
- l = array.get(heikinarray, 2)
- //_____________________________________________________
- // Heikin Ashi source function allows for different inputs
- src(_o, _h, _l, _c, _src) =>
- Close = (_o+_h+_l+_c)/4
- Open = float(na)
- Open := na(Open[1]) ? (_o + _c) / 2 : (nz(Open[1]) + nz(Close[1])) / 2
- High = math.max(_h, math.max(Open, Close))
- Low = math.min(_l, math.min(Open, Close))
- HL2 = math.avg(High, Low)
- HLC3 = math.avg(High, Low, Close)
- OHLC4 = math.avg(Open, High, Low, Close)
- Price = _src == 'close' ? Close : _src == 'open' ? Open : _src == 'high' ? High : _src == 'low' ? Low : _src == 'hl2' ? HL2 : _src == 'hlc3' ? HLC3 : OHLC4
- hi = src(o, h, l, c, 'high' ) - 50
- cl = src(o, h, l, c, 'close') - 50
- op = src(o, h, l, c, 'open' ) - 50
- lo = src(o, h, l, c, 'low' ) - 50
- hi1 = src(op, hi, lo, cl, 'high' )
- cl1 = src(op, hi, lo, cl, 'close')
- op1 = src(op, hi, lo, cl, 'open' )
- lo1 = src(op, hi, lo, cl, 'low' )
- //_____________________________________________________
- barColor = cl1 > op1 ? color.new(#4caf50, 25) : color.new(#f77c80, 25) // series color
- wikColor = cl1 > op1 ? color.new(#4caf50, 25) : color.new(#f77c80, 25)
- brDrcolor = cl1 > op1 ? color.new(#131722, 25) : color.new(#131722, 25)
- /////End Heiken Ashi Candles
- //Lets get to working on the Slow Stochastic RSI
- smoothK = input.int(8, title="Stochastic K%", minval=1, group="Slow Stochastic Inputs")
- smoothD = input.int(3, title="Stochastic D%", minval=1, group="Slow Stochastic Inputs")
- lengthRSI = input.int(21, "Stochastic RSI Length", minval=1, group="Slow Stochastic Inputs")
- lengthStoch = input.int(50, "Stochastic Length", minval=1, group="Slow Stochastic Inputs")
- src = input(close, title="Stochastic RSI Source", group="Slow Stochastic Inputs")
- rsi1 = ta.rsi(src, lengthRSI)
- k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK) - 50
- d = ta.sma(k, smoothD)
- p1 = plot(k, title="Stochastic K%", color=color.new(#5de661, 100), editable=true, display=display.none - display.status_line)
- p2 = plot(d, title="Stochastic D%", color=color.new(#a12a2a, 100), editable=true, display=display.none - display.status_line)
- h0 = hline(80, "Upper Band", color=#787B86, editable=false, display=display.none)
- hline0 = hline(0, "Middle Band", color=color.new(#cc5b1f, 20))
- h1 = hline(20, "Lower Band", color=#787B86,editable=false, display=display.none)
- fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background", editable=false, display=display.none)
- fill(title = "Slow Stochastic RSI Ribbon", plot1 = p1, plot2 = p2, color = k >= d ? color.new(#5de661, 15) : color.new(#a12a2a, 15), display=display.all)
- ///////Lets get back to the rest of the plotting. OH THE PLOTTING HAS ME PLOTZED//
- //plot(rsiMA, "RSI-based MA", color=color.orange, linewidth=1, editable=false, style=plot.style_line, display=display.none)
- rsiUpperBandOB = hline(30, "RSI Overbought", color=#787B86, display=display.none)
- rsiUpperBandOS = hline(-30, "RSI OverSold", color=#787B86, display=display.none)
- rsiUpperBand = hline(20, "RSI Upper Band", color=#787B86, display=display.none)
- rsiLowerBand = hline(-20, "RSI Lower Band", color=#787B86, display=display.none)
- hMIDhi = hline(10, "Upper Mid Band", color=color.new(#00e677, 60), linestyle=hline.style_solid)
- hMIDlo = hline(-10, "Lower Mid Band", color=color.new(#a12a2a, 60), linestyle=hline.style_solid)
- fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background", display=display.none)
- fill(rsiUpperBandOB, rsiUpperBand, color=color.new(#a12a2a, 80), title="Overbought Background", display = display.none)
- fill(rsiUpperBandOS, rsiLowerBand, color=color.new(#00E676, 80), title="Oversold Background", display = display.none)
- fill(hMIDhi, hMIDlo, color=color.new(#3179f5, 94), title="Midrange Background", display = display.none)
- fill(hline0, rsiUpperBandOB, 30, 0, top_color = color.rgb(21, 122, 34, 70), bottom_color = color.rgb(186, 189, 185, 100))
- fill(hline0, rsiUpperBandOS, 0, -30, top_color = color.rgb(186, 189, 185, 100), bottom_color = color.rgb(189, 60, 27, 70))
- //-----------------------END RSI UPDATED-----------------------------
- //Lets start with the secondary Stripped RSI with only the Moving averages.
- //------------------------------------------------------------------------------
- //RSI Stripped plotted
- ma2(source, length, type) =>
- switch type
- "SMA" => ta.sma(source, length)
- "EMA" => ta.ema(source, length)
- "SMMA (RMA)" => ta.rma(source, length)
- "WMA" => ta.wma(source, length)
- "VWMA" => ta.vwma(source, length)
- "LSMA" => ta.linreg(source, length, offset=0)
- "VWAP" => ta.vwap(source)
- rsi2LengthInput = input.int(14, title="RSI Length", group="Relative Strength Input Settings")
- rsi2SourceInput = input(close, "RSI Source", group="Relative Strength Input Settings")
- ma2LengthInput = input.int(14, title="RSI MA Length", group="RSI MA Settings")
- ma2TypeInput = input.string("SMA", title="RSI MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "VWAP"], tooltip="Smooths the HA candles.", group="RSI MA Settings")
- ma3TypeInput = input.string("SMA", title="RSI Trend MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "VWAP"], tooltip="Smooths the HA candles.", group="RSI MA Settings")
- //Coloring the RSIma
- color rsi2MABull = input.color(color.new(#66bb6a, 0), title="Bull RSI MA", group="RSI MA Settings")
- color rsi2MABear = input.color(color.new(#eb4949, 0), title="Bear RSI MA", group="RSI MA Settings")
- float RSIma2 = ta.sma(rsi2SourceInput, rsi2LengthInput)
- //Coloring the RSIma2
- color rsi3MABull = input.color(color.new(#66bb6a, 0), title="Bull RSI Trend", group="RSI MA Settings")
- color rsi3MABear = input.color(color.new(#eb4949, 0), title="Bear RSI Trend", group="RSI MA Settings")
- float RSIma3 = ta.sma(rsi2SourceInput, rsi2LengthInput)
- /// MA Colors End//
- //twooffset=input(title="RSI MA Offset", defval=0, group="RSI MA Settings")
- //Save the Rising Falling ma color status
- bool rsi2MARising = ta.rising(RSIma2, 1)
- bool rsi3MARising = ta.rising(RSIma2, 1)
- twoup = ta.rma(math.max(ta.change(rsi2SourceInput), 0), rsi2LengthInput)
- twodown = ta.rma(-math.min(ta.change(rsi2SourceInput), 0), rsi2LengthInput)
- rsi2 = twodown == 0 ? 100 : twoup == 0 ? 0 : 100 - (100 / (1 + twoup / twodown)) - 50
- rsiMA2 = ma2(rsi2, ma2LengthInput, ma2TypeInput)
- rsiMA3 = ma2(rsi2, ma2LengthInput, ma3TypeInput) / 3.5
- ///RSI Pivots//
- // Pivot Trendline Inputs
- pivot_high_low_trendline_lookback = input.int(7, title="RSI Trendline Lookback", group="Trendlines and Pivots")
- // Pivot high/low calculation
- pivot_high = rsi2 == ta.highest(rsi2, pivot_high_low_trendline_lookback)
- pivot_low = rsi2 == ta.lowest(rsi2, pivot_high_low_trendline_lookback)
- /////End Saved MA Colors and status////
- //////////////Secondary RSI MA////////////////////////////
- //BUY and SELL indications
- //Buy sell Strategy
- // Buy sell Plots
- //Buy Sell Alerts
- ///Setting Colors and limitations for the RSI Trend Cloud with YELLOW rsi trend
- float maxLine = -10
- float minLine = 10
- bool rsiBullish = rsi2 > rsiMA2
- color topColor = rsiBullish ? color.new(#4b0000, 0) : color.new(#f23645, 20)
- color botColor = rsiBullish ? color.new(#ffeb3b, 20) : color.new(#040c09, 0)
- float topLineValue = rsiBullish ? maxLine : maxLine
- float botLineValue = rsiBullish ? minLine : minLine
- ///Adjusting for background color of RSI MA trend
- //rsiup = rsi2 > rsiMA2 and rsiMA2 > rsiMA3 and rsi2 > 0 and op1 < cl1 and cl1 > 10
- rsiup = rsi2 > rsiMA2 and rsi2 > 0 and op1 < cl1 and op1 > rsiMA3
- rsidown = rsi2 < rsiMA2 and rsiMA2 < rsiMA3 and rsi2 < 0 and op1 > cl1 and cl1 < 10
- RSIMAbackgroundColour = rsiup ? color.new(#07d40e, 75) : rsidown ? color.new(#f7525f, 75) : na
- //////////////////////
- ///Setting Colors and limitations for the RSIMA Trend Cloud
- float MAmaxLine = -20
- float MAminLine = 20
- bool rsiMABullish = rsiMA2 > rsiMA3
- color MAtopColor = rsiMABullish ? color.new(#0bff14, 0) : color.new(#3e0a0f, 20)
- color MAbotColor = rsiMABullish ? color.new(#145a16, 55) : color.new(#5e1b1b, 0)
- float MAtopLineValue = rsiMABullish ? MAmaxLine : MAmaxLine
- float MAbotLineValue = rsiMABullish ? MAminLine : MAminLine
- //Plotting the RSI Trend Cloud
- rsiPlot = plot(rsi2, title="RSI", color=#f6fa0500, linewidth=1, style=plot.style_line)
- //RSI MA Trend Cloud
- //Up and down color plotting for the RSI MA///
- color cld_ma = rsiMA2 > 0 ? color.green : color.red
- //color cld_ma = rsi2MARising ? rsi2MABull : rsi2MABear
- color cld_ma2 = rsi3MARising ? rsi2MABull : rsi2MABear
- // Plot pivot high/low
- plot(pivot_high ? rsi2 : na, color=color.green, style=plot.style_line, linewidth=1, title="Pivot High Trendline", display = display.all - display.status_line)
- plot(pivot_low ? rsi2 : na, color=color.red, style=plot.style_line, linewidth=1, title="Pivot Low Trendline", display = display.all - display.status_line)
- plot(rsiMA2, title="ma", color=cld_ma, linewidth=2, style=plot.style_line, display=display.all)
- // Plot blue horizontal line from pivot low to next pivot low with a lower value
- var float pivot_low_trendline = na
- for i = 0 to rsi2LengthInput - 1
- if pivot_low[i]
- pivot_low_trendline := rsi2[i]
- for j = i + 1 to rsi2LengthInput - 1
- if pivot_low[j] and rsi2[j] > pivot_low_trendline
- pivot_low_trendline := rsi2[j]
- break
- //
- var float pivot_high_trendline = na
- for i = 0 to rsi2LengthInput - 1
- if pivot_high[i]
- pivot_high_trendline := rsi2[i]
- for j = i + 1 to rsi2LengthInput - 1
- if pivot_high[j] and rsi2[j] < pivot_high_trendline
- pivot_high_trendline := rsi2[j]
- break
- plot(pivot_high_trendline, color=color.rgb(0, 226, 215), linewidth=1, title="Pivot High", style=plot.style_line, display = display.all - display.status_line)
- plot(pivot_low_trendline, color=color.rgb(190, 122, 19), linewidth=1, title="Pivot Low", style=plot.style_line, display = display.all - display.status_line)
- //////////////////////////////////////////////
- //Study for resistance support long and short
- rsi_resistance = (rsi2[1] == pivot_high_trendline) and rsi2 < pivot_high_trendline
- rsi_support = (rsi2[1] == pivot_low_trendline) and rsi2 > pivot_low_trendline
- plotshape(rsi_resistance, title="Resistance", style=shape.labeldown, location=location.top, color=color.red, text="R", textcolor = color.rgb(224, 208, 208), display=display.all - display.status_line)
- plotshape(rsi_support, title="Support", style=shape.labelup, location=location.bottom, color=color.green, text="S", textcolor = color.rgb(255, 255, 255, 12), display=display.all - display.status_line)
- ////End of new color condition plotting///
- //Study to mark all DOJI HA Candles
- BullDoji = op1 < cl1 and hi1 > cl1 and lo1 < op1
- BullDoLong = op1 < cl1 and op1 < 10 and cl1 > 10 and op1[1] < cl1[1] and hi1[1] > cl1[1] and lo1[1] < op1[1]
- BearDoShort = op1 > cl1 and op1 > -10 and cl1 < -10 and op1[1] > cl1[1] and hi1[1] > op1[1] and lo1[1] < cl1[1]
- //DojLongExit = op1[1] < cl1[1] and op1 > cl1 and lo1 < lo1[1] and hi1 > op1 and lo1 < cl1 and rsi2[1] > 20 and cl1[1] > 20 and ultraSmooth_stochastic[1] > ultraSmooth_stochastic
- //DojShortExit = op1[1] > cl1[1] and op1 < cl1 and hi1 > hi1[1] and lo1 < op1 and hi1 > cl1 and rsi2[1] < -20 and cl1[1] < -20 and ultraSmooth_stochastic[1] < ultraSmooth_stochastic
- BearDoji = op1 > cl1 and hi1 > op1 and lo1 < cl1
- plotshape(BullDoLong, title="Imbalance", style=shape.labelup, location=location.bottom, color=color.rgb(35, 167, 8), textcolor=color.rgb(255, 255, 255), text="Imbalance", display=display.all - display.status_line)
- plotshape(BearDoShort, title="Imbalance", style=shape.labeldown, location=location.top, color=color.rgb(221, 14, 14), textcolor=color.rgb(255, 255, 255), text="Imbalance", display=display.all - display.status_line)
- alertcondition(BullDoLong or BearDoShort, title="Imbalance", message="Imbalance Alert")
- //plotshape(DojLongExit, title="LDojExit", style=shape.labeldown, location=location.top, color=color.rgb(221, 14, 14), textcolor=color.rgb(255, 255, 255), text="Doj Long Exit", display=display.none - display.status_line)
- //plotshape(DojShortExit, title="SDojExit", style=shape.labelup, location=location.bottom, color=color.rgb(35, 167, 8), textcolor=color.rgb(255, 255, 255), text="Doj Short Exit", display=display.none - display.status_line)
- ////////////////////////////////////
- //Poltting Order Blocks
- //condition = DojLongExit
- //Orderblock = ta.valuewhen(DojLongExit, open, 1)
- //DLE = array.new_line(1, DojLongExit)
- //line.delete(DLE[5])
- rsiAveragePlot = plot(rsiMA2, title="Average RSI Up Down", color = cld_ma, linewidth=1, display=display.none)
- //bgcolor(color=RSIMAbackgroundColour, transp=85,
- // title="RSIMA coloured background")
- rsiAveragePlot2 = plot(rsiMA3, title="RSI Trend Direction", color = cld_ma2, linewidth=1, display=display.none)
- //rsiAveragePlot = plot(rsiMA2, title="RSI Moving Average", color=color.new(#0096a7, 100), linewidth=1, style=plot.style_line)
- //Plot for Trend Fill
- colUp = rsi2 > 0 ? input.color(color.new(#fffdfd, 0), '', group= 'RSI Trend Colors', inline= 'up') :
- input.color(color.rgb(167, 9, 9, 38), '', group= 'RSI Trend Colors', inline= 'dn')
- colDn = rsi2 > 0 ? input.color(color.new(#207407, 48), '', group= 'RSI Trend Colors', inline= 'up') :
- input.color(color.new(#ffe602, 0), '', group= 'RSI Trend Colors', inline= 'dn')
- //
- color itopColor = rsiBullish ? color.rgb(75, 0, 0) : color.new(#f23645, 20)
- color ibotColor = rsiBullish ? color.new(#ffeb3b, 20) : color.new(#040c09, 0)
- hline_center = plot(0, title="hidden midline", display = display.none, editable = false)
- fill(rsiPlot, hline_center, rsi2 > 0 ? 30 : 0, rsi2 > 0 ? 0 : -30, colUp, colDn, title="RSI Trend")
- fill(rsiAveragePlot, rsiAveragePlot2, MAtopLineValue, MAbotLineValue, MAtopColor, MAbotColor, title="RSI Moving Average Trend", display = display.none)
- fill(rsiPlot, rsiAveragePlot, topLineValue, botLineValue, topColor, botColor, title="RSI + MA Trend", display = display.none)
- bgcolor(RSIMAbackgroundColour, title="Trend background Color", display = display.none)
- //HA Candles
- plotcandle(op1, hi1, lo1, cl1, title = "HA Candle", color = barColor, wickcolor = wikColor, bordercolor = brDrcolor)
- //Original RSI / RSI-MA Plots
- //plot(rsiMA, title="RSI Moving Average", color=color.orange, linewidth=2, editable=false, style=plot.style_line)
Advertisement