本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("FRK Bubbles", shorttitle="FRK Bubbles", overlay=true, max_labels_count=500)
string GROUP_SWINGS = "Swing detection"
int leftBars = input.int(2, "Bars left", minval=1, maxval=50, group=GROUP_SWINGS)
int rightBars = input.int(2, "Bars right", minval=1, maxval=50, group=GROUP_SWINGS)
string pivotBasis = input.string("Wick", "Pivot based on", options=["Wick", "Close"], group=GROUP_SWINGS)
int keepBubbles = input.int(120, "Recent bubbles to keep", minval=10, maxval=125, group=GROUP_SWINGS)
string GROUP_STYLE = "Bubble style"
int bubbleSize = input.int(12, "Bubble size", minval=6, maxval=50, group=GROUP_STYLE)
int borderThickness = input.int(2, "Border thickness", minval=1, maxval=10, group=GROUP_STYLE)
bool showSwingText = input.bool(false, "Show HH / HL / LH / LL text", group=GROUP_STYLE)
color textColor = input.color(color.white, "Text color", group=GROUP_STYLE)
string GROUP_COLORS = "Structure colors"
color bullishFill = input.color(color.rgb(0, 190, 105), "Bullish fill (HH / HL)", group=GROUP_COLORS)
color bullishBorder = input.color(color.rgb(0, 255, 140), "Bullish border", group=GROUP_COLORS)
color bearishFill = input.color(color.rgb(225, 45, 65), "Bearish fill (LH / LL)", group=GROUP_COLORS)
color bearishBorder = input.color(color.rgb(255, 75, 90), "Bearish border", group=GROUP_COLORS)
color equalFill = input.color(color.rgb(245, 155, 20), "Equal pivot fill", group=GROUP_COLORS)
color equalBorder = input.color(color.rgb(255, 190, 45), "Equal pivot border", group=GROUP_COLORS)
// Two circles create the adjustable fill and outline.
f_addBubble(array<label> outerQueue, array<label> innerQueue, int x, float y,
string kind, string pivotName, color fill, color border,
bool showText, color txtColor, int sizePx, int borderPx, int keep) =>
string tip = kind + " " + pivotName + "\nPrice: " + str.tostring(y, format.mintick) +
"\nBasis: " + pivotBasis + "\nConfirmed " + str.tostring(rightBars) + " bar(s) after the pivot"
label outer = label.new(x=x, y=y, text="", xloc=xloc.bar_index, yloc=yloc.price,
color=border, style=label.style_circle, textcolor=txtColor,
size=sizePx + borderPx * 2, tooltip=tip)
label inner = label.new(x=x, y=y, text=showText ? kind : "", xloc=xloc.bar_index,
yloc=yloc.price, color=fill, style=label.style_circle, textcolor=txtColor,
size=sizePx, tooltip=tip)
array.push(outerQueue, outer)
array.push(innerQueue, inner)
if array.size(outerQueue) > keep
label.delete(array.shift(outerQueue))
label.delete(array.shift(innerQueue))
float highSource = pivotBasis == "Wick" ? high : close
float lowSource = pivotBasis == "Wick" ? low : close
float pivotHigh = ta.pivothigh(highSource, leftBars, rightBars)
float pivotLow = ta.pivotlow(lowSource, leftBars, rightBars)
var float previousHigh = na
var float previousLow = na
var label[] highOuter = array.new_label()
var label[] highInner = array.new_label()
var label[] lowOuter = array.new_label()
var label[] lowInner = array.new_label()
bool newHH = false
bool newLH = false
bool newHL = false
bool newLL = false
bool newEQH = false
bool newEQL = false
// The bubble is drawn on the pivot candle after the right-side bars confirm it.
if barstate.isconfirmed
if not na(pivotHigh)
string highKind = na(previousHigh) ? "H" : pivotHigh > previousHigh ? "HH" : pivotHigh < previousHigh ? "LH" : "EQH"
color highFill = highKind == "HH" ? bullishFill : highKind == "LH" ? bearishFill : equalFill
color highBorder = highKind == "HH" ? bullishBorder : highKind == "LH" ? bearishBorder : equalBorder
f_addBubble(highOuter, highInner, bar_index - rightBars, pivotHigh, highKind,
"swing high", highFill, highBorder, showSwingText, textColor,
bubbleSize, borderThickness, keepBubbles)
newHH := highKind == "HH"
newLH := highKind == "LH"
newEQH := highKind == "EQH"
previousHigh := pivotHigh
if not na(pivotLow)
string lowKind = na(previousLow) ? "L" : pivotLow > previousLow ? "HL" : pivotLow < previousLow ? "LL" : "EQL"
color lowFill = lowKind == "HL" ? bullishFill : lowKind == "LL" ? bearishFill : equalFill
color lowBorder = lowKind == "HL" ? bullishBorder : lowKind == "LL" ? bearishBorder : equalBorder
f_addBubble(lowOuter, lowInner, bar_index - rightBars, pivotLow, lowKind,
"swing low", lowFill, lowBorder, showSwingText, textColor,
bubbleSize, borderThickness, keepBubbles)
newHL := lowKind == "HL"
newLL := lowKind == "LL"
newEQL := lowKind == "EQL"
previousLow := pivotLow
alertcondition(newHH, "Higher high (HH)", "FRK Bubbles: confirmed higher high")
alertcondition(newLH, "Lower high (LH)", "FRK Bubbles: confirmed lower high")
alertcondition(newHL, "Higher low (HL)", "FRK Bubbles: confirmed higher low")
alertcondition(newLL, "Lower low (LL)", "FRK Bubbles: confirmed lower low")
alertcondition(newEQH, "Equal high (EQH)", "FRK Bubbles: confirmed equal high")
alertcondition(newEQL, "Equal low (EQL)", "FRK Bubbles: confirmed equal low")