True Opens [Pro +]

HDJ1 · study · 422 行 · 点赞 296 · TradingView 原页

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

Pine Script

//@version=6
indicator("True Opens [Pro +]", shorttitle = "True Opens", overlay = true, max_lines_count = 500, max_labels_count = 500)
 
const string GRP_MASTER   = "Master Toggles"
const string GRP_DISPLAY  = "Display Mode"
const string GRP_LABEL    = "Label Preset"
const string GRP_STYLE    = "Line Style"
const string GRP_COLORS   = "Colors"
const string GRP_SETTINGS = "Settings"
const string GRP_TABLE    = "Bias Table"
 
bool showMicro   = input.bool(true,  "Show Micro TO",   group = GRP_MASTER, tooltip = "~22.5-minute quarters (64 sessions/day). Ultra-short-term reference for scalpers.")
bool show90m     = input.bool(true,  "Show 90m TO",     group = GRP_MASTER, tooltip = "Asia, London, NY and PM sessions. Each session's Q2 (the second 90 minutes) gives Asia TO, London TO, NY TO and PM TO.")
bool showDaily   = input.bool(true,  "Show Daily TO",   group = GRP_MASTER, tooltip = "6-hour quarters (18:00-00:00, 00:00-06:00, 06:00-12:00, 12:00-18:00 ET). The True Day is the 00:00 open.")
bool showWeekly  = input.bool(true,  "Show Weekly TO",  group = GRP_MASTER, tooltip = "Monday = Q1, Tuesday = Q2 (True Week), Wednesday = Q3, Thursday = Q4. The True Week is Tuesday's daily open.")
bool showMonthly = input.bool(true,  "Show Monthly TO", group = GRP_MASTER, tooltip = "Week 1 = Q1, Week 2 = Q2 (True Month), Week 3 = Q3, Week 4 = Q4 (+ distortion days 29-31). The True Month is the Monday open of the second trading week.")
bool show0830    = input.bool(false, "Show 8:30 Open",  group = GRP_MASTER, tooltip = "Plots the 8:30 ET open (economic news reference). Not a cyclic open.")
bool show0930    = input.bool(true,  "Show 9:30 Open",  group = GRP_MASTER, tooltip = "Plots the equity market open (RTH reference). Not a cyclic open.")
bool show1000    = input.bool(false, "Show 10:00 Open", group = GRP_MASTER, tooltip = "Plots the 10:00 ET open. Not a cyclic open.")
bool show1800    = input.bool(false, "Show 18:00 Open", group = GRP_MASTER, tooltip = "Plots the 18:00 ET open (trading day open). Not a cyclic open.")
bool showDWO     = input.bool(false, "Show Dynamic Weekly Open", group = GRP_MASTER, tooltip = "Plots the first open of the trading week, adapting to the instrument's week start. Not a cyclic open.")
 
string displayMode = input.string("Auto", "Display Mode", options = ["Auto", "Custom"], group = GRP_DISPLAY, tooltip = "Auto: uses sensible TF ranges per cycle (recommended).\nCustom: define your own TF visibility ranges (Min → Max) for each cycle below.")
string tfMicroMin  = input.timeframe("1S",  "Micro TO",      inline = "tfMicro", group = GRP_DISPLAY)
string tfMicroMax  = input.timeframe("1",   "→",             inline = "tfMicro", group = GRP_DISPLAY)
string tf90mMin    = input.timeframe("1S",  "90m TO",        inline = "tf90m",   group = GRP_DISPLAY)
string tf90mMax    = input.timeframe("5",   "→",             inline = "tf90m",   group = GRP_DISPLAY)
string tfDailyMin  = input.timeframe("1S",  "Daily TO",      inline = "tfDaily", group = GRP_DISPLAY)
string tfDailyMax  = input.timeframe("60",  "→",             inline = "tfDaily", group = GRP_DISPLAY)
string tfWeeklyMin = input.timeframe("60",  "Weekly TO",     inline = "tfWeek",  group = GRP_DISPLAY)
string tfWeeklyMax = input.timeframe("D",   "→",             inline = "tfWeek",  group = GRP_DISPLAY)
string tfMonthMin  = input.timeframe("240", "Monthly TO",    inline = "tfMonth", group = GRP_DISPLAY)
string tfMonthMax  = input.timeframe("W",   "→",             inline = "tfMonth", group = GRP_DISPLAY)
string tfSessMin   = input.timeframe("1S",  "8:30/9:30/10:00", inline = "tfSess", group = GRP_DISPLAY)
string tfSessMax   = input.timeframe("5",   "→",             inline = "tfSess",  group = GRP_DISPLAY)
string tf1800Min   = input.timeframe("1S",  "18:00 Open",    inline = "tf1800",  group = GRP_DISPLAY)
string tf1800Max   = input.timeframe("60",  "→",             inline = "tf1800",  group = GRP_DISPLAY)
string tfDWOMin    = input.timeframe("1S",  "Weekly Open",   inline = "tfDWO",   group = GRP_DISPLAY)
string tfDWOMax    = input.timeframe("240", "→",             inline = "tfDWO",   group = GRP_DISPLAY)
 
