Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © zander
- //@version=5
- indicator("HA Reversal", overlay = true)
- //RRS
- comparedWithSecurity = input.symbol(title="Compare With", defval="SPY")
- lengths = input(title="Length", defval=12)
- //##########Rolling Price Change##########
- comparedClose = request.security(symbol=comparedWithSecurity, timeframe="", expression=close)
- comparedRollingMove = comparedClose - comparedClose[lengths]
- symbolRollingMove = close - close[lengths]
- //##########Rolling ATR Change##########
- symbolRollingATR = ta.atr(lengths)[1]
- comparedRollingATR = request.security (symbol=comparedWithSecurity, timeframe="", expression= ta.atr(lengths)[1])
- //##########Calculations##########
- powerIndex = comparedRollingMove / comparedRollingATR
- RRS = (symbolRollingMove - powerIndex * symbolRollingATR) / symbolRollingATR
- //##########Plot##########
- RealRelativeStrength = plot(RRS, "RealRelativeStrength", color=color.blue)
- Baseline = plot(0, "Baseline", color=color.red)
- //##########Extra Stuff##########
- fill(RealRelativeStrength, Baseline, color = RRS >= 0 ? color.green : color.red, title="fill")
- correlated = ta.correlation(close, comparedClose, lengths)
- //HA Definitions
- mid = (open[1] + close[1])/2
- currentmid = (open+high+low+close)
- flatBottom = mid < low
- flatTop = mid > high
- height = currentmid - mid
- biggerlong = height > height[1]
- biggershort = height < height[1]
- //BBandWidth
- length = input.int(10, minval=1)
- src = input(close, title="Source")
- mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
- basis = ta.sma(src, length)
- dev = mult * ta.stdev(src, length)
- upper = basis + dev
- lower = basis - dev
- bbw = (upper-lower)/basis
- BandExp = bbw > bbw[1]
- vwap = ta.vwap
- ema1 = ta.ema(close, 1)
- ema8 = ta.ema(close, 8)
- ema21 = ta.ema(close, 21)
- bullcross = ema1>ema21
- bearcross = ema1<ema21
- abovevwap = ema8 > vwap
- belowvwap = ema8 < vwap
- RSLimit = input(1)
- RS = RRS > RSLimit
- RW = RRS < RSLimit*-1
- longcheck = BandExp and flatBottom and biggerlong
- shortcheck = BandExp and flatTop and biggershort
- newshort = shortcheck[1] != true
- newlong = longcheck[1] != true
- //!!!!!!!! Below: Remove "and RS" or "and RW" so that this can be used on the SPY. Remove "and bullcross" to get rid of 21ema filter. Remove "and above/belowvwap" to remove VWAP filter.
- long = BandExp and flatBottom and biggerlong and newlong and abovevwap and bullcross
- short = BandExp and flatTop and biggershort and newshort and belowvwap and bearcross
- plotshape(long, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, size = size.tiny, offset=1)
- plotshape(short, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, size = size.tiny, offset=1)
- //plotshape(short, "Short", shape.arrowdown, location.abovebar, color=color.red, size=size.large, offset=1)
- //Alerts
- alertcondition(long, "HA Reversal Long", "Long")
- alertcondition(short, "HA Reversal Short", "Short")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement