OptionSense Predict Map

dragonjia · study · 138 行 · 点赞 6 · TradingView 原页

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

Pine Script

//@version=6
indicator("OptionSense Predict Map | SPY | Valid 2026-11-20", overlay=true, max_lines_count=80, max_labels_count=80, max_boxes_count=40)
 
// Generated by OptionSense. Do not edit prices by hand; regenerate from daily_card.json.
// BET availability: N/A: 0dte, monthly | VETO/0%
// Best viewed on 5-minute candles. Personal chart drawings are not part of this indicator.
var line[] os_lines = array.new_line()
var label[] os_labels = array.new_label()
var box[] os_boxes = array.new_box()
var table os_panel = table.new(position.top_right, 2, 7, bgcolor=color.new(color.black, 15), border_color=color.new(color.gray, 70), border_width=1)
var table os_tabs = table.new(position.top_left, 1, 2, bgcolor=color.new(color.black, 8), border_color=color.new(color.gray, 65), border_width=1)
var table os_guide = table.new(position.bottom_left, 2, 7, bgcolor=color.new(color.black, 12), border_color=color.new(color.gray, 70), border_width=1)
 
lang = input.string("English", "Language", options=["English", "中文"])
panel_mode = input.string("Compact", "Panel", options=["Compact", "Full", "Hidden"])
scenario_mode = input.string("Top", "Scenarios", options=["Top", "Hidden"])
guide_mode = input.string("Clean", "Guide", options=["Clean", "Guide"])
level_label_size = input.string("Normal", "Level labels", options=["Small", "Normal", "Large"])
tag_offset = input.int(56, "Tag offset bars", minval=20, maxval=120)
strict_valid_date = input.bool(false, "Hide overlay outside valid date")
 
f_lang(string en, string zh) =>
    lang == "中文" ? zh : en
 
f_level_size() =>
    level_label_size == "Large" ? size.large : level_label_size == "Normal" ? size.normal : size.small
 
f_clear() =>
    if array.size(os_lines) > 0
        for i = 0 to array.size(os_lines) - 1
            line.delete(array.get(os_lines, i))
    if array.size(os_labels) > 0
        for i = 0 to array.size(os_labels) - 1
            label.delete(array.get(os_labels, i))
    if array.size(os_boxes) > 0
        for i = 0 to array.size(os_boxes) - 1
            box.delete(array.get(os_boxes, i))
    array.clear(os_lines)
    array.clear(os_labels)
    array.clear(os_boxes)
 
f_level(float price, string caption, string suffix, color c, line_style_arg, int width) =>
    ln = line.new(bar_index - 220, price, bar_index + tag_offset, price, xloc=xloc.bar_index, extend=extend.none, color=c, style=line_style_arg, width=width)
    suffix_text = suffix == "" ? "" : " " + suffix
    lb = label.new(bar_index + tag_offset + 2, price, caption + " " + str.tostring(price, format.mintick) + suffix_text, xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_left, color=color.new(color.black, 10), textcolor=c, size=f_level_size())
    array.push(os_lines, ln)
    array.push(os_labels, lb)
 
f_line(float price, color c, line_style_arg, int width) =>
    ln = line.new(bar_index - 220, price, bar_index + tag_offset, price, xloc=xloc.bar_index, extend=extend.none, color=color.new(c, 15), style=line_style_arg, width=width)
    array.push(os_lines, ln)
 
f_box(float lo, float hi, string caption, color c, int transp) =>
    bx = box.new(bar_index - 220, hi, bar_index + tag_offset, lo, xloc=xloc.bar_index, border_color=color.new(c, 55), bgcolor=color.new(c, transp))
    lb = label.new(bar_index - 215, (hi + lo) / 2.0, caption, xloc=xloc.bar_index, yloc=yloc.price, style=label.style_label_right, color=color.new(c, 56), textcolor=color.white, size=size.normal)
    array.push(os_boxes, bx)
    array.push(os_labels, lb)
 
f_badge(string caption, color c) =>
    lb = label.new(bar_index - 220, high, caption, xloc=xloc.bar_index, yloc=yloc.abovebar, style=label.style_label_down, color=color.new(c, 10), textcolor=color.black, size=size.normal)
    array.push(os_labels, lb)
 
