Keltner Hull Suite [QuantAlgo]

QuantAlgo · study · 140 行 · 点赞 872 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This script is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © QuantAlgo
 
//@version=6
indicator(title = 'Keltner Hull Suite [QuantAlgo]', overlay = true, timeframe = '', timeframe_gaps = true)
 
//              ╔════════════════════════════════╗              //
//              ║      USER-DEFINED SETTINGS     ║              //
//              ╚════════════════════════════════╝              //
 
var string hull_settings = '════════ Hull Configuration ════════'
var string visual_settings = '════════ Visualization Settings ════════'
 
tooltip_hull_period = 'Number of bars used for Hull Moving Average calculation. Lower values (8-12) make the indicator more responsive to recent price changes, adapting quickly to new trends but potentially generating more false signals in choppy markets. Higher values (16-21) provide smoother, more stable trend identification with reduced noise but slower reaction to genuine trend changes.'
tooltip_keltner_period = 'Number of bars used for Keltner band calculation. Determines the lookback period for volatility measurement. Lower values (14-18) create bands that adapt quickly to recent volatility changes. Higher values (21-30) produce more stable bands that filter out short-term fluctuations.'
tooltip_keltner_multiplier = 'Multiplier applied to double-smoothed True Range for creating dynamic support/resistance bands. Lower values (1.0-1.5) create tighter bands closer to Hull MA, generating more frequent trend changes and earlier signals but increased risk of false breakouts. Higher values (2.5-3.0) create wider bands with stronger trend persistence, fewer signals, and reduced whipsaws but potential for late entries.'
tooltip_price_source = 'Price data used for all calculations. Close: Most common, uses closing price for end-of-period analysis. High/Low: Emphasizes extremes, useful for breakout strategies. HL2/HLC3/OHLC4: Averaged prices reduce impact of wicks and provide smoother trends. HLCC4: Close-weighted average balancing intrabar movement with close significance. Selection impacts signal timing and sensitivity.'
tooltip_preset = 'Select a predefined configuration optimized for different trading styles and market conditions.'
tooltip_preset_details = 'Default (14, 20, 2.0): Balanced configuration suitable for most timeframes and general trading applications. Provides moderate responsiveness with good noise filtering. Optimal for swing trading and daily analysis.\n\nFast Response (10, 14, 1.5): Aggressive setup designed for active intraday trading and scalping. Shorter periods capture rapid price changes with tighter Keltner bands for frequent signals. Best for 1-15min charts where quick entries are critical. Expect more signals but also more false positives in ranging markets.\n\nSmooth Trend (18, 30, 2.5): Conservative configuration for position trading and swing trading. Extended periods provide robust trend identification while wider Keltner bands filter market noise. Ideal for 4h-daily charts where trend persistence matters more than timing precision. Significantly reduces whipsaws but may lag major reversals.'
tooltip_bar_coloring = 'Enable/disable coloring of price bars on the main chart based on the current trend direction. When enabled, bars are colored using the bullish color during uptrends and bearish color during downtrends. This provides an immediate visual reference of the trend direction directly on the price chart without needing to analyze the trend line position.'
tooltip_color_preset = 'Pre-configured color schemes optimized for different chart themes and visual preferences. Each preset maintains strong contrast for instant trend identification.'
tooltip_bullish_color = 'Color for bullish/upward trend signals. Represents market conditions where price is above the adaptive trend line and momentum is positive. Green traditionally signals bullish conditions and uptrend regimes. Choose colors with high contrast against your chart background for optimal visibility. This color is used for the trend band during uptrends and bar coloring when enabled.'
tooltip_bearish_color = 'Color for bearish/downward trend signals. Represents market conditions where price is below the adaptive trend line and momentum is negative. Red conventionally signals bearish conditions and downtrend regimes. Ensure strong contrast with both chart background and bullish color. This color is used for the trend band during downtrends and bar coloring when enabled.'
tooltip_line_transparency = 'Transparency level for the main trend lines. Lower values (0-30) create more opaque, prominent lines that stand out clearly on the chart. Higher values (60-90) create more subtle, transparent lines that blend into the background.'
tooltip_fill_transparency = 'Transparency level for the trend band fill between the main and shifted trend lines. Lower values (0-50) create a more solid, prominent band that clearly highlights trend areas. Higher values (70-95) create a subtle background highlight that doesn\'t obscure price action.'
 
hullPeriod = input.int(14, 'Hull MA Period', group = hull_settings, tooltip = tooltip_hull_period)
keltnerPeriod = input.int(20, 'Keltner Period', group = hull_settings, tooltip = tooltip_keltner_period)
keltnerMultiplier = input.float(2.0, 'Keltner Multiplier', step = 0.1, group = hull_settings, tooltip = tooltip_keltner_multiplier)
priceSource = input.source(close, 'Price Source', group = hull_settings, tooltip = tooltip_price_source)
 
presetConfig = input.string('Default', 'Preconfigured Preset', options=['Default', 'Fast Response', 'Smooth Trend'], group = hull_settings, tooltip = tooltip_preset + '\n\n' + tooltip_preset_details)
 
if presetConfig == 'Fast Response'
    hullPeriod := 10
    keltnerPeriod := 14
    keltnerMultiplier := 1.5
    keltnerMultiplier
