本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Alec's Candle Imbalance Detector", overlay=true, max_lines_count=500)
// --- User Inputs ---
onlySessionOpen = input.bool(false, "Only First Candle of Regular Session", tooltip="Restricts rays strictly to the market opening candle.")
sessionTime = input.session("0930-0935", "Session Open Window (Exchange Time)", tooltip="Adjust end time if using on higher timeframes (e.g. 0930-1030 for 1H).")
rayColor = input.color(color.new(#FF00FF, 20), "Open Ray Color")
lineWidth = input.int(3, "Line Width", minval=1, maxval=10)
// --- Timeframe Logic ---
// Works on 1m, 5m, 15m, 30m, and 1H (60m) charts
isValidTF = timeframe.isintraday and (
timeframe.multiplier == 1 or
timeframe.multiplier == 5 or
timeframe.multiplier == 15 or
timeframe.multiplier == 30 or
timeframe.multiplier == 60
)
inSession = not onlySessionOpen or not na(time(timeframe.period, sessionTime))
tol = syminfo.mintick * 0.1
// Bullish candle where price never traded below Open (Open == Low)
isBullNoLowerWick = close > open and math.abs(open - low) <= tol
// Bearish candle where price never traded above Open (Open == High)
isBearNoUpperWick = close < open and math.abs(high - open) <= tol
// --- Line Management (Arrays to Track Retests) ---
var line[] activeBullLines = array.new_line()
var line[] activeBearLines = array.new_line()
if isValidTF
// 1. Update & Check Retests for Existing Bullish Rays (Open == Low)
if array.size(activeBullLines) > 0
for i = array.size(activeBullLines) - 1 to 0
l = array.get(activeBullLines, i)
lvl = line.get_y1(l)
// Extend the line to the current bar
line.set_x2(l, bar_index)
// Stop tracking if price revisits/drops to or below the open level
if low <= lvl + tol
array.remove(activeBullLines, i)
// 2. Update & Check Retests for Existing Bearish Rays (Open == High)
if array.size(activeBearLines) > 0
for i = array.size(activeBearLines) - 1 to 0
l = array.get(activeBearLines, i)
lvl = line.get_y1(l)
// Extend the line to the current bar
line.set_x2(l, bar_index)
// Stop tracking if price revisits/rises to or above the open level
if high >= lvl - tol
array.remove(activeBearLines, i)
// 3. Create New Rays on Confirmed Bars
if inSession and barstate.isconfirmed
if isBullNoLowerWick
newBull = line.new(
x1=bar_index,
y1=open,
x2=bar_index,
y2=open,
extend=extend.none,
color=rayColor,
width=lineWidth
)
array.push(activeBullLines, newBull)
if array.size(activeBullLines) > 250
array.shift(activeBullLines)
if isBearNoUpperWick
newBear = line.new(
x1=bar_index,
y1=open,
x2=bar_index,
y2=open,
extend=extend.none,
color=rayColor,
width=lineWidth
)
array.push(activeBearLines, newBear)
if array.size(activeBearLines) > 250
array.shift(activeBearLines)