AE_DAMRS LEVELS w QT

A3rl · study · 413 行 · 点赞 8 · 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/
// © A3rl
 
//@version=6
indicator("AE_DAMRS LEVELS w QT", overlay=true, shorttitle="AE_DAMRS w QT")
 
//#region Inputs
groupGeneral = "General"
targetTimezone = input.int(-5, "Target Timezone (GMT)", tooltip="The GMT offset you want lines locked to. Default -5 = Set -4 for GMT-4, 12 for GMT+12, etc.", minval=-12, maxval=14, group=groupGeneral)
//showBrokerServerTime = input.bool(true, "Show Broker Server Time", group=groupGeneral)
 
show4HOpen = input.bool(true, title="Show 4H Opening Price")
show6HOpen = input.bool(true, title="Show 6H Opening Price")
show90mOpen = input.bool(true, title="Show 90m Opening Price")
 
show4H = input.bool(false, title="Show 4H High/Low")
show1H = input.bool(true, title="Show 1H High/Low")
show6H = input.bool(true, title="Show 6H High/Low")
show90m = input.bool(true, title="Show 90m High/Low")
 
lineWidth = input.int(1, "Line Width", minval=1, maxval=5, group=groupGeneral)
 
// 4H and 6H current candle opening prices
o4 = request.security(syminfo.tickerid, "240", open, lookahead=barmerge.lookahead_on)
o6 = request.security(syminfo.tickerid, "360", open, lookahead=barmerge.lookahead_on)
o90 = request.security(syminfo.tickerid, "90", open, lookahead=barmerge.lookahead_on)
 
// 4H / 6H Opening Prices
plot(show4HOpen ? o4 : na, title="4H Open", color=color.black, linewidth=1, style=plot.style_circles)
plot(show6HOpen ? o6 : na, title="6H Open", color=color.aqua, linewidth=1, style=plot.style_circles)
plot(show90mOpen ? o90 : na, title="90m Open", color=color.green, linewidth=1, style=plot.style_circles)
 
showDailyOpen   = input.bool(true, title="Show Daily Open (18:00 NY)")
showMidnightOpen = input.bool(true, title="Show Midnight Open (00:00 NY)")
 
// high low 
h4 = request.security(syminfo.tickerid, "240", high)
l4 = request.security(syminfo.tickerid, "240", low)
 
// 1H data
h1 = request.security(syminfo.tickerid, "60", high)
l1 = request.security(syminfo.tickerid, "60", low)
 
// 6H data
h6 = request.security(syminfo.tickerid, "360", high)
l6 = request.security(syminfo.tickerid, "360", low)
 
// 90m data
h90 = request.security(syminfo.tickerid, "90", high)
l90 = request.security(syminfo.tickerid, "90", low)
 
// Daily and Midnight opening prices (New York timezone)
dailyOpen = ta.valuewhen(hour(time, "America/New_York") == 18 and minute(time, "America/New_York") == 0, open, 0)
 
midnightOpen = ta.valuewhen(hour(time, "America/New_York") == 0 and minute(time, "America/New_York") == 0, open, 0)
 
// Daily / Midnight Opening Prices
plot(showDailyOpen ? dailyOpen : na, title="Daily Open (18:00 NY)", color=color.orange, linewidth=1, style=plot.style_circles)
plot(showMidnightOpen ? midnightOpen : na, title="Midnight Open (00:00 NY)", color=color.fuchsia, linewidth=1, style=plot.style_circles)
 
// 4H High / Low
plot(show4H ? h4 : na, title="4H High", color=color.black, linewidth=1, style=plot.style_circles)
plot(show4H ? l4 : na, title="4H Low", color=color.black, linewidth=1, style=plot.style_circles)
 
// 1H High / Low
plot(show1H ? h1 : na, title="1H High", color=color.green, linewidth=1, style=plot.style_circles)
plot(show1H ? l1 : na, title="1H Low", color=color.green, linewidth=1, style=plot.style_circles)
 
// 6H High / Low
plot(show6H ? h6 : na, title="6H High", color=color.aqua, linewidth=1, style=plot.style_circles)
plot(show6H ? l6 : na, title="6H Low", color=color.aqua, linewidth=1, style=plot.style_circles)
 
// 90m High / Low
plot(show90m ? h90 : na, title="90m High", color=color.gray, linewidth=1, style=plot.style_circles)
plot(show90m ? l90 : na, title="90m Low", color=color.gray, linewidth=1, style=plot.style_circles)
 
 
//#region Time 1
name1 = input.string("T1", "Name", group="Time 1")
enable1 = input.bool(true, "Show Time 1", group="Time 1")
hour1 = input.int(20, "Hour (0-23)", minval=0, maxval=23, group="Time 1")
min1 = input.int(18, "Minute (0-59)", minval=0, maxval=59, group="Time 1")
color1 = input.color(color.blue, "Color", group="Time 1")
//#endregion
 
