本页源码来自 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/
// © SMRTAlgo
//@version=6
indicator("Pivot Levels Breakouts [SMRT Algo]", overlay=true, max_labels_count=500, max_lines_count=100)
// INPUTS
string G1 = "Pivot Structure"
int pivotLength = input.int(60, "Pivot Lookback", minval=2, maxval=200, group=G1)
int pivotStrength = input.int(8, "Swing Pivot Strength", minval=1, maxval=20, group=G1)
bool showRollingLevels = input.bool(true, "Show Rolling Support / Resistance", group=G1)
bool showSwingLevels = input.bool(true, "Show Confirmed Swing Levels", group=G1)
int trendEmaLength = input.int(34, "Trend EMA Length", minval=2, group=G1)
int trendAtrLength = input.int(14, "Trend ATR Length", minval=2, group=G1)
float trendAtrMultiplier = input.float(0.15, "Trend Noise Filter (ATR)", minval=0.0, step=0.05, group=G1)
string G2 = "Volume"
int volumeLength = input.int(20, "Volume Baseline", minval=2, group=G2)
float volumeThreshold = input.float(1.20, "Relative Volume Threshold", minval=0.1, step=0.05, group=G2)
bool useVolumeFilter = input.bool(true, "Require Volume Confirmation", group=G2)
bool usePressureFilter = input.bool(true, "Require Directional Volume Pressure", group=G2)
string G3 = "Breakout"
float bufferPercent = input.float(0.0, "Breakout Buffer (%)", minval=0.0, step=0.05, group=G3)
bool requireBodyBreak = input.bool(true, "Require Candle Body Beyond Level", group=G3)
bool requireCandleDirection = input.bool(true, "Require Directional Candle", group=G3)
bool showSignals = input.bool(true, "Show BUY / SELL Signals", group=G3)
string G4 = "Appearance"
color buyColor = input.color(#0df1c6, "BUY", group=G4)
color sellColor = input.color(#e91e63, "SELL", group=G4)
//bullishColor = input.color(#0df1c6, "Colors ",inline = '1', group = advancedSettingsGroup,display = display.none,active = (colorTheme == "Custom"))
//bearishColor = input.color(,
// ROLLING LEVELS
float rollingHigh = ta.highest(high, pivotLength)[1]
float rollingLow = ta.lowest(low, pivotLength)[1]
// CONFIRMED SWING PIVOTS
float swingHigh = ta.pivothigh(high, pivotStrength, pivotStrength)
float swingLow = ta.pivotlow(low, pivotStrength, pivotStrength)
var float lastSwingHigh = na
var float lastSwingLow = na
if not na(swingHigh)
lastSwingHigh := swingHigh
if not na(swingLow)
lastSwingLow := swingLow
// VOLUME ANALYSIS
float averageVolume = ta.sma(volume, volumeLength)
float relativeVolume = not na(averageVolume) and averageVolume > 0 and not na(volume) ? volume / averageVolume : na
float candleRange = high - low
float candlePosition = candleRange > 0 ? (close - low) / candleRange : 0.5
float buyPressure = volume * candlePosition
float sellPressure = volume * (1.0 - candlePosition)
float totalPressure = buyPressure + sellPressure
float pressureRatio = totalPressure > 0 ? (buyPressure - sellPressure) / totalPressure : 0.0
bool volumeAvailable = not na(relativeVolume)
bool volumePass = not useVolumeFilter or (volumeAvailable and relativeVolume >= volumeThreshold)
bool buyPressurePass = not usePressureFilter or pressureRatio > 0.15
bool sellPressurePass = not usePressureFilter or pressureRatio < -0.15
// BREAKOUT LEVELS
float rollingBuyLevel = rollingHigh * (1.0 + bufferPercent / 100.0)
float rollingSellLevel = rollingLow * (1.0 - bufferPercent / 100.0)
float swingBuyLevel = lastSwingHigh * (1.0 + bufferPercent / 100.0)
float swingSellLevel = lastSwingLow * (1.0 - bufferPercent / 100.0)
// CROSSOVER / CROSSUNDER
bool rollingBuyCross = ta.crossover(close, rollingBuyLevel)
bool rollingSellCross = ta.crossunder(close, rollingSellLevel)
bool swingBuyCross = ta.crossover(close, swingBuyLevel)
bool swingSellCross = ta.crossunder(close, swingSellLevel)
// VISUAL LEVELS
p1 = plot(showRollingLevels ? rollingHigh : na, "Rolling Resistance", color=color.new(na, 72), linewidth=1)
p2 = plot(showSwingLevels ? lastSwingHigh : na, "Confirmed Swing Resistance", color=sellColor, linewidth=2, style=plot.style_stepline)
l1 = plot(showRollingLevels ? rollingLow : na, "Rolling Support", color=color.new(na, 72), linewidth=1)
l2 = plot(showSwingLevels ? lastSwingLow : na, "Confirmed Swing Support", color=buyColor, linewidth=2, style=plot.style_stepline)
fill(
p1,
p2,
rollingHigh,
lastSwingHigh,
chart.bg_color,
color.new(sellColor,50),
editable = false
)
fill(
l1,
l2,
rollingLow,
lastSwingLow,
chart.bg_color,
color.new(buyColor,50),
editable = false
)
//fill(p1, p2, color=color.new(sellColor, 50))
//fill(l1, l2, color=color.new(buyColor, 50))
// ADVANCED TREND ENGINE
float trendEma = ta.ema(close, trendEmaLength)
float trendAtr = ta.atr(trendAtrLength)
float trendDistance = close - trendEma
float trendThreshold = trendAtr * trendAtrMultiplier
bool bullishStructure = not na(lastSwingHigh) and close > lastSwingHigh
bool bearishStructure = not na(lastSwingLow) and close < lastSwingLow
var int dir = 0
if not na(trendEma) and not na(trendAtr)
if trendDistance > trendThreshold
dir := 1
else if trendDistance < -trendThreshold
dir := -1
// Confirmed swing breaks can override the EMA state.
if bullishStructure
dir := 1
else if bearishStructure
dir := -1
//color trendColor = dir == 1 ? color.rgb(0, 200, 130) : dir == -1 ? color.rgb(240, 65, 75) : na
// GRADIENT TREND COLORS
float gradientRange = trendAtr * 4.0
float gradientValue = gradientRange > 0 ? trendDistance / gradientRange : 0.0
float gradientPosition = math.max(0.0, math.min(1.0, (gradientValue + 1.0) / 2.0))
color trendColor = color.from_gradient(
gradientPosition,
0.0,
1.0,
sellColor,
buyColor
)
barcolor(trendColor)
barcolor(trendColor)
// BUY / SELL SIGNALS
bool SELL = high[1] > rollingHigh[1] and close[1] > open[1] and close < open
bool BUY = low[1] < rollingLow[1] and close[1] < open[1] and close > open
plotshape(showSignals and SELL, title="SELL", style=shape.triangledown, location=location.abovebar, color=sellColor, size=size.tiny, editable=false)
plotshape(showSignals and BUY, title="BUY", style=shape.triangleup, location=location.belowbar, color=buyColor, size=size.tiny, editable=false)