string labelPreset = input.string("Auto", "Label Preset", options = ["Auto", "Custom Names", "Time"], group = GRP_LABEL, tooltip = "Auto: session-specific labels (Asia TO, London TO, True Day, etc.)\nCustom Names: use your own text for each level.\nTime: shows the bar time (HH:mm) when the TO was captured.")
bool   showLabels  = input.bool(true, "Show Labels", inline = "lblSz", group = GRP_LABEL)
string labelSize   = input.string("Tiny", "Size", options = ["Tiny", "Small", "Normal"], inline = "lblSz", group = GRP_LABEL)
string nameMicro   = input.string("Micro TO",      "Micro TO",      group = GRP_LABEL)
string nameAsia    = input.string("Asia TO",       "Asia TO",       group = GRP_LABEL)
string nameLondon  = input.string("London TO",     "London TO",     group = GRP_LABEL)
string nameNY      = input.string("NY TO",         "NY TO",         group = GRP_LABEL)
string namePM      = input.string("PM TO",         "PM TO",         group = GRP_LABEL)
string nameDay     = input.string("True Day",      "Daily TO",      group = GRP_LABEL)
string nameWeek    = input.string("True Week",     "Weekly TO",     group = GRP_LABEL)
string nameMonth   = input.string("True Month",    "Monthly TO",    group = GRP_LABEL)
string name0830    = input.string("8:30 Open",     "8:30 Open",     group = GRP_LABEL)
string name0930    = input.string("Equities Open", "9:30 Open",     group = GRP_LABEL)
string name1000    = input.string("10:00 Open",    "10:00 Open",    group = GRP_LABEL)
string name1800    = input.string("18:00 Open",    "18:00 Open",    group = GRP_LABEL)
string nameDWO     = input.string("Weekly Open",   "Dynamic Weekly Open", group = GRP_LABEL)
 
string lineStyleMode = input.string("Auto", "Line Style", options = ["Auto", "Custom"], group = GRP_STYLE, tooltip = "Auto: dashed while Q2 is active, solid after Q2 closes.\nCustom: choose solid, dashed or dotted for all lines.")
string customStyle   = input.string("Solid", "Custom Style", options = ["Solid", "Dashed", "Dotted"], group = GRP_STYLE)
int    lineWidth     = input.int(1, "Line Thickness", minval = 1, maxval = 5, group = GRP_STYLE)
 