//#region Time 2
name2 = input.string("T2", "Name", group="Time 2")
enable2 = input.bool(true, "Show Time 2", group="Time 2")
hour2 = input.int(22, "Hour (0-23)", minval=0, maxval=23, group="Time 2")
min2 = input.int(36, "Minute (0-59)", minval=0, maxval=59, group="Time 2")
color2 = input.color(color.black, "Color", group="Time 2")
//#endregion
 
//#region Time 3
name3 = input.string("T3", "Name", group="Time 3")
enable3 = input.bool(true, "Show Time 3", group="Time 3")
hour3 = input.int(3, "Hour (0-23)", minval=0, maxval=23, group="Time 3")
min3 = input.int(12, "Minute (0-59)", minval=0, maxval=59, group="Time 3")
color3 = input.color(color.black, "Color", group="Time 3")
//#endregion
 
//#region Time 4
name4 = input.string("T4", "Name", group="Time 4")
enable4 = input.bool(true, "Show Time 4", group="Time 4")
hour4 = input.int(5, "Hour (0-23)", minval=0, maxval=23, group="Time 4")
min4 = input.int(30, "Minute (0-59)", minval=0, maxval=59, group="Time 4")
color4 = input.color(color.fuchsia, "Color", group="Time 4")
//#endregion
 
//#region Time 5
name5 = input.string("T5", "Name", group="Time 5")
enable5 = input.bool(true, "Show Time 5", group="Time 5")
hour5 = input.int(7, "Hour (0-23)", minval=0, maxval=23, group="Time 5")
min5 = input.int(48, "Minute (0-59)", minval=0, maxval=59, group="Time 5")
color5 = input.color(color.black, "Color", group="Time 5")
//#endregion
 
//#region Time 6
name6 = input.string("T6", "Name", group="Time 6")
enable6 = input.bool(true, "Show Time 6", group="Time 6")
hour6 = input.int(0, "Hour (0-23)", minval=0, maxval=23, group="Time 6")
min6 = input.int(54, "Minute (0-59)", minval=0, maxval=59, group="Time 6")
color6 = input.color(color.blue, "Color", group="Time 6")
//#endregion
 
//#region Time 7
name7 = input.string("T7", "Name", group="Time 7")
enable7 = input.bool(true, "Show Time 7", group="Time 7")
hour7 = input.int(10, "Hour (0-23)", minval=0, maxval=23, group="Time 7")
min7 = input.int(6, "Minute (0-59)", minval=0, maxval=59, group="Time 7")
color7 = input.color(color.blue, "Color", group="Time 7")
//#endregion
 
//#region Time 1 - set 2 1/4 in time
name8 = input.string("T8", "Name", group="Time 8")
enable8 = input.bool(true, "Show Time 8", group="Time 8")
hour8 = input.int(19, "Hour (0-23)", minval=0, maxval=23, group="Time 8")
min8 = input.int(9, "Minute (0-59)", minval=0, maxval=59, group="Time 8")
color8 = input.color(color.orange, "Color", group="Time 8")
//#endregion
 
//#region Time 2
name9 = input.string("T9", "Name", group="Time 9")
enable9 = input.bool(true, "Show Time 9", group="Time 9")
hour9 = input.int(21, "Hour (0-23)", minval=0, maxval=23, group="Time 9")
min9 = input.int(27, "Minute (0-59)", minval=0, maxval=59, group="Time 9")
color9 = input.color(color.orange, "Color", group="Time 9")
//#endregion
 
//#region Time 3
name10 = input.string("T10", "Name", group="Time 10")
enable10 = input.bool(true, "Show Time 10", group="Time 10")
hour10 = input.int(23, "Hour (0-23)", minval=0, maxval=23, group="Time 10")
min10 = input.int(45, "Minute (0-59)", minval=0, maxval=59, group="Time 10")
color10 = input.color(color.orange, "Color", group="Time 10")
//#endregion
 
//#region Time 4
name11 = input.string("T11", "Name", group="Time 11")
enable11 = input.bool(true, "Show Time 11", group="Time 11")
hour11 = input.int(2, "Hour (0-23)", minval=0, maxval=23, group="Time 11")
min11 = input.int(3, "Minute (0-59)", minval=0, maxval=59, group="Time 11")
color11 = input.color(color.orange, "Color", group="Time 11")
//#endregion
 
//#region Time 5
name12 = input.string("T12", "Name", group="Time 12")
enable12 = input.bool(true, "Show Time 12", group="Time 12")
hour12 = input.int(4, "Hour (0-23)", minval=0, maxval=23, group="Time 12")
min12 = input.int(21, "Minute (0-59)", minval=0, maxval=59, group="Time 12")
color12 = input.color(color.orange, "Color", group="Time 12")
//#endregion
 
