本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("BO Indicator", overlay=true, dynamic_requests=true)
// ═══════════════════════════════════════════════════════════════
// INPUTS
// ═══════════════════════════════════════════════════════════════
dailyChangeThreshold = input.float(defval=5, title="% Change Threshold")
gapupThreshold = input.float(defval=2.5, title="Gap up Threshold")
rVolThreshold = input(defval=40, title="Rvol% Threshold")
showInstitutionalFootprint = input.bool(defval=true, title="Enable 15m RVOL Circle", group="Institutional Footprint")
institutionalRvolThreshold = input.float(defval=1000, title="15m RVOL% Threshold", group="Institutional Footprint")
rsLookback = input.int(defval=252, title="RS Lookback (bars = ~1 year)", group="RS vs NIFTY Table")
benchmarkSymbol = input.symbol(defval="NSE:NIFTY", title="Benchmark Index", group="RS vs NIFTY Table")
rsStrongTextSize = input.int(defval=28, title="RS > 50% Font Size", minval=18, maxval=40, group="RS vs NIFTY Table")
// ═══════════════════════════════════════════════════════════════
// MOVING AVERAGES
// ═══════════════════════════════════════════════════════════════
// Each chart has a fixed timeframe. Skip averages that have no output on it.
float sma21 = na
float sma50 = na
float sma200 = na
float sma10 = na
float ema30 = na
float sma30 = na
if timeframe.isdaily
sma21 := ta.ema(close, 21)
sma50 := ta.ema(close, 50)
sma200 := ta.ema(close, 200)
if timeframe.isweekly
sma10 := ta.sma(close, 10)
ema30 := ta.ema(close, 30)
sma30 := ta.sma(close, 30)
// ═══════════════════════════════════════════════════════════════
// DAILY CHANGE & VOLUME
// ═══════════════════════════════════════════════════════════════
dailyChange = math.round(((close - close[1]) / close[1]) * 100, 2)
avgVolume = ta.sma(volume, 50)
volPercent = ((volume - avgVolume) / avgVolume) * 100
bool chartIs15m = timeframe.isintraday and timeframe.in_seconds() == 15 * 60
bool chartIs1D = timeframe.isdaily and timeframe.multiplier == 1
// Institutional circles are allowed only on 15-minute and 1-day charts.
bool footprintTimeframeAllowed = chartIs15m or chartIs1D
// RS is displayed only on daily charts, so request NIFTY only there.
float rsVsNiftyPct = na
if timeframe.isdaily
float niftyClose = request.security(benchmarkSymbol, timeframe.period, close, barmerge.gaps_off, barmerge.lookahead_off)
float rsRatio = nz(niftyClose) != 0 ? close / niftyClose : na
int rsAnchorOffset = math.min(bar_index, rsLookback - 1)
float rsAnchorValue = rsRatio[rsAnchorOffset]
rsVsNiftyPct := na(rsAnchorValue) or rsAnchorValue == 0 ? na : math.round((rsRatio / rsAnchorValue - 1) * 100, 1)
// ═══════════════════════════════════════════════════════════════
// CONDITIONS
// ═══════════════════════════════════════════════════════════════
condition0 = (math.round(((high - close[1]) / close[1]) * 100, 2)) > dailyChangeThreshold
condition1 = dailyChange > dailyChangeThreshold
// IPO FIX: ta.ema() always returns a value from bar 0, but for recent
// IPOs with e.g. only 60 bars, the "200-bar EMA" is effectively a
// 60-bar EMA — so condition3 (sma50 >= sma200) can be misleading.
// Guard: bypass alignment conditions when insufficient bars exist.
// This allows recently listed stocks to show signals too.
condition2 = bar_index < 50 ? true : sma21 >= sma50
condition3 = bar_index < 200 ? true : sma50 >= sma200
condition4 = volPercent >= rVolThreshold
// Follow-through day (daily chart only): yesterday must show strong volume
// and price strength, followed by at least a 2.5% gain today.
followThroughDay = timeframe.isdaily and volPercent[1] > 40 and dailyChange[1] >= 3.5 and dailyChange >= 2.5
volDryCondition = volume[3] <= avgVolume and volume[2] <= avgVolume and volume[1] <= avgVolume
// 15m RVOL CIRCLE — at least one completed 15-minute candle in this chart bar
// must exceed the threshold and close above the prior 15-minute close.
// The 50-bar volume average is calculated on 15-minute data.
fQualifying15mVolume() =>
average15mVolume = ta.sma(volume, 50)
close > close[1] and not na(average15mVolume) and average15mVolume > 0 and
(volume - average15mVolume) / average15mVolume * 100 > institutionalRvolThreshold
// Keep the close-time test inside the 15m context. The daily request then
// returns one boolean per intrabar, which can be searched without a Pine loop.
bool institutionalFootprint = false
if showInstitutionalFootprint and footprintTimeframeAllowed
if chartIs15m
institutionalFootprint := fQualifying15mVolume() and time_close <= timenow
else if chartIs1D
array<bool> confirmedQualifiers = request.security_lower_tf(
syminfo.tickerid, "15", fQualifying15mVolume() and time_close <= timenow)
institutionalFootprint := array.includes(confirmedQualifiers, true)
// ═══════════════════════════════════════════════════════════════
// PLOTS — MOVING AVERAGES
// ═══════════════════════════════════════════════════════════════
plot(sma21, title="21 EMA", color=timeframe.isdaily ? color.blue : na)
plot(sma50, title="50 EMA", color=timeframe.isdaily ? color.green : na)
plot(sma200, title="200 EMA", linewidth=2, color=timeframe.isdaily ? color.red : na)
plot(sma10, title="10 SMA", color=timeframe.isweekly ? color.blue : na)
plot(ema30, title="30 EMA", linewidth=2, color=timeframe.isweekly ? color.red : na)
// ═══════════════════════════════════════════════════════════════
// ALL-TIME HIGH FUNCTIONS
// ═══════════════════════════════════════════════════════════════
GetChartHighest(dataSeries = high) =>
var chartHighest = dataSeries
if dataSeries > nz(chartHighest, -1e10)
chartHighest := dataSeries
chartHighest
GetAllTimeHigh(dataSeries = high) =>
highestHTF = request.security(syminfo.tickerid, "D", GetChartHighest(dataSeries)[1], lookahead=barmerge.lookahead_on)
highestChartTF = GetChartHighest(dataSeries)
math.max(highestHTF, highestChartTF)
// Keep the daily security context for ATH, including its historical coverage.
allTimeHigh = GetAllTimeHigh()
ath_distance = math.round(100 * (close - allTimeHigh) / allTimeHigh, 1)
// ═══════════════════════════════════════════════════════════════
// 52-WEEK RANGE
// ═══════════════════════════════════════════════════════════════
float high52 = na
float low52 = na
float rangeMove = na
float downFrom52wHigh = na
if timeframe.isdaily
high52 := ta.highest(high, 252)
low52 := ta.lowest(low, 252)
rangeMove := (high52 - low52) / low52 * 100
downFrom52wHigh := (high52 - close) / high52 * 100
condition5 = ath_distance >= -25 and ath_distance <= 0
// ═══════════════════════════════════════════════════════════════
// BREAKOUT ARROWS
// ═══════════════════════════════════════════════════════════════
position_size = 10000 / close
arrowheight = 20
plotarrow(condition0 and condition2 and condition3 and condition4 and timeframe.isdaily ? 1 : na,
title="Squat Entry", colorup=color.red, maxheight=arrowheight, minheight=arrowheight)
plotarrow(condition1 and condition2 and condition3 and condition4 and timeframe.isdaily ? 1 : na,
title="BO", colorup=color.yellow, maxheight=arrowheight, minheight=arrowheight)
plotarrow(followThroughDay ? 1 : na,
title="Follow-Through Day", colorup=color.purple, maxheight=arrowheight, minheight=arrowheight)
plotarrow(condition1 and condition2 and condition3 and condition4 and condition5 and timeframe.isdaily ? 1 : na,
title="ATH BO", colorup=color.green, maxheight=arrowheight, minheight=arrowheight)
plotshape(institutionalFootprint and footprintTimeframeAllowed,
title="15m RVOL Above Threshold + Positive Close Change",
style=shape.circle,
location=location.belowbar,
color=color.black,
size=size.tiny)
// ═══════════════════════════════════════════════════════════════
// VOL DRY SIGNAL
// ═══════════════════════════════════════════════════════════════
plotshape(condition0 and condition2 and condition3 and volDryCondition and timeframe.isdaily ? 1 : na,
title="Vol Dry", style=shape.square, location=location.abovebar, color=#f80158)
// ═══════════════════════════════════════════════════════════════
// TABLE — INFO PANEL
// ═══════════════════════════════════════════════════════════════
int tableRows = timeframe.isdaily ? 5 : timeframe.isweekly ? 4 : 2
var table conditionTable = table.new(position=position.bottom_right, columns=2, rows=tableRows)
if barstate.islast
float sma30Distance = ((close - sma30) / sma30) * 100
float someDistance = ((sma10 - sma30) / sma30) * 100
float rounded52wHighDistance = math.round(downFrom52wHigh, 1)
bool sameHighDistance = timeframe.isdaily and not na(ath_distance) and not na(rounded52wHighDistance) and math.abs(ath_distance) == rounded52wHighDistance
int row = 0
if timeframe.isweekly
table.cell(conditionTable, 0, row, "30 SMA Dist")
table.cell(conditionTable, 1, row, str.tostring(math.round(sma30Distance, 1)) + "%")
row += 1
table.cell(conditionTable, 0, row, "ATH Dist")
if sameHighDistance
table.cell(conditionTable, 1, row, str.tostring(ath_distance) + "%", text_color=color.green, text_formatting=text.format_bold)
else
table.cell(conditionTable, 1, row, str.tostring(ath_distance) + "%")
row += 1
if timeframe.isdaily
table.cell(conditionTable, 0, row, "52W High dist")
if sameHighDistance
table.cell(conditionTable, 1, row, str.tostring(rounded52wHighDistance) + "%", text_color=color.green, text_formatting=text.format_bold)
else
table.cell(conditionTable, 1, row, str.tostring(rounded52wHighDistance) + "%")
row += 1
if timeframe.isdaily
table.cell(conditionTable, 0, row, "Up from 52W L")
table.cell(conditionTable, 1, row, str.tostring(math.round(rangeMove, 1)) + "%")
row += 1
table.cell(conditionTable, 0, row, "RS vs NIFTY")
if not na(rsVsNiftyPct) and rsVsNiftyPct > 50
table.cell(conditionTable, 1, row, str.tostring(rsVsNiftyPct) + "%", text_size=rsStrongTextSize, text_formatting=text.format_bold)
else
table.cell(conditionTable, 1, row, not na(rsVsNiftyPct) ? str.tostring(rsVsNiftyPct) + "%" : "")
row += 1
if timeframe.isweekly
table.cell(conditionTable, 0, row, "10 & 30 SMA dist")
table.cell(conditionTable, 1, row, str.tostring(math.round(someDistance, 1)) + "%")
row += 1
table.cell(conditionTable, 0, row, "Position Size", text_size=size.large, text_formatting=text.format_bold)
table.cell(conditionTable, 1, row, str.tostring(math.floor(position_size)), text_size=size.large, text_formatting=text.format_bold)
// ═══════════════════════════════════════════════════════════════
// GAP UP & INTRADAY BAR COLOR
// ═══════════════════════════════════════════════════════════════
gaupChange = ((open - close[1]) / close[1]) * 100
gapupCondition = gaupChange >= gapupThreshold and dailyChange >= gapupThreshold and timeframe.isdaily
percentChange(previousClose, currentClose) =>
100 * (currentClose - previousClose) / previousClose
isIntraday = timeframe.isintraday
previousClose = isIntraday ? (chartIs15m ? close[1] : request.security(syminfo.tickerid, "15", close[1])) : na
currentClose = close
change = 0.0
if isIntraday
change := percentChange(previousClose, currentClose)
isLargeChange = isIntraday and change > 5
barcolor(isLargeChange ? color.white : na, title="Intraday 15m Move > 5%")
barcolor(gapupCondition ? color.purple : color.black, title="Daily Gap-Up / Default Candle Color")