[CT] High Low Momentum Histogram

ChaosTrader63 · study · 153 行 · 点赞 53 · TradingView 原页

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

Pine Script

// This Source Code Form is subject to the terms of the
// Mozilla Public License 2.0.
// https://mozilla.org/MPL/2.0/
//
// Indicator: [CT] High Low Momentum Histogram
//
// Original Indicator: Don Walk (Pine Script v3)
// Original Developer: [Insert original author's username]
// Original Script: [Insert original TradingView URL]
//
// Adapted and Enhanced by: ChaosTrader63
//
// The original Don Walk high/low counting logic is retained.
//
// CT Enhancements:
// - Conversion to Pine Script v6
// - Momentum histogram presentation
// - Bullish and bearish Donchian event highlighting
// - Adjustable Donchian lookback
// - Customizable histogram colors and column width
// - Optional zero reference line
// - Optional price candle coloring
// - Independent candle color customization
// - Option to match histogram and candle colors
// - Donchian high/low touch alerts
//
// Credit and appreciation to the original developer
// for sharing the foundational Don Walk indicator.
//
//@version=6
indicator("[CT] High Low Momentum Histogram", shorttitle="[CT] HL Momentum", overlay=false, precision=0)
 
//--------------------------------------------------
// DONCHIAN SETTINGS
//--------------------------------------------------
length = input.int(20, "Donchian Lookback", minval=1, group="Donchian Settings")
 
//--------------------------------------------------
// HISTOGRAM DISPLAY
//--------------------------------------------------
showZero = input.bool(true, "Show Zero Line", group="Histogram Display")
columnWidth = input.int(3, "Histogram Column Width", minval=1, maxval=10, group="Histogram Display")
 
//--------------------------------------------------
// HISTOGRAM COLORS
//--------------------------------------------------
bullColor = input.color(#00C853, "Bullish Bars", group="Histogram Colors")
bullEventColor = input.color(#006B3C, "Bullish High Touch (Dark Green)", group="Histogram Colors")
bearColor = input.color(#F28B93, "Bearish Bars", group="Histogram Colors")
bearEventColor = input.color(#8B0000, "Bearish Low Touch (Dark Red)", group="Histogram Colors")
neutralColor = input.color(color.gray, "Neutral Bars", group="Histogram Colors")
 
//--------------------------------------------------
// CANDLE COLOR SETTINGS
//--------------------------------------------------
enableCandleColor = input.bool(true, "Enable Candle Coloring", group="Candle Coloring")
 
matchHistogram = input.bool(true, "Match Histogram Colors", group="Candle Coloring")
 
showEventCandles = input.bool(true, "Highlight High/Low Touch Candles", group="Candle Coloring")
 
colorNeutralCandles = input.bool(false, "Color Neutral Candles", group="Candle Coloring")
 
candleBullColor = input.color(#00C853, "Bullish Candle", group="Candle Coloring")
candleBullEvent = input.color(#006B3C, "Bullish High Touch Candle", group="Candle Coloring")
candleBearColor = input.color(#F28B93, "Bearish Candle", group="Candle Coloring")
candleBearEvent = input.color(#8B0000, "Bearish Low Touch Candle", group="Candle Coloring")
candleNeutralColor = input.color(color.gray, "Neutral Candle", group="Candle Coloring")
 
//--------------------------------------------------
// ORIGINAL DON WALK DONCHIAN LOGIC
//--------------------------------------------------
 
// Boundaries include the current candle,
// matching the original Don Walk indicator.
upper = ta.highest(high, length)
lower = ta.lowest(low, length)
 
upperCond = high >= upper
lowerCond = low <= lower
 
// Original counting and reset behavior.
var int upCount = 0
var int downCount = 0
 
upCount := upperCond ? upCount + 1 : upCount
 
if lowerCond
    upCount := 0
 
downCount := lowerCond ? downCount - 1 : downCount
 
if upperCond
    downCount := 0
 
// Original count priority.
count = upCount > 0 ? upCount : downCount < 0 ? downCount : 0
 
//--------------------------------------------------
// HISTOGRAM COLOR LOGIC
//--------------------------------------------------
bullishEvent = count > 0 and upperCond and not lowerCond
bearishEvent = count < 0 and lowerCond and not upperCond
 
color barColor = neutralColor
 
if count > 0
    barColor := bullishEvent ? bullEventColor : bullColor
else if count < 0
    barColor := bearishEvent ? bearEventColor : bearColor
 
//--------------------------------------------------
// HISTOGRAM PLOTS
//--------------------------------------------------
plot(count, title="High Low Momentum Histogram", style=plot.style_columns, color=barColor, linewidth=columnWidth, histbase=0)
 
plot(showZero ? 0 : na, title="Zero Line", color=color.new(color.gray, 50), linewidth=1)
 
//--------------------------------------------------
// CANDLE COLOR LOGIC
//--------------------------------------------------
 
// Choose either histogram colors or independent
// user-defined candle colors.
color activeBull = matchHistogram ? bullColor : candleBullColor
color activeBullEvent = matchHistogram ? bullEventColor : candleBullEvent
color activeBear = matchHistogram ? bearColor : candleBearColor
color activeBearEvent = matchHistogram ? bearEventColor : candleBearEvent
color activeNeutral = matchHistogram ? neutralColor : candleNeutralColor
 
color candleColor = na
 
if count > 0
    candleColor := showEventCandles and bullishEvent ? activeBullEvent : activeBull
else if count < 0
    candleColor := showEventCandles and bearishEvent ? activeBearEvent : activeBear
else
    candleColor := colorNeutralCandles ? activeNeutral : na
 
// Applies colors to the main price chart
// even when the histogram is in a separate pane.
barcolor(enableCandleColor ? candleColor : na, title="CT Momentum Candle Colors")
 
//--------------------------------------------------
// ALERT CONDITIONS
//--------------------------------------------------
alertcondition(upperCond and not lowerCond, title="Donchian Upper Touch", message="[CT] High Low Momentum: Upper Donchian boundary touched")
 
alertcondition(lowerCond and not upperCond, title="Donchian Lower Touch", message="[CT] High Low Momentum: Lower Donchian boundary touched")
 
alertcondition(ta.crossover(count, 0), title="Bullish Momentum Started", message="[CT] High Low Momentum: Bullish momentum started")
 
alertcondition(ta.crossunder(count, 0), title="Bearish Momentum Started", message="[CT] High Low Momentum: Bearish momentum started")

← 返回列表