color colMicro   = input.color(#E57CE8, "Micro TO",    inline = "c1", group = GRP_COLORS)
color col90m     = input.color(#5D9CEC, "90m TO",      inline = "c1", group = GRP_COLORS)
color colDaily   = input.color(#E8899A, "Daily TO",    inline = "c2", group = GRP_COLORS)
color colWeekly  = input.color(#F4A259, "Weekly TO",   inline = "c2", group = GRP_COLORS)
color colMonthly = input.color(#8E7CC3, "Monthly TO",  inline = "c3", group = GRP_COLORS)
color col0830    = input.color(#C9A26B, "8:30 Open",   inline = "c3", group = GRP_COLORS)
color col0930    = input.color(#A3A3A3, "9:30 Open",   inline = "c4", group = GRP_COLORS)
color col1000    = input.color(#7FA88B, "10:00 Open",  inline = "c4", group = GRP_COLORS)
color col1800    = input.color(#8C9EB5, "18:00 Open",  inline = "c5", group = GRP_COLORS)
color colDWO     = input.color(#26A69A, "Weekly Open", inline = "c5", group = GRP_COLORS)
 
int  barOffset   = input.int(20, "Active Line Bar Offset", minval = 0, maxval = 300, group = GRP_SETTINGS, tooltip = "How far the line extends past the current bar.")
bool showHistory = input.bool(false, "Show Historical True Opens", group = GRP_SETTINGS, tooltip = "Keep past TOs visible instead of auto-cleanup. Only the current cycle's TO is shown when disabled.")
int  maxHistory  = input.int(20, "Max Historical TOs per Cycle", minval = 1, maxval = 40, group = GRP_SETTINGS, tooltip = "Oldest historical TOs are deleted beyond this count to stay within TradingView drawing limits.")
 
bool   showTable      = input.bool(true, "Show Bias Table", group = GRP_TABLE, tooltip = "Only applies to cyclic opens based on Quarterly Theory.\nAbove (red): potential bearish price delivery.\nBelow (green): potential bullish price delivery.")
string tablePos       = input.string("Middle Right", "Position", options = ["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"], group = GRP_TABLE)
string tableTextSize  = input.string("Small", "Text Size", options = ["Tiny", "Small", "Normal", "Large"], group = GRP_TABLE)
color  tableTextColor = input.color(#000000, "Cycle Text", group = GRP_TABLE)
color  aboveColor     = input.color(#F23645, "Above", inline = "tb", group = GRP_TABLE)
color  belowColor     = input.color(#089981, "Below", inline = "tb", group = GRP_TABLE)
 
const string TZ             = "America/Toronto"
const int    MS_PER_HOUR    = 3600000
const int    MS_PER_DAY     = 86400000
const int    MIN_PER_DAY    = 1440
const int    DAY_START_MIN  = 1080
const int    SESSION_SEC    = 21600
const int    Q90_SEC        = 5400
const int    MICRO_SEC      = 1350
const int    OPEN_0830      = 510
const int    OPEN_0930      = 570
const int    OPEN_1000      = 600
const int    OPEN_1800      = 1080
 
const int AUTO_MICRO_MIN = 0
const int AUTO_MICRO_MAX = 60
const int AUTO_90M_MIN   = 0
const int AUTO_90M_MAX   = 300
const int AUTO_DAY_MIN   = 0
const int AUTO_DAY_MAX   = 3600
const int AUTO_WEEK_MIN  = 3600
const int AUTO_WEEK_MAX  = 86400
const int AUTO_MONTH_MIN = 14400
const int AUTO_MONTH_MAX = 604800
const int AUTO_SESS_MIN  = 0
const int AUTO_SESS_MAX  = 300
const int AUTO_1800_MIN  = 0
const int AUTO_1800_MAX  = 3600
const int AUTO_DWO_MIN   = 0
const int AUTO_DWO_MAX   = 14400
 
color TRANSPARENT    = color.new(color.white, 100)
bool  IS_CRYPTO      = syminfo.type == "crypto"
int   TD_SHIFT_MS    = IS_CRYPTO ? 0 : 6 * MS_PER_HOUR
bool  IS_WEEKLY_PLUS = timeframe.isweekly or timeframe.ismonthly
 
type TOLevel
    float  price
    line   ln
    label  lb
 
type TOCycle
    color          col
    bool           visible     = false
    bool           active      = false
    int            lastCid     = -1
    int            startedCid  = -1
    int            capturedCid = -1
    TOLevel        current
    array<TOLevel> history
 
f_visible(bool enabled, int autoMin, int autoMax, simple string customMin, simple string customMax) =>
    int  cur     = timeframe.in_seconds()
    bool inRange = displayMode == "Auto" ? (cur >= autoMin and cur <= autoMax) : (cur >= timeframe.in_seconds(customMin) and cur <= timeframe.in_seconds(customMax))
    enabled and inRange
 
f_style(bool isActive) =>
    string st = line.style_solid
    if lineStyleMode == "Auto"
        st := isActive ? line.style_dashed : line.style_solid
    else
        st := switch customStyle
            "Dashed" => line.style_dashed
            "Dotted" => line.style_dotted
            => line.style_solid
    st
 
f_labelSize(string s) =>
    switch s
        "Small"  => size.small
        "Normal" => size.normal
        => size.tiny
 
f_tableSize(string s) =>
    switch s
        "Tiny"   => size.tiny
        "Normal" => size.normal
        "Large"  => size.large
        => size.small
 
f_tablePos(string p) =>
    switch p
        "Top Left"      => position.top_left
        "Top Center"    => position.top_center
        "Top Right"     => position.top_right
        "Middle Left"   => position.middle_left
        "Middle Center" => position.middle_center
        "Bottom Left"   => position.bottom_left
        "Bottom Center" => position.bottom_center
        "Bottom Right"  => position.bottom_right
        => position.middle_right
 
f_sessionName(int idx) =>
    switch idx
        0 => "Asia"
        1 => "London"
        2 => "NY"
        => "PM"
 
f_sessionCustomName(int idx) =>
    switch idx
        0 => nameAsia
        1 => nameLondon
        2 => nameNY
        => namePM
 
f_labelText(string autoTxt, string customTxt) =>
    string res = autoTxt
    if labelPreset == "Custom Names"
        res := customTxt
    else if labelPreset == "Time"
        res := str.format_time(time, "HH:mm", TZ)
    res
 
f_price(TOCycle c) =>
    float p = na
    if not na(c.current)
        p := c.current.price
    p
 
f_fixedCross(int targetEtMin, int curTdMin, int prevTdMin, bool freshDay) =>
    int  tgt       = (targetEtMin - DAY_START_MIN + MIN_PER_DAY) % MIN_PER_DAY
    bool reached   = curTdMin >= tgt and curTdMin - tgt < 60
    bool wasBefore = freshDay or prevTdMin < tgt
    timeframe.isintraday and reached and wasBefore
 
method capture(TOCycle this, float price, int cid, string txt) =>
    if not na(this.current)
        TOLevel prev = this.current
        if showHistory
            line.set_x2(prev.ln, bar_index)
            line.set_style(prev.ln, f_style(false))
            if not na(prev.lb)
                label.set_x(prev.lb, bar_index)
            this.history.push(prev)
            while this.history.size() > maxHistory
                TOLevel old = this.history.shift()
                line.delete(old.ln)
                label.delete(old.lb)
        else
            line.delete(prev.ln)
            label.delete(prev.lb)
    line  newLn = line.new(bar_index, price, bar_index + barOffset, price, xloc = xloc.bar_index, extend = extend.none, color = this.col, style = f_style(this.active), width = lineWidth)
    label newLb = na
    if showLabels
        newLb := label.new(bar_index + barOffset, price, text = txt, xloc = xloc.bar_index, color = TRANSPARENT, style = label.style_label_left, textcolor = this.col, size = f_labelSize(labelSize), textalign = text.align_left, tooltip = txt + " : " + str.tostring(price, format.mintick))
    this.current     := TOLevel.new(price, newLn, newLb)
    this.capturedCid := cid
 
method refresh(TOCycle this) =>
    if this.visible and not na(this.current)
        int x2 = bar_index + barOffset
        line.set_x2(this.current.ln, x2)
        line.set_style(this.current.ln, f_style(this.active))
        if not na(this.current.lb)
            label.set_x(this.current.lb, x2)
 
method process(TOCycle this, int cid, int q, string autoTxt, string customTxt) =>
    if this.visible
        if cid != this.lastCid
            if this.lastCid != -1
                this.startedCid := cid
            this.lastCid := cid
        if q >= 1 and this.capturedCid != cid and this.startedCid == cid
            this.active := q == 1
            this.capture(open, cid, f_labelText(autoTxt, customTxt))
        this.active := q == 1 and this.capturedCid == cid
 
method processFixed(TOCycle this, bool trigger, string autoTxt, string customTxt) =>
    if this.visible and trigger
        this.active := false
        this.capture(open, bar_index, f_labelText(autoTxt, customTxt))
 
f_biasRow(table t, int row, TOCycle c, string cycleName) =>
    int   r = row
    float p = f_price(c)
    if c.visible and not na(p)
        bool above = close >= p
        table.cell(t, 0, r, cycleName, text_color = tableTextColor, text_size = f_tableSize(tableTextSize), text_halign = text.align_right)
        table.cell(t, 1, r, above ? "Above" : "Below", text_color = above ? aboveColor : belowColor, text_size = f_tableSize(tableTextSize), text_halign = text.align_left)
        r += 1
    r
 
int etMinOfDay = hour(time, TZ) * 60 + minute(time, TZ)
int tdMin      = (etMinOfDay - DAY_START_MIN + MIN_PER_DAY) % MIN_PER_DAY
int tdSec      = tdMin * 60 + second(time, TZ)
int sessIdx    = math.min(3, int(tdSec / SESSION_SEC))
int sessSec    = tdSec - sessIdx * SESSION_SEC
int q90        = math.min(3, int(sessSec / Q90_SEC))
int q90Sec     = sessSec - q90 * Q90_SEC
int qMicro     = math.min(3, int(q90Sec / MICRO_SEC))
 
bool newIntraDay = bar_index > 0 and (tdMin < nz(tdMin[1]) or time - nz(time[1]) >= MS_PER_DAY)
var int dayCount = 0
if newIntraDay
    dayCount += 1
 
int cidDaily = dayCount
int cid90m   = dayCount * 4 + sessIdx
int cidMicro = cid90m * 4 + q90
 
int    tdT      = timeframe.isintraday ? time + TD_SHIFT_MS : IS_CRYPTO ? time : time_tradingday
string tdTz     = timeframe.isintraday ? TZ : "UTC"
int    tdYear   = year(tdT, tdTz)
int    tdMonth  = month(tdT, tdTz)
int    tdDom    = dayofmonth(tdT, tdTz)
int    tdDayKey = tdYear * 10000 + tdMonth * 100 + tdDom
int    tdWd     = (dayofweek(tdT, tdTz) + 5) % 7
int    monthKey = tdYear * 12 + tdMonth
 
bool newTradingDay = bar_index > 0 and tdDayKey != nz(tdDayKey[1])
 
var int weekCount  = 0
var int weekStartT = 0
if barstate.isfirst
    weekStartT := tdT
bool newWeek = newTradingDay and (tdWd < nz(tdWd[1]) or tdT - weekStartT >= 7 * MS_PER_DAY)
if newWeek
    weekCount  += 1
    weekStartT := tdT
 
bool newMonth = bar_index > 0 and monthKey != nz(monthKey[1])
var int weekInMonth = 1
if newMonth
    weekInMonth := 1
else if newWeek
    weekInMonth += 1
 
int monthLo  = IS_CRYPTO ? 2 : 4
int qMonthly = IS_WEEKLY_PLUS ? (tdDom < monthLo ? 0 : tdDom <= monthLo + 6 ? 1 : 2) : weekInMonth - 1
int qWeekly  = tdWd
 
int  prevTdMin = nz(tdMin[1])
bool trig0830  = f_fixedCross(OPEN_0830, tdMin, prevTdMin, newIntraDay)
bool trig0930  = f_fixedCross(OPEN_0930, tdMin, prevTdMin, newIntraDay)
bool trig1000  = f_fixedCross(OPEN_1000, tdMin, prevTdMin, newIntraDay)
bool trig1800  = f_fixedCross(OPEN_1800, tdMin, prevTdMin, newIntraDay)
bool trigDWO   = newWeek
 
var bool visMicro   = f_visible(showMicro,   AUTO_MICRO_MIN, AUTO_MICRO_MAX, tfMicroMin,  tfMicroMax)
var bool vis90m     = f_visible(show90m,     AUTO_90M_MIN,   AUTO_90M_MAX,   tf90mMin,    tf90mMax)
var bool visDaily   = f_visible(showDaily,   AUTO_DAY_MIN,   AUTO_DAY_MAX,   tfDailyMin,  tfDailyMax)
var bool visWeekly  = f_visible(showWeekly,  AUTO_WEEK_MIN,  AUTO_WEEK_MAX,  tfWeeklyMin, tfWeeklyMax)
var bool visMonthly = f_visible(showMonthly, AUTO_MONTH_MIN, AUTO_MONTH_MAX, tfMonthMin,  tfMonthMax)
var bool vis0830    = f_visible(show0830,    AUTO_SESS_MIN,  AUTO_SESS_MAX,  tfSessMin,   tfSessMax)
var bool vis0930    = f_visible(show0930,    AUTO_SESS_MIN,  AUTO_SESS_MAX,  tfSessMin,   tfSessMax)
var bool vis1000    = f_visible(show1000,    AUTO_SESS_MIN,  AUTO_SESS_MAX,  tfSessMin,   tfSessMax)
var bool vis1800    = f_visible(show1800,    AUTO_1800_MIN,  AUTO_1800_MAX,  tf1800Min,   tf1800Max)
var bool visDWO     = f_visible(showDWO,     AUTO_DWO_MIN,   AUTO_DWO_MAX,   tfDWOMin,    tfDWOMax)
 
string txtMicroAuto = "Micro TO " + f_sessionName(sessIdx) + " Q" + str.tostring(q90 + 1)
string txt90mAuto   = f_sessionName(sessIdx) + " TO"
string txt90mCustom = f_sessionCustomName(sessIdx)
 
var TOCycle cMicro   = TOCycle.new(colMicro,   visMicro,   history = array.new<TOLevel>())
var TOCycle c90m     = TOCycle.new(col90m,     vis90m,     history = array.new<TOLevel>())
var TOCycle cDaily   = TOCycle.new(colDaily,   visDaily,   history = array.new<TOLevel>())
var TOCycle cWeekly  = TOCycle.new(colWeekly,  visWeekly,  history = array.new<TOLevel>())
var TOCycle cMonthly = TOCycle.new(colMonthly, visMonthly, history = array.new<TOLevel>())
var TOCycle c0830    = TOCycle.new(col0830,    vis0830,    history = array.new<TOLevel>())
var TOCycle c0930    = TOCycle.new(col0930,    vis0930,    history = array.new<TOLevel>())
var TOCycle c1000    = TOCycle.new(col1000,    vis1000,    history = array.new<TOLevel>())
var TOCycle c1800    = TOCycle.new(col1800,    vis1800,    history = array.new<TOLevel>())
var TOCycle cDWO     = TOCycle.new(colDWO,     visDWO,     history = array.new<TOLevel>())
 
cMonthly.process(monthKey,  qMonthly, "True Month",  nameMonth)
cWeekly.process(weekCount,  qWeekly,  "True Week",   nameWeek)
cDaily.process(cidDaily,    sessIdx,  "True Day",    nameDay)
c90m.process(cid90m,        q90,      txt90mAuto,    txt90mCustom)
cMicro.process(cidMicro,    qMicro,   txtMicroAuto,  nameMicro)
 
c0830.processFixed(trig0830, "8:30 Open",     name0830)
c0930.processFixed(trig0930, "Equities Open", name0930)
c1000.processFixed(trig1000, "10:00 Open",    name1000)
c1800.processFixed(trig1800, "18:00 Open",    name1800)
cDWO.processFixed(trigDWO,   "Weekly Open",   nameDWO)
 
if barstate.islast
    cMonthly.refresh()
    cWeekly.refresh()
    cDaily.refresh()
    c90m.refresh()
    cMicro.refresh()
    c0830.refresh()
    c0930.refresh()
    c1000.refresh()
    c1800.refresh()
    cDWO.refresh()
 
var table biasTable = table.new(f_tablePos(tablePos), 2, 5, bgcolor = TRANSPARENT, frame_color = TRANSPARENT, frame_width = 0, border_color = TRANSPARENT, border_width = 0)
 
if showTable and barstate.islast
    table.clear(biasTable, 0, 0, 1, 4)
    int row = 0
    row := f_biasRow(biasTable, row, cMicro,   "Micro")
    row := f_biasRow(biasTable, row, c90m,     "90m")
    row := f_biasRow(biasTable, row, cDaily,   "Daily")
    row := f_biasRow(biasTable, row, cWeekly,  "Weekly")
    row := f_biasRow(biasTable, row, cMonthly, "Monthly")
 
float toMicro   = cMicro.visible   ? f_price(cMicro)   : na
float to90m     = c90m.visible     ? f_price(c90m)     : na
float toDaily   = cDaily.visible   ? f_price(cDaily)   : na
float toWeekly  = cWeekly.visible  ? f_price(cWeekly)  : na
float toMonthly = cMonthly.visible ? f_price(cMonthly) : na
 
int biasMicro   = na(toMicro)   ? 0 : close >= toMicro   ? 1 : -1
int bias90m     = na(to90m)     ? 0 : close >= to90m     ? 1 : -1
int biasDaily   = na(toDaily)   ? 0 : close >= toDaily   ? 1 : -1
int biasWeekly  = na(toWeekly)  ? 0 : close >= toWeekly  ? 1 : -1
int biasMonthly = na(toMonthly) ? 0 : close >= toMonthly ? 1 : -1
 
bool sameMicro   = toMicro   == toMicro[1]
bool same90m     = to90m     == to90m[1]
bool sameDaily   = toDaily   == toDaily[1]
bool sameWeekly  = toWeekly  == toWeekly[1]
bool sameMonthly = toMonthly == toMonthly[1]
 
bool crossMicro   = ta.cross(close, toMicro)   and sameMicro
bool cross90m     = ta.cross(close, to90m)     and same90m
bool crossDaily   = ta.cross(close, toDaily)   and sameDaily
bool crossWeekly  = ta.cross(close, toWeekly)  and sameWeekly
bool crossMonthly = ta.cross(close, toMonthly) and sameMonthly
 
alertcondition(crossMicro,   "Micro TO Cross",   "True Opens [Pro +]: {{ticker}} crossed the Micro TO at {{close}}")
alertcondition(cross90m,     "90m TO Cross",     "True Opens [Pro +]: {{ticker}} crossed the 90m TO at {{close}}")
alertcondition(crossDaily,   "True Day Cross",   "True Opens [Pro +]: {{ticker}} crossed the True Day at {{close}}")
alertcondition(crossWeekly,  "True Week Cross",  "True Opens [Pro +]: {{ticker}} crossed the True Week at {{close}}")
alertcondition(crossMonthly, "True Month Cross", "True Opens [Pro +]: {{ticker}} crossed the True Month at {{close}}")
 
alertcondition(biasMicro   == 1  and biasMicro[1]   == -1 and sameMicro,   "Micro Bias Above",   "True Opens [Pro +]: {{ticker}} Micro bias changed to Above at {{close}}")
alertcondition(biasMicro   == -1 and biasMicro[1]   == 1  and sameMicro,   "Micro Bias Below",   "True Opens [Pro +]: {{ticker}} Micro bias changed to Below at {{close}}")
alertcondition(bias90m     == 1  and bias90m[1]     == -1 and same90m,     "90m Bias Above",     "True Opens [Pro +]: {{ticker}} 90m bias changed to Above at {{close}}")
alertcondition(bias90m     == -1 and bias90m[1]     == 1  and same90m,     "90m Bias Below",     "True Opens [Pro +]: {{ticker}} 90m bias changed to Below at {{close}}")
alertcondition(biasDaily   == 1  and biasDaily[1]   == -1 and sameDaily,   "Daily Bias Above",   "True Opens [Pro +]: {{ticker}} Daily bias changed to Above at {{close}}")
alertcondition(biasDaily   == -1 and biasDaily[1]   == 1  and sameDaily,   "Daily Bias Below",   "True Opens [Pro +]: {{ticker}} Daily bias changed to Below at {{close}}")
alertcondition(biasWeekly  == 1  and biasWeekly[1]  == -1 and sameWeekly,  "Weekly Bias Above",  "True Opens [Pro +]: {{ticker}} Weekly bias changed to Above at {{close}}")
alertcondition(biasWeekly  == -1 and biasWeekly[1]  == 1  and sameWeekly,  "Weekly Bias Below",  "True Opens [Pro +]: {{ticker}} Weekly bias changed to Below at {{close}}")
alertcondition(biasMonthly == 1  and biasMonthly[1] == -1 and sameMonthly, "Monthly Bias Above", "True Opens [Pro +]: {{ticker}} Monthly bias changed to Above at {{close}}")
alertcondition(biasMonthly == -1 and biasMonthly[1] == 1  and sameMonthly, "Monthly Bias Below", "True Opens [Pro +]: {{ticker}} Monthly bias changed to Below at {{close}}")

← 返回列表