The Stop Odds: how often a stop this far away was hit

TheSimplifier7 · study · 482 行 · 点赞 25 · 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/
// © TheSimplifier7
//@version=6
indicator("The Stop Odds: how often a stop this far away was hit at this hour", shorttitle = "The Stop Odds", overlay = true, max_lines_count = 20, max_labels_count = 20, max_polylines_count = 20)
 
//  THE STOP ODDS · version 3.1
//  Where would a stop be hit, over the window you choose: the next two hours, the next four, or to the 17:00 New York close?
//  From the last 30 minute close, the script reads how far price went over that window (cut at the 17:00 New York close) from
//  the same time of day on each of the last 250 days (or as many as the history it reads holds: about 200 at the default 10,000
//  bars), each in the ATR of its own day before. It draws where that got to on half of those days, one in four and one in ten,
//  above and below: a stop there was hit that often. Your stop, clicked or typed, gets its own number. Every line is graded when
//  its window is out. Each window was tested and sealed before it shipped (two hours: PREREG-STOP-NOW-30M; four hours and to the
//  close: PREREG-STOP-WINDOWS). It calls no side.
//  v3.1 (from 3.0): the window; four checkpoints a window in the tables; the distance in the chart's currency on every
//  label; A STOP HERE said once a side; your stop's label in place of a line's it sits on; the panel's HIT 1 IN 2 row; the record
//  in bold. At two hours every count is 3.0's.
 
// ─────────────────────────────────────────────── inputs
string W2  = "Next 2 hours"
string W4  = "Next 4 hours"
string WC  = "To the 17:00 NY close"
string winIn   = input.string(W2, "Window", options = [W2, W4, WC], group = "WINDOW",
     tooltip = "How long your stop has to survive. Two hours, four hours, or to gold's 17:00 New York close. Each window keeps its own counts and its own record.")
string gS      = "YOUR STOP"
float  stopP   = input.price(0.0, "Your stop", confirm = true, group = gS,
     tooltip = "Click your stop's price on the chart when you add the script, or type it here. 0 for none.")
float  tgtP    = input.price(0.0, "Your target", group = gS, tooltip = "Optional, typed here, read the same way as your stop. 0 for none.")
int    alIn    = input.int(25, "Alert when your stop's odds reach, in 100", minval = 1, maxval = 99, group = gS,
     tooltip = "An alert when the odds your stop is hit within the window rise to this many in 100, and one when price reaches your stop or your target. Create one alert on the script with Any alert() function call.")
string clockIn = input.string("New York", "Clock", options = ["New York", "London", "Madrid"], group = gS,
     tooltip = "The time zone the times are written in. The day is gold's, 18:00 to 17:00 New York, whatever the clock.")
bool   coneIn  = input.bool(true, "The cone", group = "LOOK", tooltip = "Where price got to at the window's four checkpoints on half, one in four and one in ten of the earlier days, drawn from the last 30 minute close.")
string panelIn = input.string("Bottom left", "Panel", options = ["Bottom left", "Top right", "Bottom right", "Off"], group = "LOOK",
     tooltip = "Where the panel sits. Bottom left keeps it clear of the cone and its labels at the right.")
int    histIn  = input.int(10000, "30 minute bars to count from", minval = 3000, maxval = 20000, step = 1000, group = "LOOK",
     tooltip = "How many 30 minute bars of history the counts are read from. 10,000 is about 217 days. Each time of day needs 60 earlier days before it prints.")
 
// ─────────────────────────────────────────────── the house palette
color C_GOLD = #E0A93B
color C_BLUE = #8DB0F5                                   // above the price, as across the range (R23)
color C_MUTE = #8A94A6
color C_INK  = #F3EFE6
color C_BG   = #0B1730
color C_RED  = #E2574C                                   // below it; lines
color C_REDT = #EE7B70                                   // its words, a step lighter so they read on the navy
 