else if presetConfig == 'Smooth Trend'
    hullPeriod := 18
    keltnerPeriod := 30
    keltnerMultiplier := 2.5
    keltnerMultiplier
 
enableBarColoring = input.bool(false, 'Enable Bar Coloring', group = visual_settings, tooltip = tooltip_bar_coloring)
 
colorPreset = input.string('Custom', 'Color Preset', options=['Classic', 'Aqua', 'Cosmic', 'Ember', 'Neon', 'Custom'], group = visual_settings, tooltip = tooltip_color_preset)
bullishColorInput = input.color(#00ffaa, 'Bullish Trend Color', group = visual_settings, tooltip = tooltip_bullish_color)
bearishColorInput = input.color(#ff0000, 'Bearish Trend Color', group = visual_settings, tooltip = tooltip_bearish_color)
 
lineTransparency = input.int(30, 'Line Transparency', minval = 0, maxval = 100, step = 5, group = visual_settings, tooltip = tooltip_line_transparency)
fillTransparency = input.int(70, 'Fill Transparency', minval = 0, maxval = 100, step = 5, group = visual_settings, tooltip = tooltip_fill_transparency)
 
[bullishColor, bearishColor] = switch colorPreset
    'Classic' => [#00ff00, #ff0000]
    'Aqua' => [#00bfff, #ff8c00]
    'Cosmic' => [#49ffce, #9932cc]
    'Ember' => [#ff6600, #00cccc]
    'Neon' => [#ffff00, #ff00ff]
    'Custom' => [bullishColorInput, bearishColorInput]
 
//              ╔════════════════════════════════╗              //
//              ║        CORE CALCULATION        ║              //
//              ╚════════════════════════════════╝              //
 
hullMA = ta.hma(priceSource, hullPeriod)
tr = ta.tr(true)
smoothTR = ta.ema(tr, keltnerPeriod)
doubleSmooth = ta.ema(smoothTR, keltnerPeriod)
deviation = doubleSmooth * keltnerMultiplier
upperBound = hullMA + deviation
lowerBound = hullMA - deviation
 
var float trendLine = hullMA
trendLine := nz(trendLine[1], hullMA)
 
if upperBound < trendLine
    trendLine := upperBound
 
if lowerBound > trendLine
    trendLine := lowerBound
 
trendUp = trendLine > trendLine[1]
trendDown = trendLine < trendLine[1]
 
var color currentTrend = bullishColor
if trendUp
    currentTrend := bullishColor
    currentTrend
if trendDown
    currentTrend := bearishColor
    currentTrend
 
var int trendState = 0
 
if trendUp
    trendState := 1
if trendDown
    trendState := -1
 
longSignal = trendState == 1 and trendState[1] != 1
shortSignal = trendState == -1 and trendState[1] != -1
 
//              ╔════════════════════════════════╗              //
//              ║         VISUALIZATION          ║              //
//              ╚════════════════════════════════╝              //
 
mainTrendLine = trendLine
shiftedTrendLine = trendLine[2]
 
lineColor = color.new(currentTrend, lineTransparency)
fillColor = color.new(currentTrend, fillTransparency)
 
mainPlot = plot(mainTrendLine, title = 'Main Trend Line', color = lineColor, linewidth = 4)
shiftedPlot = plot(shiftedTrendLine, title = 'Shifted Trend Line', color = lineColor, linewidth = 4)
 
fill(mainPlot, shiftedPlot, title = 'Trend Band', color = fillColor)
 
barColor = enableBarColoring ? currentTrend : na
barcolor(barColor, title = 'Trend Bar Color')
 
//              ╔════════════════════════════════╗              //
//              ║             ALERTS             ║              //
//              ╚════════════════════════════════╝              //
 
alertcondition(longSignal, title = 'Bullish Trend Signal', message = 'Keltner Hull Suite: Trend changed to BULLISH {{exchange}}:{{ticker}} - {{interval}}')
alertcondition(shortSignal, title = 'Bearish Trend Signal', message = 'Keltner Hull Suite: Trend changed to BEARISH {{exchange}}:{{ticker}} - {{interval}}')
alertcondition(longSignal or shortSignal, title = 'Trend Change', message = 'Keltner Hull Suite: Trend direction changed - Check chart {{exchange}}:{{ticker}} - {{interval}}')
 
//              ╔════════════════════════════════╗              //
//              ║           CREATED BY           ║              //
//              ╚════════════════════════════════╝              //
 
// ██████╗ ██╗   ██╗ █████╗ ███╗   ██╗████████╗     █████╗ ██╗      ██████╗  ██████╗ 
//██╔═══██╗██║   ██║██╔══██╗████╗  ██║╚══██╔══╝    ██╔══██╗██║     ██╔════╝ ██╔═══██╗
//██║   ██║██║   ██║███████║██╔██╗ ██║   ██║       ███████║██║     ██║  ███╗██║   ██║
//██║▄▄ ██║██║   ██║██╔══██║██║╚██╗██║   ██║       ██╔══██║██║     ██║   ██║██║   ██║
//╚██████╔╝╚██████╔╝██║  ██║██║ ╚████║   ██║       ██║  ██║███████╗╚██████╔╝╚██████╔╝
// ╚══▀▀═╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝       ╚═╝  ╚═╝╚══════╝ ╚═════╝  ╚═════╝

← 返回列表