//#region Time 6
name13 = input.string("T13", "Name", group="Time 13")
enable13 = input.bool(true, "Show Time 13", group="Time 13")
hour13 = input.int(6, "Hour (0-23)", minval=0, maxval=23, group="Time 13")
min13 = input.int(39, "Minute (0-59)", minval=0, maxval=59, group="Time 13")
color13 = input.color(color.orange, "Color", group="Time 13")
//#endregion
 
//#region Time 7
name14 = input.string("T14", "Name", group="Time 14")
enable14 = input.bool(true, "Show Time 14", group="Time 14")
hour14 = input.int(8, "Hour (0-23)", minval=0, maxval=23, group="Time 14")
min14 = input.int(57, "Minute (0-59)", minval=0, maxval=59, group="Time 14")
color14 = input.color(color.orange, "Color", group="Time 14")
//#endregion
 
//#region Time 6
name15 = input.string("T15", "Name", group="Time 15")
enable15 = input.bool(true, "Show Time 15", group="Time 15")
hour15 = input.int(11, "Hour (0-23)", minval=0, maxval=23, group="Time 15")
min15 = input.int(15, "Minute (0-59)", minval=0, maxval=59, group="Time 15")
color15 = input.color(color.orange, "Color", group="Time 15")
//#endregion
 
//#region Time 7
name16 = input.string("T16", "Name", group="Time 16")
enable16 = input.bool(true, "Show Time 16", group="Time 16")
hour16 = input.int(13, "Hour (0-23)", minval=0, maxval=23, group="Time 16")
min16 = input.int(33, "Minute (0-59)", minval=0, maxval=59, group="Time 16")
color16 = input.color(color.orange, "Color", group="Time 16")
//#endregion
 
//#region Time 5
name17 = input.string("T17", "Name", group="Time 17")
enable17 = input.bool(true, "Show Time 17", group="Time 17")
hour17 = input.int(12, "Hour (0-23)", minval=0, maxval=23, group="Time 17")
min17 = input.int(24, "Minute (0-59)", minval=0, maxval=59, group="Time 17")
color17 = input.color(color.black, "Color", group="Time 17")
//#endregion
 
//#region Time 7
name18 = input.string("T18", "Name", group="Time 18")
enable18 = input.bool(true, "Show Time 18", group="Time 18")
hour18 = input.int(14, "Hour (0-23)", minval=0, maxval=23, group="Time 18")
min18 = input.int(42, "Minute (0-59)", minval=0, maxval=59, group="Time 18")
color18 = input.color(color.blue, "Color", group="Time 18")
//#endregion
 
//#region Time logic
exchangeOffsetRaw = hour(time) - hour(time, "UTC")
exchangeOffset = exchangeOffsetRaw > 12 ? exchangeOffsetRaw - 24 : exchangeOffsetRaw < -12 ? exchangeOffsetRaw + 24 : exchangeOffsetRaw
//#endregion
 
//#region Draw function
drawLine(_enabled, _H, _M, _color) =>
    utcHour = (_H - targetTimezone + 24) % 24
    brokerHour = (utcHour + exchangeOffset + 24) % 24
    if _enabled and hour(time) == brokerHour and minute(time) == _M
        line.new(bar_index, low - ta.tr, bar_index, high + ta.tr, extend=extend.both, color=_color, style=line.style_solid, width=lineWidth)
//#endregion
 
// Call all draw functions on every bar
 
drawLine(enable1, hour1, min1, color1)
drawLine(enable2, hour2, min2, color2)
drawLine(enable3, hour3, min3, color3)
drawLine(enable4, hour4, min4, color4)
drawLine(enable5, hour5, min5, color5)
drawLine(enable6, hour6, min6, color6)
drawLine(enable7, hour7, min7, color7)
drawLine(enable8, hour8, min8, color8)
drawLine(enable9, hour9, min9, color9)
drawLine(enable10, hour10, min10, color10)
drawLine(enable11, hour11, min11, color11)
drawLine(enable12, hour12, min12, color12)
drawLine(enable13, hour13, min13, color13)
drawLine(enable14, hour14, min14, color14)
drawLine(enable15, hour15, min15, color15)
drawLine(enable16, hour16, min16, color16)
drawLine(enable17, hour17, min17, color17)
drawLine(enable18, hour18, min18, color18)
 
//var label offsetLabel = na
//if showBrokerServerTime and barstate.islast
//    label.delete(offsetLabel)
//    offsetLabel := label.new(bar_index, high, "Broker: UTC" + (exchangeOffset >= 0 ? "+" : "") + str.tostring(exchangeOffset), style=label.style_label_left, textcolor=color.white, color=color.new(color.black, 0))
 
