本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator(title="Fractal Breakout Trend Following System", overlay=true, max_lines_count=500, max_labels_count=500)
//#region INPUTS SECTION
leftLenH = input.int(title="Pivot High", defval=5, minval=1, inline="Pivot High", group="Pivot LEFT / RIGHT")
rightLenH = input.int(title="/", defval=5, minval=1, inline="Pivot High", group="Pivot LEFT / RIGHT")
leftLenL = input.int(title="Pivot Low", defval=5, minval=1, inline="Pivot Low", group="Pivot LEFT / RIGHT")
rightLenL = input.int(title="/", defval=5, minval=1, inline="Pivot Low", group="Pivot LEFT / RIGHT")
// Visual Settings
showLabels = input(defval=true, title="Show Pivot Labels?", group="Visual Settings", tooltip="Toggle to display labels for key price swing points: Higher High, Higher Low, Lower High, and Lower Low")
changeBackgroundColor = input.bool(false, title="Change Background Color?", group="Visual Settings", tooltip="Toggle to change the chart background based on ZigZag signals")
bullishColor = input.color(color.green, title="Bullish Color", group="Visual Settings", tooltip="Color to indicate bullish ZigZag conditions")
bearishColor = input.color(color.red, title="Bearish Color", group="Visual Settings", tooltip="Color to indicate Bearish ZigZag conditions")
//#endregion
ph = ta.pivothigh(leftLenH, rightLenH)
pl = ta.pivotlow(leftLenL, rightLenL)
res = fixnan(ph)
sup = fixnan(pl)
var bool resBroken = false
var bool supBroken = false
var line resLine = na
var line supLine = na
var int trend = 0
// Plot resistance lines
if not na(ph)
resLine := line.new(bar_index - rightLenH, res, bar_index, res, color=color.red)
if not resBroken
line.set_x2(resLine[1], bar_index - rightLenH)
resBroken := false
else if not resBroken
line.set_x2(resLine, bar_index)
// Plot support lines
if not na(pl)
supLine := line.new(bar_index - rightLenL, sup, bar_index, sup, color=color.green)
if not supBroken
line.set_x2(supLine[1], bar_index - rightLenL)
supBroken := false
else if not supBroken
line.set_x2(supLine, bar_index)
if ta.crossover(close, res)
resBroken := true, trend := 1
if ta.crossunder(close, sup)
supBroken := true, trend := -1
// Plot labels
resLabel = res[0] < res[1] ? "LH" : res[0] > res[1] ? "HH" : na
supLabel = sup[0] < sup[1] ? "LL" : sup[0] > sup[1] ? "HL" : na
if showLabels
if not na(resLabel)
label.new(bar_index - rightLenH, high, text=resLabel, yloc=yloc.abovebar, style=label.style_none, textcolor=color.white)
if not na(supLabel)
label.new(bar_index - rightLenL, low, text=supLabel, yloc=yloc.belowbar, style=label.style_none, textcolor=color.white)
// Set the background color based on Fratal High/Low breakout
bgcolor(changeBackgroundColor ? color.new(trend == 1 ? bullishColor : bearishColor, 90) : na)