Simplistic Trading | Trading Sessions

briangtrades · study · 75 行 · 点赞 9 · 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/
// © briangtrades
 
 
 //@version=6
indicator("Simplistic Trading | Trading Sessions", overlay=true, max_boxes_count=500, max_labels_count=500)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SESSION SETTINGS — CALIFORNIA TIME
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
string TZ = "America/Los_Angeles"
 
showNY = input.bool(true, "Show New York Session")
showAsia = input.bool(true, "Show Asian Session")
 
nySession = input.session("0630-0800", "New York (6:30 AM – 8:00 AM)")
asiaSession = input.session("1800-2000", "Asian (6:00 PM – 8:00 PM)")
 
shadeColor = input.color(color.silver, "Session Shade Color")
shadeTransparency = input.int(82, "Shade Transparency", minval=0, maxval=100)
 
labelColor = input.color(color.gray, "Label Background")
labelTextColor = input.color(color.white, "Label Text")
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SESSION DETECTION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
inNY = not na(time(timeframe.period, nySession, TZ))
inAsia = not na(time(timeframe.period, asiaSession, TZ))
 
nyStart = inNY and not inNY[1]
asiaStart = inAsia and not inAsia[1]
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SESSION SHADING
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bgcolor(showNY and inNY ? color.new(shadeColor, shadeTransparency) : na, title="New York Session")
bgcolor(showAsia and inAsia ? color.new(shadeColor, shadeTransparency) : na, title="Asian Session")
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SESSION LABELS — TOP OF CHART AREA
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var label nyLabel = na
var label asiaLabel = na
 
if showNY and nyStart
    nyLabel := label.new(
         bar_index, high, "NEW YORK",
         xloc=xloc.bar_index,
         yloc=yloc.abovebar,
         style=label.style_label_down,
         color=color.new(labelColor, 15),
         textcolor=labelTextColor,
         size=size.small)
 
if showAsia and asiaStart
    asiaLabel := label.new(
         bar_index, high, "ASIAN SESSION",
         xloc=xloc.bar_index,
         yloc=yloc.abovebar,
         style=label.style_label_down,
         color=color.new(labelColor, 15),
         textcolor=labelTextColor,
         size=size.small)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// REMOVE LABELS WHEN SESSIONS ARE DISABLED
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if not showNY and not na(nyLabel)
    label.delete(nyLabel)
    nyLabel := na
 
if not showAsia and not na(asiaLabel)
    label.delete(asiaLabel)
    asiaLabel := na

← 返回列表