//====================================================
// TRUE OPENING PRICES - TABLE CALCULATIONS
//====================================================
 
string nyTZ = "America/New_York"
 
// Calculate the four NY opening prices using 1-minute data.
// This avoids depending on the chart timeframe.
 
[tmo, two, tdo, nyO] = request.security(syminfo.tickerid, "1", [
 
    // TMO: Second Monday of the month, 00:00 NY
    ta.valuewhen(
         dayofweek(time, nyTZ) == dayofweek.monday and
         dayofmonth(time, nyTZ) >= 8 and
         dayofmonth(time, nyTZ) <= 14 and
         hour(time, nyTZ) == 0 and
         minute(time, nyTZ) == 0,
         open, 0),
 
    // TWO: Tuesday, 18:00 NY
    ta.valuewhen(
         dayofweek(time, nyTZ) == dayofweek.tuesday and
         hour(time, nyTZ) == 18 and
         minute(time, nyTZ) == 0,
         open, 0),
 
    // TDO: Daily, 00:00 NY
    ta.valuewhen(
         hour(time, nyTZ) == 0 and
         minute(time, nyTZ) == 0,
         open, 0),
 
    // NYO: Daily, 09:30 NY
    ta.valuewhen(
         hour(time, nyTZ) == 9 and
         minute(time, nyTZ) == 30,
         open, 0)
 
], lookahead=barmerge.lookahead_on)
 
 
//====================================================
// TMSO: SECOND 90-MINUTE OPENING IN EACH 6H CYCLE
//====================================================
 
// Detect the second 90m candle inside each 6H period.
// The 6H period identifier is obtained from the 90m context.
 
tmso = request.security(syminfo.tickerid, "90",
 
    ta.valuewhen(
         time("360") == time("360")[1] and
         time("360")[1] != time("360")[2],
         open, 0),
 
    lookahead=barmerge.lookahead_on)
 
 
//====================================================
// STATUS TABLE
//====================================================
 
// Above = RED (Bearish context / Look for SHORT)
// Below = GREEN (Bullish context / Look for LONG)
 
statusText(float level) =>
    na(level) ? "N/A" : close > level ? "Above" : "Below"
 
statusColor(float level) =>
    na(level) ? color.gray : close > level ? color.red : color.green
 
 
// Create table: 2 columns, 6 rows (header + 5 references)
 
var table opTable = table.new(
     position.bottom_left,
     2, 6,
     border_width=1,
     border_color=color.new(color.gray, 65),
     frame_width=1,
     frame_color=color.new(color.gray, 65))
 
 
// Update table on the latest bar
 
if barstate.islast
 
    // Header
    table.cell(opTable, 0, 0, "TO",
         text_color=color.white,
         bgcolor=color.rgb(45, 45, 45),
         text_size=size.small)
 
    table.cell(opTable, 1, 0, "STATUS",
         text_color=color.white,
         bgcolor=color.rgb(45, 45, 45),
         text_size=size.small)
 
    // TMSO
    table.cell(opTable, 0, 1, "TMSO",
         text_color=color.white,
         bgcolor=color.new(color.black, 15),
         text_size=size.small)
 
    table.cell(opTable, 1, 1, statusText(tmso),
         text_color=color.white,
         bgcolor=statusColor(tmso),
         text_size=size.small)
 
    // NYO
    table.cell(opTable, 0, 2, "NYO",
         text_color=color.white,
         bgcolor=color.new(color.black, 15),
         text_size=size.small)
 
    table.cell(opTable, 1, 2, statusText(nyO),
         text_color=color.white,
         bgcolor=statusColor(nyO),
         text_size=size.small)
 
    // TDO
    table.cell(opTable, 0, 3, "TDO",
         text_color=color.white,
         bgcolor=color.new(color.black, 15),
         text_size=size.small)
 
    table.cell(opTable, 1, 3, statusText(tdo),
         text_color=color.white,
         bgcolor=statusColor(tdo),
         text_size=size.small)
 
    // TWO
    table.cell(opTable, 0, 4, "TWO",
         text_color=color.white,
         bgcolor=color.new(color.black, 15),
         text_size=size.small)
 
    table.cell(opTable, 1, 4, statusText(two),
         text_color=color.white,
         bgcolor=statusColor(two),
         text_size=size.small)
 
    // TMO
    table.cell(opTable, 0, 5, "TMO",
         text_color=color.white,
         bgcolor=color.new(color.black, 15),
         text_size=size.small)
 
    table.cell(opTable, 1, 5, statusText(tmo),
         text_color=color.white,
         bgcolor=statusColor(tmo),
         text_size=size.small)

← 返回列表