string NY    = "America/New_York"
string TZ    = clockIn == "New York" ? NY : clockIn == "London" ? "Europe/London" : "Europe/Madrid"
string CK    = clockIn == "New York" ? "NY" : str.upper(clockIn)
int    NR    = 46                                       // 30 minute rows in gold's day, 18:00 to 16:30 New York
int    WIN   = 250                                      // earlier days counted at each row
int    MINP  = 60                                       // none printed from fewer
int    WB    = winIn == W2 ? 4 : winIn == W4 ? 8 : NR - 1   // bars in the window, before the 17:00 cut
bool   W2ON  = winIn == W2
float  REACH = W2ON ? 1.0 : 1.5                         // how far, in ATR, a stop is counted
string WNAME = W2ON ? "NEXT 2 HOURS" : winIn == W4 ? "NEXT 4 HOURS" : "TO THE 17:00 NY CLOSE"
string WPH   = W2ON ? "IN THE NEXT 2 HOURS" : winIn == W4 ? "IN THE NEXT 4 HOURS" : "BY THE 17:00 NY CLOSE"
// To the close with more than 8 hours left (the Asian session), the counts come true but are no sharper than a plain random
// walk: PREREG-STOP-WINDOWS on silver, 23 October 2026, z 1.86 against the gate of 3.25 (VERDICT_STOP_WINDOWS_SILVER.json).
// So the panel says so in those hours. Every other stretch of every window passed it.
bool   FLAT8 = true
int    K     = 21                                       // a call's record: see f_eng
bool   tfOk  = timeframe.isintraday and timeframe.in_seconds() <= 1800
 
f_px(float p) =>
    math.abs(p) >= 100 ? str.tostring(p, "#,##0.00") : str.tostring(p, format.mintick)
f_d(float x) =>
    str.tostring(x, "#,##0.00")
// a distance, in the chart's currency
f_cur(float x) =>
    syminfo.currency == "USD" ? "$" + f_d(x) : f_d(x) + " " + syminfo.currency
f_in100(float p) =>
    p < 0.005 ? "UNDER 1 IN 100" : p >= 0.995 ? "OVER 99 IN 100" : str.tostring(math.round(p * 100)) + " IN 100"
// the checkpoint h (0 to 3) of a window of e bars, in bars: at two hours each bar, as 3.0; otherwise the window's quarters
f_ck(int h, int e) =>
    W2ON ? math.min(h + 1, e) : math.max(1, int(math.ceil((h + 1) * e / 4.0)))
// the line at quantile q of a sorted array, read between its two nearest values
f_q(array<float> s, float q) =>
    int   n   = array.size(s)
    float pos = q * (n - 1)
    int   lo  = int(math.floor(pos))
    int   hi  = math.min(lo + 1, n - 1)
    array.get(s, lo) + (pos - lo) * (array.get(s, hi) - array.get(s, lo))
// the share of a sorted array at or past d
f_ge(array<float> s, float d) =>
    int n  = array.size(s)
    int lo = 0
    int hi = n
    while lo < hi
        int md = int((lo + hi) / 2)
        if array.get(s, md) < d
            lo := md + 1
        else
            hi := md
    float(n - lo) / n
 
// ─────────────────────────────────────────────── the engine, run on 30 minute bars
// Each 30 minute bar's row is its open's half hour since 18:00 New York. At its close, a call: from that close, over the window
// (cut at 17:00), the row's table of earlier days gives the cone and the lines; your stop and target take their share. When the
// call's window is out, how far its high and low went by each of the window's four checkpoints goes into the row's table, and the
// call is graded. The ATR is the 14 day Wilder ATR of gold's day before, built from these bars, as the seal's judge builds it.
// Everything returned is the last closed bar's, so nothing repaints.
f_tix(int h, int s, int r) =>
    ((h * 2 + s) * 46 + r) * 250
