本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Trades-Dont-Lie
//@version=5
// Midnight Opening Ranges (w/ Std Dev) [TDL] v2.1
// Plots rectangles showing the price range during 00:00-00:30 EST
// Displays both current and historical ranges with customizable lookback period
// Uses GMT-5 timezone for accurate EST time window
// Properly handles day transitions with separate current/historical colors
// Shows opening price level (12am) for current session
// Features standard deviation levels based on range size with up to 10 customizable levels
// Supports individual or master color control for SD levels
indicator("Midnight Opening Ranges[TDL]", overlay=true)
// General Settings
lookbackDays = input.int(5, "Number of Previous Days", minval=1, maxval=50, group="General Settings")
futureOffset = input.int(20, "Future Bars Extension", minval=0, tooltip="Number of bars to extend into the future", group="General Settings")
// Current Session Settings
var currentGroup = "Current Session"
currentBoxFillColor = input.color(color.new(color.blue, 80), "Box Fill", inline="current_box", group=currentGroup)
currentBoxBorderColor = input.color(color.blue, "Border", inline="current_box", group=currentGroup)
currentMidlineColor = input.color(color.yellow, "Midline", inline="current_mid", group=currentGroup)
currentMidlineStyle = input.string("Dashed", "Style", options=["Solid", "Dotted", "Dashed"], inline="current_mid", group=currentGroup)
// Opening Price Settings
var openGroup = "Opening Price (12am)"
showOpenLabel = input.bool(true, "Show Opening Price", inline="open_main", group=openGroup)
openPriceColor = input.color(color.new(color.red, 0), "Color", inline="open_main", group=openGroup)
openPriceStyle = input.string("Dotted", "Style", options=["Solid", "Dotted", "Dashed"], inline="open_main", group=openGroup)
// Replace the custom opening prices section with this more organized version
var customOpenGroup = "Custom Opening Lines"
// Custom Line 1
showCustomOpen1 = input.bool(true, "Line 1", inline="custom_open1_main", group=customOpenGroup)
customOpen1Hour = input.int(9, "Hour", inline="custom_open1_time", minval=0, maxval=23, group=customOpenGroup)
customOpen1Min = input.int(30, "Min", inline="custom_open1_time", minval=0, maxval=59, group=customOpenGroup)
customOpen1Text = input.string("NY Open", "Label", inline="custom_open1_time", group=customOpenGroup)
customOpen1Color = input.color(color.new(color.green, 0), "Color", inline="custom_open1_style", group=customOpenGroup)
customOpen1Style = input.string("Dotted", "Style", options=["Solid", "Dotted", "Dashed"], inline="custom_open1_style", group=customOpenGroup)
customOpen1LineWidth = input.int(1, "Width", inline="custom_open1_style", minval=1, maxval=4, group=customOpenGroup)
customOpen1TextSize = input.string("Small", "Text Size", options=["Tiny", "Small", "Normal", "Large"], inline="custom_open1_style", group=customOpenGroup)
// Custom Line 2
showCustomOpen2 = input.bool(false, "Line 2", inline="custom_open2_main", group=customOpenGroup)
customOpen2Hour = input.int(10, "Hour", inline="custom_open2_time", minval=0, maxval=23, group=customOpenGroup)
customOpen2Min = input.int(0, "Min", inline="custom_open2_time", minval=0, maxval=59, group=customOpenGroup)
customOpen2Text = input.string("London Close", "Label", inline="custom_open2_time", group=customOpenGroup)
customOpen2Color = input.color(color.new(color.purple, 0), "Color", inline="custom_open2_style", group=customOpenGroup)
customOpen2Style = input.string("Dotted", "Style", options=["Solid", "Dotted", "Dashed"], inline="custom_open2_style", group=customOpenGroup)
customOpen2LineWidth = input.int(1, "Width", inline="custom_open2_style", minval=1, maxval=4, group=customOpenGroup)
customOpen2TextSize = input.string("Small", "Text Size", options=["Tiny", "Small", "Normal", "Large"], inline="custom_open2_style", group=customOpenGroup)
// Historical Session Settings
var historyGroup = "Historical Sessions"
historyBoxFillColor = input.color(color.new(color.gray, 80), "Box Fill", inline="history_box", group=historyGroup)
historyBoxBorderColor = input.color(color.gray, "Border", inline="history_box", group=historyGroup)
historyMidlineColor = input.color(color.white, "Midline", inline="history_mid", group=historyGroup)
historyMidlineStyle = input.string("Dashed", "Style", options=["Solid", "Dotted", "Dashed"], inline="history_mid", group=historyGroup)
showDateLabels = input.bool(true, "Show Date Labels", group=historyGroup)
// Standard Deviation Settings
var sdGroup = "Standard Deviations"
showSD = input.bool(true, "Enable Standard Deviations", group=sdGroup, inline="sd_main")
showHistorySD = input.bool(true, "Show Historical", group=sdGroup, inline="sd_main")
sdStyle = input.string("Dashed", "Style", options=["Solid", "Dotted", "Dashed"], group=sdGroup, inline="sd_main")
showSDLabels = input.bool(true, "Show Labels", group=sdGroup, inline="sd_main")
// Add master color settings
useMasterColor = input.bool(false, "Use Master Color", inline="master_color", group=sdGroup)
masterSDColor = input.color(color.new(color.purple, 0), "", inline="master_color", group=sdGroup)
// SD Level Settings
var sdLevelsGroup = "SD Levels Configuration"
// Level 1-10 settings
show_sd1 = input.bool(true, "Level 1", inline="sd1", group=sdLevelsGroup)
sd1_value = input.float(0.5, "", inline="sd1", group=sdLevelsGroup, step=0.25)
sd1_color = input.color(color.new(color.purple, 0), "", inline="sd1", group=sdLevelsGroup)
show_sd2 = input.bool(true, "Level 2", inline="sd2", group=sdLevelsGroup)
sd2_value = input.float(1.0, "", inline="sd2", group=sdLevelsGroup, step=0.25)
sd2_color = input.color(color.new(color.red, 0), "", inline="sd2", group=sdLevelsGroup)
show_sd3 = input.bool(true, "Level 3", inline="sd3", group=sdLevelsGroup)
sd3_value = input.float(1.5, "", inline="sd3", group=sdLevelsGroup, step=0.25)
sd3_color = input.color(color.new(color.yellow, 0), "", inline="sd3", group=sdLevelsGroup)
show_sd4 = input.bool(true, "Level 4", inline="sd4", group=sdLevelsGroup)
sd4_value = input.float(2.0, "", inline="sd4", group=sdLevelsGroup, step=0.25)
sd4_color = input.color(color.new(color.green, 0), "", inline="sd4", group=sdLevelsGroup)
show_sd5 = input.bool(false, "Level 5", inline="sd5", group=sdLevelsGroup)
sd5_value = input.float(2.5, "", inline="sd5", group=sdLevelsGroup, step=0.25)
sd5_color = input.color(color.new(color.blue, 0), "", inline="sd5", group=sdLevelsGroup)
show_sd6 = input.bool(false, "Level 6", inline="sd6", group=sdLevelsGroup)
sd6_value = input.float(3.0, "", inline="sd6", group=sdLevelsGroup, step=0.25)
sd6_color = input.color(color.new(color.orange, 0), "", inline="sd6", group=sdLevelsGroup)
show_sd7 = input.bool(false, "Level 7", inline="sd7", group=sdLevelsGroup)
sd7_value = input.float(3.5, "", inline="sd7", group=sdLevelsGroup, step=0.25)
sd7_color = input.color(color.new(color.teal, 0), "", inline="sd7", group=sdLevelsGroup)
show_sd8 = input.bool(false, "Level 8", inline="sd8", group=sdLevelsGroup)
sd8_value = input.float(4.0, "", inline="sd8", group=sdLevelsGroup, step=0.25)
sd8_color = input.color(color.new(color.maroon, 0), "", inline="sd8", group=sdLevelsGroup)
show_sd9 = input.bool(false, "Level 9", inline="sd9", group=sdLevelsGroup)
sd9_value = input.float(4.5, "", inline="sd9", group=sdLevelsGroup, step=0.25)
sd9_color = input.color(color.new(color.olive, 0), "", inline="sd9", group=sdLevelsGroup)
show_sd10 = input.bool(false, "Level 10", inline="sd10", group=sdLevelsGroup)
sd10_value = input.float(5.0, "", inline="sd10", group=sdLevelsGroup, step=0.25)
sd10_color = input.color(color.new(color.navy, 0), "", inline="sd10", group=sdLevelsGroup)
// Add this with the other variable declarations
var label[] dateLabels = array.new_label()
// Move these variable declarations to the top with other variables
var float sessionHigh = na
var float sessionLow = na
var int sessionStartTime = na
var int currentDay = dayofmonth(time, "GMT-5")
var float openPrice = na
// Add these with other variable declarations
var float[] customOpen1Prices = array.new_float()
var int[] customOpen1Times = array.new_int()
var float[] customOpen2Prices = array.new_float()
var int[] customOpen2Times = array.new_int()
var line[] customOpen1Lines = array.new_line()
var label[] customOpen1Labels = array.new_label()
var line[] customOpen2Lines = array.new_line()
var label[] customOpen2Labels = array.new_label()
var line customOpen1Line = na
var line customOpen2Line = na
var label customOpen1Label = na
var label customOpen2Label = na
// Replace the first custom open variables and logic with:
var float customOpen1Price = na
var int customOpen1StartTime = na
var float customOpen2Price = na
var int customOpen2StartTime = na
// Replace both capture sections with:
if (hour(time, "GMT-5") == customOpen1Hour) and (minute(time, "GMT-5") == customOpen1Min) and (second(time, "GMT-5") == 0)
customOpen1Price := open
customOpen1StartTime := time
if (hour(time, "GMT-5") == customOpen2Hour) and (minute(time, "GMT-5") == customOpen2Min) and (second(time, "GMT-5") == 0)
customOpen2Price := open
customOpen2StartTime := time
// Define session times
isInTimeWindow = (hour(time, "GMT-5") == 0 and minute(time, "GMT-5") >= 0 and minute(time, "GMT-5") < 30)
newDay = dayofmonth(time, "GMT-5") != dayofmonth(time[1], "GMT-5")
// Arrays to store historical data
var float[] historyHighs = array.new_float()
var float[] historyLows = array.new_float()
var int[] historyTimes = array.new_int()
// Add these variables after the other variable declarations
var box[] historyBoxes = array.new_box()
var line[] historyLines = array.new_line()
var box currentBox = na
var line currentMidline = na
var line openPriceLine = na
var label openPriceLabel = na
var line[] sdLines = array.new_line()
var label[] sdLabels = array.new_label()
// Handle new day
if newDay
if not na(sessionHigh)
array.push(historyHighs, sessionHigh)
array.push(historyLows, sessionLow)
array.push(historyTimes, sessionStartTime)
if array.size(historyHighs) > lookbackDays
array.shift(historyHighs)
array.shift(historyLows)
array.shift(historyTimes)
sessionHigh := na
sessionLow := na
sessionStartTime := na
currentDay := dayofmonth(time, "GMT-5")
// Reset values at the start of new session
if isInTimeWindow and not isInTimeWindow[1]
sessionHigh := high
sessionLow := low
sessionStartTime := time
openPrice := open
// Update high and low during session
if isInTimeWindow
sessionHigh := math.max(sessionHigh, high)
sessionLow := math.min(sessionLow, low)
// Plot boxes and midlines
if barstate.islast
// Clear previous drawings
for b in historyBoxes
box.delete(b)
array.clear(historyBoxes)
// Keep historical midlines and date labels separate from SD cleanup
for l in historyLines
line.delete(l)
array.clear(historyLines)
for l in dateLabels
label.delete(l)
array.clear(dateLabels)
// Clean up SD lines and labels unconditionally
for l in sdLines
line.delete(l)
array.clear(sdLines)
for l in sdLabels
label.delete(l)
array.clear(sdLabels)
if not na(currentBox)
box.delete(currentBox)
if not na(currentMidline)
line.delete(currentMidline)
if not na(openPriceLine)
line.delete(openPriceLine)
if not na(openPriceLabel)
label.delete(openPriceLabel)
if not na(customOpen1Line)
line.delete(customOpen1Line)
if not na(customOpen1Label)
label.delete(customOpen1Label)
if not na(customOpen2Line)
line.delete(customOpen2Line)
if not na(customOpen2Label)
label.delete(customOpen2Label)
// Clean up custom open lines and labels
for l in customOpen1Lines
line.delete(l)
array.clear(customOpen1Lines)
for l in customOpen1Labels
label.delete(l)
array.clear(customOpen1Labels)
for l in customOpen2Lines
line.delete(l)
array.clear(customOpen2Lines)
for l in customOpen2Labels
label.delete(l)
array.clear(customOpen2Labels)
// Plot historical boxes and midlines
for i = 0 to array.size(historyHighs) - 1
float midPrice = (array.get(historyHighs, i) + array.get(historyLows, i)) / 2
int historyTime = array.get(historyTimes, i)
float historyHigh = array.get(historyHighs, i)
float historyLow = array.get(historyLows, i)
// Calculate next day's start time (only for SD lines)
int nextDayTime = historyTime + 86400000 // Add 24 hours in milliseconds
box b = box.new(
left=historyTime,
right=time + (futureOffset * timeframe.multiplier * 60000), // Modified
top=historyHigh,
bottom=historyLow,
bgcolor=historyBoxFillColor,
border_color=historyBoxBorderColor,
xloc=xloc.bar_time)
array.push(historyBoxes, b)
line l = line.new(
x1=historyTime,
y1=midPrice,
x2=time + (futureOffset * timeframe.multiplier * 60000), // Modified
y2=midPrice,
color=historyMidlineColor,
style=historyMidlineStyle == "Solid" ? line.style_solid :
historyMidlineStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(historyLines, l)
// Add date label at midpoint
if showDateLabels
label dateLabel = label.new(
x=time + (futureOffset * timeframe.multiplier * 60000),
y=midPrice,
text=str.format("{0,number,00}/{1,number,00}", month(historyTime, "GMT-5"), dayofmonth(historyTime, "GMT-5")),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=historyMidlineColor,
xloc=xloc.bar_time)
array.push(dateLabels, dateLabel)
// Add historical standard deviations
if showSD and showHistorySD
float historyRange = historyHigh - historyLow
// Level 1
if show_sd1
float dev1 = historyRange * sd1_value
color sdLineColor1 = useMasterColor ? masterSDColor : sd1_color
line upperLine1 = line.new(
x1=historyTime,
y1=historyHigh + dev1,
x2=nextDayTime,
y2=historyHigh + dev1,
color=sdLineColor1,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine1)
line lowerLine1 = line.new(
x1=historyTime,
y1=historyLow - dev1,
x2=nextDayTime,
y2=historyLow - dev1,
color=sdLineColor1,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine1)
if showSDLabels
label upperLabel1 = label.new(
x=nextDayTime,
y=historyHigh + dev1,
text="+" + str.tostring(sd1_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor1,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel1)
label lowerLabel1 = label.new(
x=nextDayTime,
y=historyLow - dev1,
text="-" + str.tostring(sd1_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor1,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel1)
// Repeat for levels 2-4 with respective settings
// Level 2
if show_sd2
float dev2 = historyRange * sd2_value
color sdLineColor2 = useMasterColor ? masterSDColor : sd2_color
line upperLine2 = line.new(
x1=historyTime,
y1=historyHigh + dev2,
x2=nextDayTime,
y2=historyHigh + dev2,
color=sdLineColor2,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine2)
line lowerLine2 = line.new(
x1=historyTime,
y1=historyLow - dev2,
x2=nextDayTime,
y2=historyLow - dev2,
color=sdLineColor2,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine2)
if showSDLabels
label upperLabel2 = label.new(
x=nextDayTime,
y=historyHigh + dev2,
text="+" + str.tostring(sd2_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor2,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel2)
label lowerLabel2 = label.new(
x=nextDayTime,
y=historyLow - dev2,
text="-" + str.tostring(sd2_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor2,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel2)
// Level 3
if show_sd3
float dev3 = historyRange * sd3_value
color sdLineColor3 = useMasterColor ? masterSDColor : sd3_color
line upperLine3 = line.new(
x1=historyTime,
y1=historyHigh + dev3,
x2=nextDayTime,
y2=historyHigh + dev3,
color=sdLineColor3,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine3)
line lowerLine3 = line.new(
x1=historyTime,
y1=historyLow - dev3,
x2=nextDayTime,
y2=historyLow - dev3,
color=sdLineColor3,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine3)
if showSDLabels
label upperLabel3 = label.new(
x=nextDayTime,
y=historyHigh + dev3,
text="+" + str.tostring(sd3_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor3,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel3)
label lowerLabel3 = label.new(
x=nextDayTime,
y=historyLow - dev3,
text="-" + str.tostring(sd3_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor3,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel3)
// Level 4
if show_sd4
float dev4 = historyRange * sd4_value
color sdLineColor4 = useMasterColor ? masterSDColor : sd4_color
line upperLine4 = line.new(
x1=historyTime,
y1=historyHigh + dev4,
x2=nextDayTime,
y2=historyHigh + dev4,
color=sdLineColor4,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine4)
line lowerLine4 = line.new(
x1=historyTime,
y1=historyLow - dev4,
x2=nextDayTime,
y2=historyLow - dev4,
color=sdLineColor4,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine4)
if showSDLabels
label upperLabel4 = label.new(
x=nextDayTime,
y=historyHigh + dev4,
text="+" + str.tostring(sd4_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor4,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel4)
label lowerLabel4 = label.new(
x=nextDayTime,
y=historyLow - dev4,
text="-" + str.tostring(sd4_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor4,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel4)
// Level 5
if show_sd5
float dev5 = historyRange * sd5_value
color sdLineColor5 = useMasterColor ? masterSDColor : sd5_color
line upperLine5 = line.new(
x1=historyTime,
y1=historyHigh + dev5,
x2=nextDayTime,
y2=historyHigh + dev5,
color=sdLineColor5,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine5)
line lowerLine5 = line.new(
x1=historyTime,
y1=historyLow - dev5,
x2=nextDayTime,
y2=historyLow - dev5,
color=sdLineColor5,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine5)
if showSDLabels
label upperLabel5 = label.new(
x=nextDayTime,
y=historyHigh + dev5,
text="+" + str.tostring(sd5_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor5,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel5)
label lowerLabel5 = label.new(
x=nextDayTime,
y=historyLow - dev5,
text="-" + str.tostring(sd5_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor5,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel5)
// Level 6
if show_sd6
float dev6 = historyRange * sd6_value
color sdLineColor6 = useMasterColor ? masterSDColor : sd6_color
line upperLine6 = line.new(
x1=historyTime,
y1=historyHigh + dev6,
x2=nextDayTime,
y2=historyHigh + dev6,
color=sdLineColor6,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine6)
line lowerLine6 = line.new(
x1=historyTime,
y1=historyLow - dev6,
x2=nextDayTime,
y2=historyLow - dev6,
color=sdLineColor6,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine6)
if showSDLabels
label upperLabel6 = label.new(
x=nextDayTime,
y=historyHigh + dev6,
text="+" + str.tostring(sd6_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor6,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel6)
label lowerLabel6 = label.new(
x=nextDayTime,
y=historyLow - dev6,
text="-" + str.tostring(sd6_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor6,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel6)
// Level 7
if show_sd7
float dev7 = historyRange * sd7_value
color sdLineColor7 = useMasterColor ? masterSDColor : sd7_color
line upperLine7 = line.new(
x1=historyTime,
y1=historyHigh + dev7,
x2=nextDayTime,
y2=historyHigh + dev7,
color=sdLineColor7,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine7)
line lowerLine7 = line.new(
x1=historyTime,
y1=historyLow - dev7,
x2=nextDayTime,
y2=historyLow - dev7,
color=sdLineColor7,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine7)
if showSDLabels
label upperLabel7 = label.new(
x=nextDayTime,
y=historyHigh + dev7,
text="+" + str.tostring(sd7_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor7,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel7)
label lowerLabel7 = label.new(
x=nextDayTime,
y=historyLow - dev7,
text="-" + str.tostring(sd7_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor7,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel7)
// Level 8
if show_sd8
float dev8 = historyRange * sd8_value
color sdLineColor8 = useMasterColor ? masterSDColor : sd8_color
line upperLine8 = line.new(
x1=historyTime,
y1=historyHigh + dev8,
x2=nextDayTime,
y2=historyHigh + dev8,
color=sdLineColor8,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine8)
line lowerLine8 = line.new(
x1=historyTime,
y1=historyLow - dev8,
x2=nextDayTime,
y2=historyLow - dev8,
color=sdLineColor8,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine8)
if showSDLabels
label upperLabel8 = label.new(
x=nextDayTime,
y=historyHigh + dev8,
text="+" + str.tostring(sd8_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor8,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel8)
label lowerLabel8 = label.new(
x=nextDayTime,
y=historyLow - dev8,
text="-" + str.tostring(sd8_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor8,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel8)
// Level 9
if show_sd9
float dev9 = historyRange * sd9_value
color sdLineColor9 = useMasterColor ? masterSDColor : sd9_color
line upperLine9 = line.new(
x1=historyTime,
y1=historyHigh + dev9,
x2=nextDayTime,
y2=historyHigh + dev9,
color=sdLineColor9,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine9)
line lowerLine9 = line.new(
x1=historyTime,
y1=historyLow - dev9,
x2=nextDayTime,
y2=historyLow - dev9,
color=sdLineColor9,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine9)
if showSDLabels
label upperLabel9 = label.new(
x=nextDayTime,
y=historyHigh + dev9,
text="+" + str.tostring(sd9_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor9,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel9)
label lowerLabel9 = label.new(
x=nextDayTime,
y=historyLow - dev9,
text="-" + str.tostring(sd9_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor9,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel9)
// Level 10
if show_sd10
float dev10 = historyRange * sd10_value
color sdLineColor10 = useMasterColor ? masterSDColor : sd10_color
line upperLine10 = line.new(
x1=historyTime,
y1=historyHigh + dev10,
x2=nextDayTime,
y2=historyHigh + dev10,
color=sdLineColor10,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine10)
line lowerLine10 = line.new(
x1=historyTime,
y1=historyLow - dev10,
x2=nextDayTime,
y2=historyLow - dev10,
color=sdLineColor10,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine10)
if showSDLabels
label upperLabel10 = label.new(
x=nextDayTime,
y=historyHigh + dev10,
text="+" + str.tostring(sd10_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor10,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel10)
label lowerLabel10 = label.new(
x=nextDayTime,
y=historyLow - dev10,
text="-" + str.tostring(sd10_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor10,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel10)
// Plot current session
if not na(sessionHigh) and dayofmonth(time, "GMT-5") == currentDay
float currentMidPrice = (sessionHigh + sessionLow) / 2
currentBox := box.new(
left=sessionStartTime,
right=time + (futureOffset * timeframe.multiplier * 60000),
top=sessionHigh,
bottom=sessionLow,
bgcolor=currentBoxFillColor,
border_color=currentBoxBorderColor,
xloc=xloc.bar_time)
currentMidline := line.new(
x1=sessionStartTime,
y1=currentMidPrice,
x2=time + (futureOffset * timeframe.multiplier * 60000),
y2=currentMidPrice,
color=currentMidlineColor,
style=currentMidlineStyle == "Solid" ? line.style_solid :
currentMidlineStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
// Add opening price line
if not na(openPrice)
openPriceLine := line.new(
x1=sessionStartTime,
y1=openPrice,
x2=time + (futureOffset * timeframe.multiplier * 60000),
y2=openPrice,
color=openPriceColor,
style=openPriceStyle == "Solid" ? line.style_solid :
openPriceStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
if showOpenLabel
openPriceLabel := label.new(
x=time + (futureOffset * timeframe.multiplier * 60000),
y=openPrice,
text="12am",
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=openPriceColor,
xloc=xloc.bar_time)
// Plot standard deviation levels
if showSD
float rangeSize = sessionHigh - sessionLow
// Level 1
if show_sd1
float dev1 = rangeSize * sd1_value
color sdLineColor1 = useMasterColor ? masterSDColor : sd1_color
line upperLine1 = line.new(
x1=sessionStartTime,
y1=sessionHigh + dev1,
x2=time,
y2=sessionHigh + dev1,
color=sdLineColor1,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine1)
line lowerLine1 = line.new(
x1=sessionStartTime,
y1=sessionLow - dev1,
x2=time,
y2=sessionLow - dev1,
color=sdLineColor1,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine1)
if showSDLabels
label upperLabel1 = label.new(
x=time,
y=sessionHigh + dev1,
text="+" + str.tostring(sd1_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor1,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel1)
label lowerLabel1 = label.new(
x=time,
y=sessionLow - dev1,
text="-" + str.tostring(sd1_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor1,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel1)
// Level 2
if show_sd2
float dev2 = rangeSize * sd2_value
color sdLineColor2 = useMasterColor ? masterSDColor : sd2_color
line upperLine2 = line.new(
x1=sessionStartTime,
y1=sessionHigh + dev2,
x2=time,
y2=sessionHigh + dev2,
color=sdLineColor2,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine2)
line lowerLine2 = line.new(
x1=sessionStartTime,
y1=sessionLow - dev2,
x2=time,
y2=sessionLow - dev2,
color=sdLineColor2,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine2)
if showSDLabels
label upperLabel2 = label.new(
x=time,
y=sessionHigh + dev2,
text="+" + str.tostring(sd2_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor2,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel2)
label lowerLabel2 = label.new(
x=time,
y=sessionLow - dev2,
text="-" + str.tostring(sd2_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor2,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel2)
// Level 3
if show_sd3
float dev3 = rangeSize * sd3_value
color sdLineColor3 = useMasterColor ? masterSDColor : sd3_color
line upperLine3 = line.new(
x1=sessionStartTime,
y1=sessionHigh + dev3,
x2=time,
y2=sessionHigh + dev3,
color=sdLineColor3,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine3)
line lowerLine3 = line.new(
x1=sessionStartTime,
y1=sessionLow - dev3,
x2=time,
y2=sessionLow - dev3,
color=sdLineColor3,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine3)
if showSDLabels
label upperLabel3 = label.new(
x=time,
y=sessionHigh + dev3,
text="+" + str.tostring(sd3_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor3,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel3)
label lowerLabel3 = label.new(
x=time,
y=sessionLow - dev3,
text="-" + str.tostring(sd3_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor3,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel3)
// Level 4
if show_sd4
float dev4 = rangeSize * sd4_value
color sdLineColor4 = useMasterColor ? masterSDColor : sd4_color
line upperLine4 = line.new(
x1=sessionStartTime,
y1=sessionHigh + dev4,
x2=time,
y2=sessionHigh + dev4,
color=sdLineColor4,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine4)
line lowerLine4 = line.new(
x1=sessionStartTime,
y1=sessionLow - dev4,
x2=time,
y2=sessionLow - dev4,
color=sdLineColor4,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine4)
if showSDLabels
label upperLabel4 = label.new(
x=time,
y=sessionHigh + dev4,
text="+" + str.tostring(sd4_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor4,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel4)
label lowerLabel4 = label.new(
x=time,
y=sessionLow - dev4,
text="-" + str.tostring(sd4_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor4,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel4)
// Level 5
if show_sd5
float dev5 = rangeSize * sd5_value
color sdLineColor5 = useMasterColor ? masterSDColor : sd5_color
line upperLine5 = line.new(
x1=sessionStartTime,
y1=sessionHigh + dev5,
x2=time,
y2=sessionHigh + dev5,
color=sdLineColor5,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine5)
line lowerLine5 = line.new(
x1=sessionStartTime,
y1=sessionLow - dev5,
x2=time,
y2=sessionLow - dev5,
color=sdLineColor5,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine5)
if showSDLabels
label upperLabel5 = label.new(
x=time,
y=sessionHigh + dev5,
text="+" + str.tostring(sd5_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor5,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel5)
label lowerLabel5 = label.new(
x=time,
y=sessionLow - dev5,
text="-" + str.tostring(sd5_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor5,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel5)
// Level 6
if show_sd6
float dev6 = rangeSize * sd6_value
color sdLineColor6 = useMasterColor ? masterSDColor : sd6_color
line upperLine6 = line.new(
x1=sessionStartTime,
y1=sessionHigh + dev6,
x2=time,
y2=sessionHigh + dev6,
color=sdLineColor6,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine6)
line lowerLine6 = line.new(
x1=sessionStartTime,
y1=sessionLow - dev6,
x2=time,
y2=sessionLow - dev6,
color=sdLineColor6,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine6)
if showSDLabels
label upperLabel6 = label.new(
x=time,
y=sessionHigh + dev6,
text="+" + str.tostring(sd6_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor6,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel6)
label lowerLabel6 = label.new(
x=time,
y=sessionLow - dev6,
text="-" + str.tostring(sd6_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor6,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel6)
// Level 7
if show_sd7
float dev7 = rangeSize * sd7_value
color sdLineColor7 = useMasterColor ? masterSDColor : sd7_color
line upperLine7 = line.new(
x1=sessionStartTime,
y1=sessionHigh + dev7,
x2=time,
y2=sessionHigh + dev7,
color=sdLineColor7,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine7)
line lowerLine7 = line.new(
x1=sessionStartTime,
y1=sessionLow - dev7,
x2=time,
y2=sessionLow - dev7,
color=sdLineColor7,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine7)
if showSDLabels
label upperLabel7 = label.new(
x=time,
y=sessionHigh + dev7,
text="+" + str.tostring(sd7_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor7,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel7)
label lowerLabel7 = label.new(
x=time,
y=sessionLow - dev7,
text="-" + str.tostring(sd7_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor7,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel7)
// Level 8
if show_sd8
float dev8 = rangeSize * sd8_value
color sdLineColor8 = useMasterColor ? masterSDColor : sd8_color
line upperLine8 = line.new(
x1=sessionStartTime,
y1=sessionHigh + dev8,
x2=time,
y2=sessionHigh + dev8,
color=sdLineColor8,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine8)
line lowerLine8 = line.new(
x1=sessionStartTime,
y1=sessionLow - dev8,
x2=time,
y2=sessionLow - dev8,
color=sdLineColor8,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine8)
if showSDLabels
label upperLabel8 = label.new(
x=time,
y=sessionHigh + dev8,
text="+" + str.tostring(sd8_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor8,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel8)
label lowerLabel8 = label.new(
x=time,
y=sessionLow - dev8,
text="-" + str.tostring(sd8_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor8,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel8)
// Level 9
if show_sd9
float dev9 = rangeSize * sd9_value
color sdLineColor9 = useMasterColor ? masterSDColor : sd9_color
line upperLine9 = line.new(
x1=sessionStartTime,
y1=sessionHigh + dev9,
x2=time,
y2=sessionHigh + dev9,
color=sdLineColor9,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine9)
line lowerLine9 = line.new(
x1=sessionStartTime,
y1=sessionLow - dev9,
x2=time,
y2=sessionLow - dev9,
color=sdLineColor9,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine9)
if showSDLabels
label upperLabel9 = label.new(
x=time,
y=sessionHigh + dev9,
text="+" + str.tostring(sd9_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor9,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel9)
label lowerLabel9 = label.new(
x=time,
y=sessionLow - dev9,
text="-" + str.tostring(sd9_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor9,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel9)
// Level 10
if show_sd10
float dev10 = rangeSize * sd10_value
color sdLineColor10 = useMasterColor ? masterSDColor : sd10_color
line upperLine10 = line.new(
x1=sessionStartTime,
y1=sessionHigh + dev10,
x2=time,
y2=sessionHigh + dev10,
color=sdLineColor10,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, upperLine10)
line lowerLine10 = line.new(
x1=sessionStartTime,
y1=sessionLow - dev10,
x2=time,
y2=sessionLow - dev10,
color=sdLineColor10,
style=sdStyle == "Solid" ? line.style_solid :
sdStyle == "Dotted" ? line.style_dotted :
line.style_dashed,
xloc=xloc.bar_time)
array.push(sdLines, lowerLine10)
if showSDLabels
label upperLabel10 = label.new(
x=time,
y=sessionHigh + dev10,
text="+" + str.tostring(sd10_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor10,
xloc=xloc.bar_time)
array.push(sdLabels, upperLabel10)
label lowerLabel10 = label.new(
x=time,
y=sessionLow - dev10,
text="-" + str.tostring(sd10_value),
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=sdLineColor10,
xloc=xloc.bar_time)
array.push(sdLabels, lowerLabel10)
// Plot custom open 1
if showCustomOpen1 and not na(customOpen1Price)
int endOfDay1 = timestamp(year(customOpen1StartTime), month(customOpen1StartTime), dayofmonth(customOpen1StartTime), 23, 59, 59)
line.new(
x1=customOpen1StartTime,
y1=customOpen1Price,
x2=endOfDay1,
y2=customOpen1Price,
color=customOpen1Color,
style=customOpen1Style == "Solid" ? line.style_solid :
customOpen1Style == "Dotted" ? line.style_dotted :
line.style_dashed,
width=customOpen1LineWidth,
xloc=xloc.bar_time)
label.new(
x=endOfDay1,
y=customOpen1Price,
text=customOpen1Text,
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=customOpen1Color,
size=customOpen1TextSize == "Tiny" ? size.tiny :
customOpen1TextSize == "Small" ? size.small :
customOpen1TextSize == "Normal" ? size.normal :
size.large,
xloc=xloc.bar_time)
// Plot custom open 2
if showCustomOpen2 and not na(customOpen2Price)
int endOfDay2 = timestamp(year(customOpen2StartTime), month(customOpen2StartTime), dayofmonth(customOpen2StartTime), 23, 59, 59)
line.new(
x1=customOpen2StartTime,
y1=customOpen2Price,
x2=endOfDay2,
y2=customOpen2Price,
color=customOpen2Color,
style=customOpen2Style == "Solid" ? line.style_solid :
customOpen2Style == "Dotted" ? line.style_dotted :
line.style_dashed,
width=customOpen2LineWidth,
xloc=xloc.bar_time)
label.new(
x=endOfDay2,
y=customOpen2Price,
text=customOpen2Text,
color=color.new(color.black, 100),
style=label.style_label_left,
textcolor=customOpen2Color,
size=customOpen2TextSize == "Tiny" ? size.tiny :
customOpen2TextSize == "Small" ? size.small :
customOpen2TextSize == "Normal" ? size.normal :
size.large,
xloc=xloc.bar_time)