is_expected_symbol = str.upper(syminfo.ticker) == "SPY"
should_rebuild = barstate.islastconfirmedhistory or (barstate.islast and barstate.isconfirmed)
chart_ymd = year(time, "America/New_York") * 10000 + month(time, "America/New_York") * 100 + dayofmonth(time, "America/New_York")
is_valid_day = chart_ymd == 20261120
validity_text = is_valid_day ? f_lang("VALID: 2026-11-20", "有效日: 2026-11-20") : chart_ymd < 20261120 ? f_lang("WAITING: 2026-11-20", "等待有效日: 2026-11-20") : f_lang("EXPIRED: 2026-11-20", "已过期: 2026-11-20")
validity_color = is_valid_day ? color.lime : chart_ymd < 20261120 ? color.yellow : color.red
is_active_card = is_expected_symbol and is_valid_day
can_draw_overlay = is_active_card or (is_expected_symbol and not strict_valid_date)
 
if should_rebuild
    f_clear()
    if not is_expected_symbol
        na
    else
        f_badge(validity_text, validity_color)
        if can_draw_overlay
            f_level(694.59, f_lang("WEEKLY S", "周线支撑"), "(WEEKLY) ★★★", color.new(color.teal, 35), line.style_dashed, 1)
            f_level(707.0707, f_lang("VP S1", "VP S1"), "★", color.gray, line.style_dotted, 1)
            f_level(711.2355, f_lang("LVN1", "LVN1"), "★", color.gray, line.style_dotted, 1)
            f_level(734.566, f_lang("MA5", "MA5"), "", color.gray, line.style_dotted, 1)
            f_level(736.2241, f_lang("VP R1", "VP R1"), "★★★", color.gray, line.style_dotted, 1)
            f_level(737.15, f_lang("WEEKLY R", "周线阻力"), "(WEEKLY) ★★★", color.new(color.orange, 35), line.style_dashed, 1)
            f_level(751.3155, f_lang("MA20", "MA20"), "", color.gray, line.style_dotted, 1)
            if scenario_mode == "Top"
                f_box(705.79, 711.24, f_lang("BREAK 44% | 705.79-711.24", "失守低量区 44% | 705.79-711.24"), color.red, 81)
                f_box(711.24, 727.06, f_lang("RANGE 42% | 711.24-727.06", "价值区下方整理 42% | 711.24-727.06"), color.yellow, 82)
                f_box(727.06, 736.22, f_lang("RECLAIM 14% | 727.06-736.22", "重返价值区 14% | 727.06-736.22"), color.lime, 90)
            f_box(725.99, 727.06, f_lang("NO CALL", "禁追CALL"), color.orange, 90)
            f_box(734.57, 736.22, f_lang("NO CALL", "禁追CALL"), color.orange, 90)
            f_box(707.07, 711.24, f_lang("NO PUT", "禁追PUT"), color.orange, 90)
 
if barstate.islast
    table.cell(os_tabs, 0, 0, f_lang("Target Trading Day: 2026-11-20 Fri", "目标交易日:2026-11-20 周五"), text_color=color.white, text_size=size.small)
    table.cell(os_tabs, 0, 1, f_lang("Pre-market Final", "盘前最终版"), text_color=color.yellow, text_size=size.small)
    table.clear(os_guide, 0, 0, 1, 6)
    if guide_mode == "Guide"
        table.cell(os_guide, 0, 0, "OptionSense", text_color=color.white, text_size=size.small)
        table.cell(os_guide, 1, 0, f_lang("Reading Guide", "读图说明"), text_color=color.yellow, text_size=size.small)
        table.cell(os_guide, 0, 1, f_lang("Valid day", "有效日"), text_color=color.gray, text_size=size.small)
        table.cell(os_guide, 1, 1, f_lang("Use target date only", "仅用于目标交易日"), text_color=color.white, text_size=size.small)
        table.cell(os_guide, 0, 2, f_lang("Walls", "墙位"), text_color=color.gray, text_size=size.small)
        table.cell(os_guide, 1, 2, "N/A: 0dte, monthly | VETO/0%", text_color=color.white, text_size=size.small)
        table.cell(os_guide, 0, 3, f_lang("Stars", "星级"), text_color=color.gray, text_size=size.small)
        table.cell(os_guide, 1, 3, f_lang("Relative strength", "相对强度"), text_color=color.white, text_size=size.small)
        table.cell(os_guide, 0, 4, f_lang("Merged labels", "合并标签"), text_color=color.gray, text_size=size.small)
        table.cell(os_guide, 1, 4, f_lang("Confluence zones", "共振区"), text_color=color.white, text_size=size.small)
        table.cell(os_guide, 0, 5, f_lang("Risk", "风险"), text_color=color.gray, text_size=size.small)
        table.cell(os_guide, 1, 5, f_lang("Not financial advice", "非投资建议"), text_color=color.white, text_size=size.small)
        table.cell(os_guide, 0, 6, "Community", text_color=color.gray, text_size=size.small)
        table.cell(os_guide, 1, 6, f_lang("Please like and leave your feedback in comments", "欢迎点赞与评论反馈"), text_color=color.white, text_size=size.small)
 