f_eng() =>
    int   t6  = time + 6 * 3600000
    int   dk  = year(t6, NY) * 10000 + month(t6, NY) * 100 + dayofmonth(t6, NY)
    int   mn  = ((hour(time, NY) - 18 + 24) % 24) * 60 + minute(time, NY)
    int   row = int(mn / 30)
    bool  onG = mn % 30 == 0 and row < NR
    // the ATR of the day before
    var float dH   = na
    var float dL   = na
    var float dC   = na
    var float pCl  = na
    var int   dKey = -1
    var int   nD   = 0
    var float trS  = 0.0
    var float atrW = na
    var float aPv  = na
    if dk != dKey
        if dKey != -1
            float tr = na(pCl) ? dH - dL : math.max(dH - dL, math.max(math.abs(dH - pCl), math.abs(dL - pCl)))
            nD += 1
            if nD <= 14
                trS += tr
                if nD == 14
                    atrW := trS / 14.0
            else
                atrW := (atrW * 13.0 + tr) / 14.0
            pCl := dC
        dKey := dk
        dH   := high
        dL   := low
        dC   := close
        aPv  := atrW
    else
        dH := math.max(dH, high)
        dL := math.min(dL, low)
        dC := close
    // the tables: 4 checkpoints x 2 sides x 46 rows x 250 days, in ATR
    var array<float> tb  = array.new<float>(8 * 46 * 250, na)
    var array<int>   tHd = array.new<int>(46, 0)
    var array<int>   tN  = array.new<int>(46, 0)
    // the last bars, unbroken within the day: row, day, high, low, close, ATR, and each one's call
    var array<int>   bR = array.new<int>()
    var array<int>   bD = array.new<int>()
    var array<float> bH = array.new<float>()
    var array<float> bL = array.new<float>()
    var array<float> bC = array.new<float>()
    var array<float> bA = array.new<float>()
    var array<float> bP = array.new<float>()
    // the record: the lines' calls, what they said and what came; your stop's the same
    var float gN = 0.0
    var float gS = 0.0
    var float gY = 0.0
    var float sN = 0.0
    var float sS = 0.0
    var float sY = 0.0
    array<float> cone = array.new<float>(24, na)
    float ss = na
    float ts = na
    int   ei = math.min(WB, NR - 1 - row)
    int   n  = 0
    if onG
        // a break in the bars ends every window still open
        int m = array.size(bR)
        if m > 0 and (array.get(bD, m - 1) != dk or array.get(bR, m - 1) != row - 1)
            array.clear(bR)
            array.clear(bD)
            array.clear(bH)
            array.clear(bL)
            array.clear(bC)
            array.clear(bA)
            array.clear(bP)
            m := 0
        // the windows this bar closes
        if m > 0
            for j = 0 to m - 1
                int rj = array.get(bR, j)
                int ej = math.min(WB, NR - 1 - rj)
                if rj + ej == row
                    float cj = array.get(bC, j)
                    float aj = array.get(bA, j)
                    if not na(aj) and aj > 0
                        float mu = na
                        float md = na
                        int   hd = array.get(tHd, rj)
                        float u4 = na
                        float d4 = na
                        int   hh = 0
                        for k = 1 to ej
                            float hk = k == ej ? high : array.get(bH, j + k)
                            float lk = k == ej ? low : array.get(bL, j + k)
                            mu := na(mu) ? hk : math.max(mu, hk)
                            md := na(md) ? lk : math.min(md, lk)
                            u4 := (mu - cj) / aj
                            d4 := (cj - md) / aj
                            while hh < 4 and f_ck(hh, ej) == k
                                array.set(tb, f_tix(hh, 0, rj) + hd, u4)
                                array.set(tb, f_tix(hh, 1, rj) + hd, d4)
                                hh += 1
                        array.set(tHd, rj, (hd + 1) % WIN)
                        array.set(tN, rj, math.min(array.get(tN, rj) + 1, WIN))
                        // grade the call, when there was one
                        int pb = j * K
                        if not na(array.get(bP, pb + 3))
                            for i = 0 to 5
                                gN += 1.0
                                gS += array.get(bP, pb + 9 + i)
                                gY += (i % 2 == 0 ? u4 : d4) >= array.get(bP, pb + 3 + i) ? 1.0 : 0.0
                            if not na(array.get(bP, pb + 17))
                                bool came = (array.get(bP, pb + 16) > 0 ? u4 : d4) >= array.get(bP, pb + 15)
                                sN += 1.0
                                sS += array.get(bP, pb + 17)
                                sY += came ? 1.0 : 0.0
        // this bar's call
        array<float> pay = array.new<float>(K, na)
        n := array.get(tN, row)
        if ei >= 1 and n >= MINP and not na(aPv) and aPv > 0
            array<float> s4u = array.new<float>()
            array<float> s4d = array.new<float>()
            for h = 0 to 3
                for s = 0 to 1
                    array<float> sl = array.slice(tb, f_tix(h, s, row), f_tix(h, s, row) + n)
                    array<float> so = array.copy(sl)
                    array.sort(so, order.ascending)
                    array.set(cone, (h * 2 + s) * 3, f_q(so, 0.5))
                    array.set(cone, (h * 2 + s) * 3 + 1, f_q(so, 0.75))
                    array.set(cone, (h * 2 + s) * 3 + 2, f_q(so, 0.9))
                    if h == 3
                        if s == 0
                            s4u := so
                        else
                            s4d := so
            array.set(pay, 0, ei)
            array.set(pay, 1, close)
            array.set(pay, 2, aPv)
            for i = 0 to 5
                float dq = array.get(cone, 3 * 6 + (i % 2) * 3 + int(i / 2))
                array.set(pay, 3 + i, dq)
                array.set(pay, 9 + i, f_ge(i % 2 == 0 ? s4u : s4d, dq))
            for k = 0 to 1
                float p_ = k == 0 ? stopP : tgtP
                if p_ > 0
                    float dd = math.abs(p_ - close) / aPv
                    float sd = p_ >= close ? 1.0 : -1.0
                    float sh = dd <= REACH ? f_ge(sd > 0 ? s4u : s4d, dd) : na
                    array.set(pay, 15 + k * 3, dd)
                    array.set(pay, 16 + k * 3, sd)
                    array.set(pay, 17 + k * 3, sh)
                    if k == 0
                        ss := sh
                    else
                        ts := sh
        array.push(bR, row)
        array.push(bD, dk)
        array.push(bH, high)
        array.push(bL, low)
        array.push(bC, close)
        array.push(bA, aPv)
        array.concat(bP, pay)
        if array.size(bR) > WB + 1
            array.shift(bR)
            array.shift(bD)
            array.shift(bH)
            array.shift(bL)
            array.shift(bC)
            array.shift(bA)
            for i = 0 to K - 1
                array.shift(bP)
    float c00 = array.get(cone, 0)
    float c01 = array.get(cone, 1)
    float c02 = array.get(cone, 2)
    float c03 = array.get(cone, 3)
    float c04 = array.get(cone, 4)
    float c05 = array.get(cone, 5)
    float c06 = array.get(cone, 6)
    float c07 = array.get(cone, 7)
    float c08 = array.get(cone, 8)
    float c09 = array.get(cone, 9)
    float c10 = array.get(cone, 10)
    float c11 = array.get(cone, 11)
    float c12 = array.get(cone, 12)
    float c13 = array.get(cone, 13)
    float c14 = array.get(cone, 14)
    float c15 = array.get(cone, 15)
    float c16 = array.get(cone, 16)
    float c17 = array.get(cone, 17)
    float c18 = array.get(cone, 18)
    float c19 = array.get(cone, 19)
    float c20 = array.get(cone, 20)
    float c21 = array.get(cone, 21)
    float c22 = array.get(cone, 22)
    float c23 = array.get(cone, 23)
    float cl_ = onG ? close : na
    int   tc_ = onG ? time_close : na
    int   e_  = onG ? ei : na
    int   n_  = onG ? n : na
    float a_  = onG ? aPv : na
    [cl_[1], tc_[1], e_[1], n_[1], a_[1], c00[1], c01[1], c02[1], c03[1], c04[1], c05[1], c06[1], c07[1], c08[1], c09[1], c10[1], c11[1], c12[1], c13[1], c14[1], c15[1], c16[1], c17[1], c18[1], c19[1], c20[1], c21[1], c22[1], c23[1], ss[1], ts[1], gN[1], gS[1], gY[1], sN[1], sS[1], sY[1]]
 
