本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoAlpha
//@version=5
indicator("Reversal and Breakout Signals [AlgoAlpha]", "AlgoAlpha - 𝓡/𝓑 𝓢𝓲𝓰𝓷𝓪𝓵𝓼", overlay = true)
len = input.int(20, "Indicator Period")
vlen = input.int(20, "Volume Strength Period")
threshold = input.float(2, "Stong Volume Threshold")
trnd = input.bool(true, "Colour Candles During Trends")
green = input.color(#00ffbb, "Bullish Colour")
red = input.color(#ff1100, "Bearish Colour")
yellow = input.color(#eeff00, "Breakout Colour")
var hstore = 0.0
var lstore = 0.0
hma = ta.hma(close, 30)
rvol = volume/ta.sma(volume, vlen)
strongvol = rvol > threshold
sh = ta.wma(high, len)
sl = ta.wma(low, len)
h = ta.highest(sh, len)
l = ta.lowest(sl, len)
if not (h < h[1] or h > h[1])
hstore := h[1]
if not (l < l[1] or l > l[1])
lstore := l[1]
candledir = close > open ? 1 : -1
var bullishrej = bool(na)
var bearishrej = bool(na)
var bullishbreakout = bool(na)
var bearishbreakout = bool(na)
var state = 0.0
breakout = candledir == 1 and close > hstore and open < hstore
breakdown = candledir == -1 and close < lstore and open > lstore
bullishbreakout := (breakout or ((breakout[1] or breakout[2] or breakout[3] or breakout[4]) and candledir == 1)) and strongvol and not (bullishbreakout[1] or bullishbreakout[2] or bullishbreakout[3])
bearishbreakout := (breakdown or ((breakdown[1] or breakdown[2] or breakdown[3] or breakdown[4]) and candledir == -1)) and strongvol and not (bearishbreakout[1] or bearishbreakout[2] or bearishbreakout[3])
bullishrej := (low < lstore and close > lstore) and not (bullishrej[1] or bullishrej[2] or bullishrej[3] or bullishrej[4])
bearishrej := (high > hstore and close < hstore) and not (bearishrej[1] or bearishrej[2] or bearishrej[3] or bearishrej[4])
if bullishbreakout
state := 1
if bearishbreakout
state := -1
if (ta.crossover(low, lstore) and state == -1) or (ta.crossunder(high, hstore) and state == 1)
state := 0
plotshape(bullishrej and not (state ==- 1) ? low * 0.9995 : na, "Bullish Reversal", shape.triangleup, location.belowbar, color.new(green, 0), size = size.tiny, text = "𝓡", textcolor = color.gray)
plotshape(bearishrej and not (state == 1) ? high * 1.0005 : na, "Bearish Reversal", shape.triangledown, location.abovebar, color.new(red, 0), size = size.tiny, text = "𝓡", textcolor = color.gray)
plotshape(bullishbreakout ? low * 0.999 : na, "Bullish Breakout", shape.diamond, location.belowbar, color.new(yellow, 0), size = size.tiny, text = "𝓑", textcolor = color.gray)
plotshape(bearishbreakout ? high * 1.001 : na, "Bearish Breakout", shape.diamond, location.abovebar, color.new(yellow, 0), size = size.tiny, text = "𝓑", textcolor = color.gray)
barcolor(bullishbreakout ? color.new(yellow, 0) : bearishbreakout ? color.new(yellow, 0) : na)
plot(hstore, color = color.new(red, 50), style = plot.style_stepline_diamond, title = "Upper Level")
plot(lstore, color = color.new(green, 50), style = plot.style_stepline_diamond, title = "Lower Level")
plot(state != 0 ? hma : na, title = "Trend Tracker", color = state == 1 ? green : red, style = plot.style_linebr, linewidth = 3)
candlecol = trnd ? (state == 1 ? green : state == -1 ? red : na) : na
plotcandle(open, high, low, close, "Coloured Candles", candlecol, candlecol, bordercolor = candlecol )
//alert conditions
alertcondition(bullishrej and not (state ==- 1), title = "Bullish Reversal", message = "A bullish Reversal has occurred.")
alertcondition(bearishrej and not (state == 1), title = "Bearish Reversal", message = "A bearish Reversal has occurred.")
alertcondition(bullishbreakout, title = "Bullish Breakout", message = "A bullish breakout has been detected.")
alertcondition(bearishbreakout, title = "Bearish Breakout", message = "A bearish breakout has been detected.")