Market Breadth TICK - $TICK

Th16rry · study · 63 行 · 点赞 6 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Th16rry
 
//@version=6
indicator("Market Breadth TICK - $TICK", shorttitle="TICK V2", overlay=false)
 
string tickSymbol = input.symbol("USI:TICK.NY", "TICK symbol")
string windowMode = input.string("Minutes", "Lookback unit", options=["Minutes", "Bars"])
int windowMinutes = input.int(120, "Lookback in minutes", minval=10, maxval=390)
int fixedBars = input.int(60, "Lookback in bars", minval=2, maxval=390)
float upperPct = input.float(90.0, "Upper percentile", minval=50.0, maxval=100.0)
float lowerPct = input.float(10.0, "Lower percentile", minval=0.0, maxval=50.0)
bool showZero = input.bool(true, "Show zero line")
 
if not (chart.is_standard and timeframe.isminutes)
    runtime.error("Use a standard intraday chart with a minute-based timeframe.")
 
f_pct(array<float> values, float pct) =>
    array<float> sorted = array.copy(values)
    array.sort(sorted, order.ascending)
    array.percentile_linear_interpolation(sorted, pct)
 
f_tick() =>
    int n = windowMode == "Minutes" ? math.max(2, int(math.ceil(windowMinutes / float(timeframe.multiplier)))) : fixedBars
    string tz = "America/New_York"
    int openMinute = 60 * hour(time, tz) + minute(time, tz)
    int closeMinute = 60 * hour(time_close, tz) + minute(time_close, tz)
    bool valid = not na(time("", "0930-1600:23456", tz)) and openMinute >= 570 and closeMinute <= 960 and closeMinute > openMinute and not na(open) and not na(high) and not na(low) and not na(close)
    var array<float> highs = array.new<float>()
    var array<float> lows = array.new<float>()
    var float nextUpper = na
    var float nextLower = na
 
    float upper = valid ? nextUpper : na
    float lower = valid ? nextLower : na
    if valid
        array.push(highs, high)
        array.push(lows, low)
        if array.size(highs) > n
            array.shift(highs)
            array.shift(lows)
        if array.size(highs) == n
            nextUpper := f_pct(highs, upperPct)
            nextLower := f_pct(lows, lowerPct)
 
    [valid ? open : na, valid ? high : na, valid ? low : na, valid ? close : na, valid ? time_close : na, upper, lower]
 
[tickO, tickH, tickL, tickC, tickEnd, upper, lower] = request.security(
    tickSymbol, timeframe.period, f_tick(),
    gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_off)
 
bool ready = barstate.isconfirmed and not na(tickC) and tickEnd > time and tickEnd <= time_close
bool hitUpper = ready and not na(upper) and tickH >= upper
bool hitLower = ready and not na(lower) and tickL <= lower
color barColor = hitUpper and hitLower ? color.fuchsia : hitUpper ? color.lime : hitLower ? color.red : color.orange
 
plotbar(ready ? tickO : na, ready ? tickH : na, ready ? tickL : na, ready ? tickC : na, title="TICK OHLC", color=barColor)
plot(ready ? upper : na, "Upper band", color=color.aqua, linewidth=2, style=plot.style_linebr)
plot(ready ? lower : na, "Lower band", color=color.aqua, linewidth=2, style=plot.style_linebr)
hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted, display=showZero ? display.all : display.none)
 
alertcondition(hitUpper, "TICK - Upper band touch", "The TICK bar high reached or exceeded the upper band.")
alertcondition(hitLower, "TICK - Lower band touch", "The TICK bar low reached or fell below the lower band.")

← 返回列表