[c0, t0, e0, n0, a0, k00, k01, k02, k03, k04, k05, k06, k07, k08, k09, k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k20, k21, k22, k23, ss0, ts0, rN, rS, rY, sN0, sS0, sY0] = request.security(syminfo.tickerid, "30", f_eng(), lookahead = barmerge.lookahead_on, calc_bars_count = histIn)
 
// the cone's distances in ATR: checkpoint h (0 to 3), side s (0 above, 1 below), q (0 half, 1 one in four, 2 one in ten)
f_k(int h, int s, int q) =>
    int i = (h * 2 + s) * 3 + q
    i == 0 ? k00 : i == 1 ? k01 : i == 2 ? k02 : i == 3 ? k03 : i == 4 ? k04 : i == 5 ? k05 : i == 6 ? k06 : i == 7 ? k07 : i == 8 ? k08 : i == 9 ? k09 :
     i == 10 ? k10 : i == 11 ? k11 : i == 12 ? k12 : i == 13 ? k13 : i == 14 ? k14 : i == 15 ? k15 : i == 16 ? k16 : i == 17 ? k17 : i == 18 ? k18 :
     i == 19 ? k19 : i == 20 ? k20 : i == 21 ? k21 : i == 22 ? k22 : k23
bool live = tfOk and not na(c0) and not na(k00)
int  tEnd = na(t0) or na(e0) ? na : t0 + e0 * 1800000
f_hm(int t) =>
    str.format_time(t, "HH:mm", TZ) + " " + CK