if barstate.islast and (panel_mode != "Hidden" or not is_expected_symbol)
    table.clear(os_panel, 0, 0, 1, 6)
    if not is_expected_symbol
        table.cell(os_panel, 0, 0, "OptionSense", text_color=color.white, text_size=size.small)
        table.cell(os_panel, 1, 0, f_lang("SYMBOL MISMATCH", "标的不匹配"), text_color=color.red, text_size=size.small)
        table.cell(os_panel, 0, 1, f_lang("Expected", "应使用"), text_color=color.gray, text_size=size.small)
        table.cell(os_panel, 1, 1, "SPY", text_color=color.white, text_size=size.small)
    else
        table.cell(os_panel, 0, 0, "OptionSense", text_color=color.white, text_size=size.small)
        table.cell(os_panel, 1, 0, "SPY" + " | " + validity_text, text_color=validity_color, text_size=size.small)
        table.cell(os_panel, 0, 1, f_lang("Top Path", "主路径"), text_color=color.gray, text_size=size.small)
        table.cell(os_panel, 1, 1, f_lang("BREAK 44%", "失守低量区 44%"), text_color=color.yellow, text_size=size.small)
        table.cell(os_panel, 0, 2, f_lang("Card Anchor", "卡片锚点"), text_color=color.gray, text_size=size.small)
        table.cell(os_panel, 1, 2, str.tostring(713.3059, format.mintick), text_color=color.white, text_size=size.small)
        if panel_mode == "Full"
            table.cell(os_panel, 0, 3, "ATR", text_color=color.gray, text_size=size.small)
            table.cell(os_panel, 1, 3, str.tostring(10.7465, format.mintick), text_color=color.white, text_size=size.small)
            table.cell(os_panel, 0, 4, f_lang("Anchor TS", "锚点时间"), text_color=color.gray, text_size=size.small)
            table.cell(os_panel, 1, 4, "2026-11-20T05:28:00-05:00", text_color=color.white, text_size=size.small)
            table.cell(os_panel, 0, 5, f_lang("Key Times", "关键时间"), text_color=color.gray, text_size=size.small)
            table.cell(os_panel, 1, 5, "[MEDIUM] 11/20 08:25 Waller 开幕致辞 |\n[HIGH] 11/20 09:30–09:40 现金盘开盘价格发现\n| [HIGH] 11/20 10:00 密歇根终值、BLS\n州就业及年度生产率 | [MEDIUM] 11/20 12:15\nCook 讲话 | [HIGH] 11/20 15:30–16:00\n临近 0DTE 到期,维持零仓位", text_color=color.white, text_size=size.small)
            table.cell(os_panel, 0, 6, f_lang("Play", "打法"), text_color=color.gray, text_size=size.small)
            table.cell(os_panel, 1, 6, "以现金观察为主。盘前 713.31 紧邻 LVN\n711.24,重点观察 09:30 开盘及 10:00 ET\n数据后对 LVN 711.24 与 S1 707.07\n的承接;所有期权结构维持 VETO/0%。", text_color=color.white, text_size=size.small)
 
// BET walls unavailable: no wall alerts; VETO/0%.

← 返回列表