string byS = na(e0) ? "" : winIn == WC or e0 < WB ? "BY THE 17:00 NY CLOSE" : "BY " + f_hm(tEnd)
bool   flatNow = winIn == WC and FLAT8 and not na(e0) and e0 > 16
 
// ─────────────────────────────────────────────── your stop and target: reached since the last 30 minute close
var float hiS  = na
var float loS  = na
var int   tPrv = na
var array<int> rT = array.new<int>(2, 0)
if tfOk and not na(t0) and (na(tPrv) or t0 != tPrv)
    tPrv := t0
    hiS  := na
    loS  := na
    array.fill(rT, 0)
if tfOk and not na(t0) and time >= t0
    hiS := na(hiS) ? high : math.max(hiS, high)
    loS := na(loS) ? low : math.min(loS, low)
    for k = 0 to 1
        float p_ = k == 0 ? stopP : tgtP
        if p_ > 0 and array.get(rT, k) == 0 and not na(c0) and (p_ >= c0 ? hiS >= p_ : loS <= p_)
            array.set(rT, k, time)
            if barstate.isrealtime
                alert("THE STOP ODDS · " + (k == 0 ? "YOUR STOP " : "YOUR TARGET ") + f_px(p_) + " IS REACHED · " + f_hm(time), alert.freq_once_per_bar)
// the alert as your stop's odds rise to the level set, once a 30 minute close
var float ssPv = na
if tfOk and not na(t0) and t0 != t0[1]
    if barstate.isrealtime and stopP > 0 and not na(ss0) and ss0 * 100.0 >= alIn and (na(ssPv) or ssPv * 100.0 < alIn)
        alert("THE STOP ODDS · YOUR STOP " + f_px(stopP) + " · HIT " + f_in100(ss0) + " " + WPH + " ON EARLIER DAYS · FROM THE " + f_hm(t0) + " CLOSE", alert.freq_once_per_bar)
    ssPv := ss0
 
// ─────────────────────────────────────────────── drawn at the last bar
f_ktag(int k) =>
    float  p_ = k == 0 ? stopP : tgtP
    float  sh = k == 0 ? ss0 : ts0
    float  dd = na(a0) or a0 <= 0 ? na : math.abs(p_ - c0) / a0
    string s  = (k == 0 ? "YOUR STOP · " : "YOUR TARGET · ") + f_px(p_) + (na(c0) ? "" : " · " + f_cur(math.abs(p_ - c0)))
    if array.get(rT, k) > 0
        s += " · REACHED " + f_hm(array.get(rT, k))
    else if not na(sh)
        s += (k == 0 ? " · HIT " : " · REACHED ") + f_in100(sh) + " " + byS
    else if not na(dd) and dd > REACH
        s += " · FARTHER THAN A USUAL DAY'S RANGE"
    else
        s += " · NO COUNT YET"
    s
// your stop's or target's label takes the place of a line's it sits on
f_near(float y) =>
    bool nr = false
    if not na(a0) and a0 > 0
        nr := (stopP > 0 and math.abs(stopP - y) < 0.03 * a0) or (tgtP > 0 and math.abs(tgtP - y) < 0.03 * a0)
    nr
var array<polyline> pl = array.new<polyline>()
var array<label>    lb = array.new<label>()
var array<line>     ln = array.new<line>()
if barstate.islast
    for p in pl
        polyline.delete(p)
    array.clear(pl)
    for l in lb
        label.delete(l)
    array.clear(lb)
    for l in ln
        line.delete(l)
    array.clear(ln)
    if live
        // the cone of light: each side lit in its own colour, the band from half to one in four brighter than the band out to
        // one in ten; a gold point marks the close. No glow on the half line: a glowing line from the close reads as a path.
        // Its points are the window's four checkpoints (each 30 minutes at two hours, the window's quarters otherwise).
        for s = 0 to 1
            float sg = s == 0 ? 1.0 : -1.0
            color sc = s == 0 ? C_BLUE : C_RED
            if coneIn
                for b = 0 to 1
                    array<chart.point> bd = array.new<chart.point>()
                    array.push(bd, chart.point.from_time(t0, c0))
                    for h = 0 to 3
                        if h == 0 or f_ck(h, e0) != f_ck(h - 1, e0)
                            array.push(bd, chart.point.from_time(t0 + f_ck(h, e0) * 1800000, c0 + sg * f_k(h, s, b + 1) * a0))
                    for h = 3 to 0
                        if h == 0 or f_ck(h, e0) != f_ck(h - 1, e0)
                            array.push(bd, chart.point.from_time(t0 + f_ck(h, e0) * 1800000, c0 + sg * f_k(h, s, b) * a0))
                    array.push(pl, polyline.new(bd, curved = false, closed = true, xloc = xloc.bar_time, line_color = color.new(sc, 100),
                         fill_color = color.new(sc, b == 0 ? 80 : 91)))
            for q = 0 to 2
                float yq = c0 + sg * f_k(3, s, q) * a0
                if coneIn
                    array<chart.point> eg = array.new<chart.point>()
                    array.push(eg, chart.point.from_time(t0, c0))
                    for h = 0 to 3
                        if h == 0 or f_ck(h, e0) != f_ck(h - 1, e0)
                            array.push(eg, chart.point.from_time(t0 + f_ck(h, e0) * 1800000, c0 + sg * f_k(h, s, q) * a0))
                    array.push(pl, polyline.new(eg, curved = false, closed = false, xloc = xloc.bar_time, line_color = color.new(sc, q == 0 ? 5 : q == 1 ? 35 : 50), line_width = q == 2 ? 1 : 2))
                else
                    array.push(ln, line.new(t0, yq, tEnd, yq, xloc = xloc.bar_time, color = color.new(sc, q == 0 ? 30 : q == 1 ? 50 : 62), style = line.style_dotted))
                if not f_near(yq)
                    string lt  = q == 0 ? "A STOP HERE: HIT 1 IN 2 · " : q == 1 ? "1 IN 4 · " : "1 IN 10 · "
                    string tt  = lt + f_cur(math.abs(yq - c0)) + " · " + f_px(yq)
                    color  tcl = s == 0 ? C_BLUE : C_REDT
                    string tip = "On " + (q == 0 ? "half" : q == 1 ? "one in four" : "one in ten") + " of the " + str.tostring(n0) + " earlier days, price got this far " +
                         (s == 0 ? "above" : "below") + " its close at this time of day " + byS + ". A stop here was hit that often."
                    if q == 0
                        array.push(lb, label.new(tEnd, yq, tt, xloc = xloc.bar_time, style = label.style_label_left, color = color.new(C_BG, 20), textcolor = tcl,
                             size = size.normal, text_formatting = text.format_bold, tooltip = tip))
                    else
                        array.push(lb, label.new(tEnd, yq, tt, xloc = xloc.bar_time, style = label.style_label_left, color = color.new(C_BG, 20), textcolor = tcl,
                             size = size.normal, tooltip = tip))
        if coneIn
            array.push(lb, label.new(t0, c0, "", xloc = xloc.bar_time, style = label.style_circle, color = C_GOLD, size = size.tiny,
                 tooltip = "The last 30 minute close, where the counts start."))
        // your stop and target
        for k = 0 to 1
            float p_ = k == 0 ? stopP : tgtP
            if p_ > 0
                bool  hit = array.get(rT, k) > 0
                color lc  = hit ? C_MUTE : C_INK               // by role, not by side: a short's stop is never blue
                color tc  = hit ? C_MUTE : C_INK
                array.push(ln, line.new(t0, p_, tEnd, p_, xloc = xloc.bar_time, color = lc, style = k == 0 ? line.style_dashed : line.style_dotted, width = 2))
                array.push(lb, label.new(tEnd, p_, f_ktag(k), xloc = xloc.bar_time, style = label.style_label_left, color = color.new(C_BG, 5),
                     textcolor = tc, size = size.normal, text_formatting = text.format_bold))
 
// ─────────────────────────────────────────────── the panel
var table tb = table.new(panelIn == "Top right" ? position.top_right : panelIn == "Bottom right" ? position.bottom_right : position.bottom_left, 3, 7, bgcolor = color.new(C_BG, 4), border_width = 0, frame_color = color.new(C_INK, 82), frame_width = 1)
f_row(int r, string a, string b, color cb, string c, color cc) =>
    table.cell(tb, 0, r, a, text_color = C_MUTE, text_size = size.small, text_halign = text.align_left)
    table.cell(tb, 1, r, "   " + b, text_color = cb, text_size = size.small, text_halign = text.align_right)
    table.cell(tb, 2, r, "   " + c, text_color = cc, text_size = size.small, text_halign = text.align_right)
// the record's row, in bold: the brightest on the panel
f_rowb(int r, string a, string b, color cb, string c, color cc) =>
    table.cell(tb, 0, r, a, text_color = C_INK, text_size = size.small, text_halign = text.align_left, text_formatting = text.format_bold)
    table.cell(tb, 1, r, "   " + b, text_color = cb, text_size = size.small, text_halign = text.align_right, text_formatting = text.format_bold)
    table.cell(tb, 2, r, "   " + c, text_color = cc, text_size = size.small, text_halign = text.align_right, text_formatting = text.format_bold)
f_kpan(int r, int k) =>
    float p_ = k == 0 ? stopP : tgtP
    float sh = k == 0 ? ss0 : ts0
    bool  hit = array.get(rT, k) > 0
    string b = f_px(p_) + (live ? " · " + f_cur(math.abs(p_ - c0)) + (p_ >= c0 ? " ABOVE" : " BELOW") : "")
    string c = hit ? "REACHED " + f_hm(array.get(rT, k)) : not na(sh) ? (k == 0 ? "HIT " : "REACHED ") + f_in100(sh) : live and not na(a0) and math.abs(p_ - c0) / a0 > REACH ? "TOO FAR TO COUNT" : "NO COUNT YET"
    f_row(r, k == 0 ? "YOUR STOP" : "YOUR TARGET", b, C_INK, c, hit ? C_MUTE : C_INK)
if barstate.isfirst
    table.merge_cells(tb, 0, 6, 2, 6)
if panelIn != "Off" and barstate.islast
    table.cell(tb, 0, 0, "THE STOP ODDS", text_color = C_GOLD, text_size = size.small, text_halign = text.align_left, text_formatting = text.format_bold)
    table.cell(tb, 1, 0, "   " + WNAME, text_color = C_INK, text_size = size.small, text_halign = text.align_right)
    table.cell(tb, 2, 0, "   " + syminfo.ticker, text_color = C_MUTE, text_size = size.small, text_halign = text.align_right)
    string note = "HOW OFTEN PRICE WENT THIS FAR " + WPH + " FROM THIS TIME OF DAY, ON EARLIER DAYS · CALLS NO SIDE"
    if not tfOk
        note := "OPEN A CHART OF 30 MINUTES OR LESS"
        table.clear(tb, 0, 1, 2, 5)
    else
        f_row(1, "FROM", live ? "THE " + f_hm(t0) + " CLOSE · " + f_px(c0) : "·", C_INK, live ? byS : "", C_MUTE)
        if live
            f_row(2, "HIT 1 IN 2", "A STOP " + f_cur(f_k(3, 0, 0) * a0) + " ABOVE OR " + f_cur(f_k(3, 1, 0) * a0) + " BELOW", C_INK, "", C_MUTE)
        else
            table.clear(tb, 0, 2, 2, 2)
        if stopP > 0
            f_kpan(3, 0)
        else
            f_row(3, "YOUR STOP", "NOT SET · CLICK IT ON THE CHART OR TYPE IT IN THE SETTINGS", C_MUTE, "", C_MUTE)
        if tgtP > 0
            f_kpan(4, 1)
        else
            table.clear(tb, 0, 4, 2, 4)
        f_rowb(5, "ITS RECORD", rN > 0 ? "SAID " + str.tostring(math.round(100 * rS / rN)) + " · CAME " + str.tostring(math.round(100 * rY / rN)) + " IN 100" : "NOTHING GRADED YET", C_INK,
             rN > 0 ? str.tostring(math.round(rN / 6), "#,##0") + " CALLS" : "", C_MUTE)
        if not live
            note := "COUNTING · EACH TIME OF DAY NEEDS 60 EARLIER DAYS"
        else if flatNow
            note := "MORE THAN 8 HOURS LEFT: AS SHARP AS A PLAIN RANDOM WALK, NO SHARPER · " + note
    table.cell(tb, 0, 6, note, text_color = C_MUTE, text_size = size.tiny, text_halign = text.align_left)

← 返回列表