本页源码来自 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/
// © Mereep01
//@version=5
indicator('Intraday Levels', 'Levels', overlay=true)
LvlSettingOption = input.string('Show lines and labels for all days', title='Display', options=['Show lines and labels for all days', 'Show lines and labels only for current day', 'Most recent Lvl across the chart'], group='Price level')
LvlSetting = LvlSettingOption == 'Show lines and labels only for current day' ? 'b' : LvlSettingOption == 'Most recent level across the chart' ? 'c' : 'a'
PMHighLvl = input.bool(true, title='Pre-market high', group='Price level', inline='PMHigh')
PMLowLvl = input.bool(true, title='Pre-market low', group='Price level', inline='PMLow')
PrevHighLvl = input.bool(true, title='Prev. day high', group='Price level', inline='PrevHigh')
PrevLowLvl = input.bool(true, title='Prev. day low', group='Price level', inline='PrevLow')
PrevCloseLvl = input.bool(true, title='Prev. day close', group='Price level', inline='PrevClose')
AHHighLvl = input.bool(true, title='After-hour high', group='Price level', inline='afterHigh')
AHLowLvl = input.bool(true, title='After-hour Low', group='Price level', inline='afterLow')
DayHighLvl = input.bool(true, title='Day High', group='Price level', inline='DayHigh')
DayLowLvl = input.bool(true, title='Day Low', group='Price level', inline='DayLow')
PMHighPrice = input.bool(true, title='Pre-market high', group='Price axis')
PMLowPrice = input.bool(true, title='Pre-market low', group='Price axis')
PrevHighPrice = input.bool(true, title='Prev day high', group='Price axis')
PrevLowPrice = input.bool(true, title='Prev day low', group='Price axis')
PrevClosePrice = input.bool(false, title='Prev day close', group='Price axis')
AHHighPrice = input.bool(true, title='After-hour high', group='Price axis')
AHLowPrice = input.bool(true, title='After-hour Low', group='Price axis')
DayHighPrice = input.bool(true, title='Day high', group='Price axis')
DayLowPrice = input.bool(true, title='Day low', group='Price axis')
PMHighLabelBool = input.bool(true, title='Pre-market high', group='Label', inline='PMHigh')
PMLowLabelBool = input.bool(true, title='Pre-market low', group='Label', inline='PMLow')
PrevHighLabelBool = input.bool(true, title='Prev day high', group='Label', inline='PrevHigh')
PrevLowLabelBool = input.bool(true, title='Prev day low', group='Label', inline='PrevLow')
PrevCloseLabelBool = input.bool(false, title='Prev day close', group='Label', inline='PrevClose')
AHHighLabelBool = input.bool(true, title='After-hour high', group='Label', inline='afterHigh')
AHLowLabelBool = input.bool(true, title='After-hour Low', group='Label', inline='afterLow')
DayHighLabelBool = input.bool(true, title='Day high', group='Label', inline='DayHigh')
DayLowLabelBool = input.bool(true, title='Day low', group='Label', inline='DayLow')
PMHighLabelPriceBool = input.bool(true, title='Display price after label text', group='Label', inline='PMHigh')
PMLowLabelPriceBool = input.bool(true, title='Display price after label text', group='Label', inline='PMLow')
PrevHighLabelPriceBool = input.bool(true, title='Display price after label text', group='Label', inline='PrevHigh')
PrevLowLabelPriceBool = input.bool(true, title='Display price after label text', group='Label', inline='PrevLow')
PrevCloseLabelPriceBool = input.bool(true, title='Display price after label text', group='Label', inline='PrevClose')
AHHighLabelPriceBool = input.bool(true, title='Display price after label text', group='Label', inline='afterHigh')
AHLowLabelPriceBool = input.bool(true, title='Display price after label text', group='Label', inline='afterLow')
DayHighLabelPriceBool = input.bool(true, title='Display price after label text', group='Label', inline='DayHigh')
DayLowLabelPriceBool = input.bool(true, title='Display price after label text', group='Label', inline='DayLow')
PMHighOffset = input.int(7, title='Pre-market high label offset from last bar', group='Label')
PMLowOffset = input.int(7, title='Pre-market low label offset from last bar', group='Label')
PrevHighOffset = input.int(7, title='Prev day high label offset from last bar', group='Label')
PrevLowOffset = input.int(7, title='Prev day low label offset from last bar', group='Label')
PrevCloseOffset = input.int(7, title='Prev day close label offset from last bar', group='Label')
AHHighOffset = input.int(7, title='After-hour high label offset from last bar', group='Label')
AHLowOffset = input.int(7, title='After-hour Low label offset from last bar', group='Label')
DayHighOffset = input.int(7, title='Day high label offset from last bar', group='Label')
DayLowOffset = input.int(7, title='Day low label offset from last bar', group='Label')
PMHighLabelAlignOption = input.string('align left', title='', options=['align left', 'align center', 'align right'], group='Label', inline='PMHigh')
PMLowLabelAlignOption = input.string('align left', title='', options=['align left', 'align center', 'align right'], group='Label', inline='PMLow')
PrevHighLabelAlignOption = input.string('align left', title='', options=['align left', 'align center', 'align right'], group='Label', inline='PrevHigh')
PrevLowLabelAlignOption = input.string('align left', title='', options=['align left', 'align center', 'align right'], group='Label', inline='PrevLow')
PrevCloseLabelAlignOption = input.string('align left', title='', options=['align left', 'align center', 'align right'], group='Label', inline='PrevClose')
AHHighLabelAlignOption = input.string('align left', title='', options=['align left', 'align center', 'align right'], group='Label', inline='afterHigh')
AHLowLabelAlignOption = input.string('align left', title='', options=['align left', 'align center', 'align right'], group='Label', inline='afterLow')
DayHighLabelAlignOption = input.string('align left', title='', options=['align left', 'align center', 'align right'], group='Label', inline='DayHigh')
DayLowLabelAlignOption = input.string('align left', title='', options=['align left', 'align center', 'align right'], group='Label', inline='DayLow')
PMHighLabelAlign = PMHighLabelAlignOption == 'align left' ? text.align_left : PMHighLabelAlignOption == 'align center' ? text.align_center : text.align_right
PMLowLabelAlign = PMLowLabelAlignOption == 'align left' ? text.align_left : PMLowLabelAlignOption == 'align center' ? text.align_center : text.align_right
PrevHighLabelAlign = PrevHighLabelAlignOption == 'align left' ? text.align_left : PrevHighLabelAlignOption == 'align center' ? text.align_center : text.align_right
PrevLowLabelAlign = PrevLowLabelAlignOption == 'align left' ? text.align_left : PrevLowLabelAlignOption == 'align center' ? text.align_center : text.align_right
PrevCloseLabelAlign = PrevCloseLabelAlignOption == 'align left' ? text.align_left : PrevCloseLabelAlignOption == 'align center' ? text.align_center : text.align_right
AHHighLabelAlign = AHHighLabelAlignOption == 'align left' ? text.align_left : AHHighLabelAlignOption == 'align center' ? text.align_center : text.align_right
AHLowLabelAlign = AHLowLabelAlignOption == 'align left' ? text.align_left : AHLowLabelAlignOption == 'align center' ? text.align_center : text.align_right
DayHighLabelAlign = DayHighLabelAlignOption == 'align left' ? text.align_left : DayHighLabelAlignOption == 'align center' ? text.align_center : text.align_right
DayLowLabelAlign = DayLowLabelAlignOption == 'align left' ? text.align_left : DayLowLabelAlignOption == 'align center' ? text.align_center : text.align_right
PMHighLabelText = input.string('PMH ', title='Text', group='Label', inline='PMHigh')
PMLowLabelText = input.string('PML ', title='Text', group='Label', inline='PMLow')
PrevHighLabelText = input.string('PDH ', title='Text', group='Label', inline='PrevHigh')
PrevLowLabelText = input.string('PDL ', title='Text', group='Label', inline='PrevLow')
PrevCloseLabelText = input.string('PDC ', title='Text', group='Label', inline='PrevClose')
AHHighLabelText = input.string('AHH ', title='Text', group='Label', inline='afterHigh')
AHLowLabelText = input.string('AHL ', title='Text', group='Label', inline='afterLow')
DayHighLabelText = input.string('DH ', title='Text', group='Label', inline='DayHigh')
DayLowLabelText = input.string('DL ', title='Text', group='Label', inline='DayLow')
PMHighLabelTextColour = input(title='', defval=#000000, group='Label', inline='PMHigh')
PMLowLabelTextColour = input(title='', defval=#000000, group='Label', inline='PMLow')
PrevHighLabelTextColour = input(title='', defval=#000000, group='Label', inline='PrevHigh')
PrevLowLabelTextColour = input(title='', defval=#000000, group='Label', inline='PrevLow')
PrevCloseLabelTextColour = input(title='', defval=#000000, group='Label', inline='PrevClose')
AHHighLabelTextColour = input(title='', defval=#000000, group='Label', inline='afterHigh')
AHLowLabelTextColour = input(title='', defval=#000000, group='Label', inline='afterLow')
DayHighLabelTextColour = input(title='', defval=#000000, group='Label', inline='DayHigh')
DayLowLabelTextColour = input(title='', defval=#000000, group='Label', inline='DayLow')
secondBool = input.bool(true, title='Seconds', group='Price axis visibility', inline='second')
minuteBool = input.bool(true, title='Minutes', group='Price axis visibility', inline='minute')
hourBool = input.bool(true, title='Hours', group='Price axis visibility', inline='hour')
dayBool = input.bool(false, title='Days', group='Price axis visibility', inline='day')
weekBool = input.bool(false, title='Weeks', group='Price axis visibility', inline='week')
monthBool = input.bool(false, title='Months', group='Price axis visibility', inline='month')
secondMin = input.int(1, '', 1, 59, group='Price axis visibility', inline='second')
secondMax = input.int(59, '-', 1, 59, group='Price axis visibility', inline='second')
minuteMin = input.int(1, '', 1, 59, group='Price axis visibility', inline='minute')
minuteMax = input.int(59, '-', 1, 59, group='Price axis visibility', inline='minute')
hourMin = input.int(1, '', 1, 24, group='Price axis visibility', inline='hour')
hourMax = input.int(24, '-', 1, 24, group='Price axis visibility', inline='hour')
dayMin = input.int(1, '', 1, 366, group='Price axis visibility', inline='day')
dayMax = input.int(366, '-', 1, 366, group='Price axis visibility', inline='day')
weekMin = input.int(1, '', 1, 52, group='Price axis visibility', inline='week')
weekMax = input.int(52, '-', 1, 52, group='Price axis visibility', inline='week')
monthMin = input.int(1, '', 1, 12, group='Price axis visibility', inline='month')
monthMax = input.int(12, '-', 1, 12, group='Price axis visibility', inline='month')
timeframeNumberstr = str.match(timeframe.period, '[0-9]*')
timeframeNumber = str.tonumber(timeframeNumberstr)
timeframeLetter = str.match(timeframe.period, '[A-Z]')
bool timeframePlot = false
if secondBool and timeframeLetter=='S' and secondMin<=timeframeNumber and secondMax>=timeframeNumber
timeframePlot := true
if minuteBool and timeframeLetter=='' and minuteMin<=timeframeNumber and minuteMax>=timeframeNumber
timeframePlot := true
if hourBool and timeframeLetter=='' and hourMin*60<=timeframeNumber and hourMax*60>=timeframeNumber
timeframePlot := true
if dayBool and timeframeLetter=='D' and dayMin<=timeframeNumber and dayMax>=timeframeNumber
timeframePlot := true
if weekBool and timeframeLetter=='W' and weekMin<=timeframeNumber and weekMax>=timeframeNumber
timeframePlot := true
if monthBool and timeframeLetter=='M' and monthMin<=timeframeNumber and monthMax>=timeframeNumber
timeframePlot := true
PMHighColour = input(title='', defval=#ffffff, group='Price level', inline='PMHigh')
PMLowColour = input(title='', defval=#ffffff, group='Price level', inline='PMLow')
PrevHighColour = input(title='', defval=#0008ff, group='Price level', inline='PrevHigh')
PrevLowColour = input(title='', defval=#0008ff, group='Price level', inline='PrevLow')
PrevCloseColour = input(title='', defval=color.rgb(255, 255, 0), group='Price level', inline='PrevClose')
AHHighColour = input(title='', defval=color.rgb(0, 255, 255), group='Price level', inline='afterHigh')
AHLowColour = input(title='', defval=color.rgb(0, 255, 255), group='Price level', inline='afterLow')
DayHighColour = input(title='', defval=color.rgb(0, 255, 191), group='Price level', inline='DayHigh')
DayLowColour = input(title='', defval=color.rgb(0, 255, 191), group='Price level', inline='DayLow')
PMHighLineWidth = input(2, 'Thickness', group='Price level', inline='PMHigh')
PMLowLineWidth = input(2, 'Thickness', group='Price level', inline='PMLow')
PrevHighLineWidth = input(2, 'Thickness', group='Price level', inline='PrevHigh')
PrevLowLineWidth = input(2, 'Thickness', group='Price level', inline='PrevLow')
PrevCloseLineWidth = input(2, 'Thickness', group='Price level', inline='PrevClose')
AHHighLineWidth = input(2, 'Thickness', group='Price level', inline='afterHigh')
AHLowLineWidth = input(2, 'Thickness', group='Price level', inline='afterLow')
DayHighLineWidth = input(2, 'Thickness', group='Price level', inline='DayHigh')
DayLowLineWidth = input(2, 'Thickness', group='Price level', inline='DayLow')
PMHighStyleOption = input.string('dashed (╌)', title='', options=['solid (─)', 'dotted (..)','dashed (╌)'], group='Price level', inline='PMHigh')
PMLowStyleOption = input.string('dashed (╌)', title='', options=['solid (─)', 'dotted (..)','dashed (╌)'], group='Price level', inline='PMLow')
PrevHighStyleOption = input.string('solid (─)', title='', options=['solid (─)', 'dotted (..)','dashed (╌)'], group='Price level', inline='PrevHigh')
PrevLowStyleOption = input.string('solid (─)', title='', options=['solid (─)', 'dotted (..)','dashed (╌)'], group='Price level', inline='PrevLow')
PrevCloseStyleOption = input.string('solid (─)', title='', options=['solid (─)', 'dotted (..)','dashed (╌)'], group='Price level', inline='PrevClose')
AHHighStyleOption = input.string('dashed (╌)', title='', options=['solid (─)', 'dotted (..)','dashed (╌)'], group='Price level', inline='afterHigh')
AHLowStyleOption = input.string('dashed (╌)', title='', options=['solid (─)', 'dotted (..)','dashed (╌)'], group='Price level', inline='afterLow')
DayHighStyleOption = input.string('solid (─)', title='', options=['solid (─)', 'dotted (..)','dashed (╌)'], group='Price level', inline='DayHigh')
DayLowStyleOption = input.string('solid (─)', title='', options=['solid (─)', 'dotted (..)','dashed (╌)'], group='Price level', inline='DayLow')
PMHighLineStyle = PMHighStyleOption == 'dotted (┈)' ? line.style_dotted : PMHighStyleOption == 'dashed (╌)' ? line.style_dashed : line.style_solid
PMLowLineStyle = PMLowStyleOption == 'dotted (┈)' ? line.style_dotted : PMLowStyleOption == 'dashed (╌)' ? line.style_dashed : line.style_solid
PrevHighLineStyle = PrevHighStyleOption == 'dotted (┈)' ? line.style_dotted : PrevHighStyleOption == 'dashed (╌)' ? line.style_dashed : line.style_solid
PrevLowLineStyle = PrevLowStyleOption == 'dotted (┈)' ? line.style_dotted : PrevLowStyleOption == 'dashed (╌)' ? line.style_dashed : line.style_solid
PrevCloseLineStyle = PrevCloseStyleOption == 'dotted (┈)' ? line.style_dotted : PrevCloseStyleOption == 'dashed (╌)' ? line.style_dashed : line.style_solid
AHHighLineStyle = AHHighStyleOption == 'dotted (┈)' ? line.style_dotted : AHHighStyleOption == 'dashed (╌)' ? line.style_dashed : line.style_solid
AHLowLineStyle = AHLowStyleOption == 'dotted (┈)' ? line.style_dotted : AHLowStyleOption == 'dashed (╌)' ? line.style_dashed : line.style_solid
DayHighLineStyle = DayHighStyleOption == 'dotted (┈)' ? line.style_dotted : DayHighStyleOption == 'dashed (╌)' ? line.style_dashed : line.style_solid
DayLowLineStyle = DayLowStyleOption == 'dotted (┈)' ? line.style_dotted : DayLowStyleOption == 'dashed (╌)' ? line.style_dashed : line.style_solid
var line PMHighLine = na
var line PMLowLine = na
var line PrevHighLine = na
var line PrevLowLine = na
var line PrevCloseLine = na
var line AHHighLine = na
var line AHLowLine = na
var line DayHighLine = na
var line DayLowLine = na
var float PMHigh = na
var float PMLow = na
var float PrevHigh = na
var float PrevLow = na
var float PrevClose = na
var float DayHigh = na // not used because chart does not consider some regular session prices when viewing Extended Trading Hours, e.g. prices between 0930-0959 on the 1 hour timeframe.
var float DayLow = na
// var float DayClose = na
var float AHHigh = na
var float AHLow = na
var label PMHighLabel = na
var label PMLowLabel = na
var label PrevHighLabel = na
var label PrevLowLabel = na
var label PrevCloseLabel = na
var label AHHighLabel = na
var label AHLowLabel = na
var label DayHighLabel = na
var label DayLowLabel = na
// Premarket High and Premarket Low
if session.isfirstbar and session.ispremarket // initialize PMHigh and PMLow for new day
PMHigh := high
PMLow := low
// var float temp = na
// array <float> test = request.security_lower_tf(syminfo.tickerid,'1',high)
// if array.size(test)>0 and time('1','0400-0859','UTC-4') // time condition does not work because request.security_lower_tf will take all prices in the completed candle
// temp := array.max(test)
if high > PMHigh and session.ispremarket
PMHigh := high
line.set_y1(PMHighLine, PMHigh) // shift PMHigh in real-time
line.set_y2(PMHighLine, PMHigh)
label.set_y(PMHighLabel, PMHigh)
if PMHighLabelPriceBool
//label.set_text(PMHighLabel, 'PMH: ' + str.tostring(PMHigh,format.mintick))
label.set_text(PMHighLabel, PMHighLabelText + str.tostring(PMHigh, format.mintick))
if low < PMLow and session.ispremarket
PMLow := low
line.set_y1(PMLowLine, PMLow) // shift PMLow in real-time
line.set_y2(PMLowLine, PMLow)
label.set_y(PMLowLabel, PMLow)
if PMLowLabelPriceBool
label.set_text(PMLowLabel, PMLowLabelText + str.tostring(PMLow, format.mintick))
// Day High and Day Low
DayHigh := request.security(syminfo.tickerid, "D", high, lookahead=barmerge.lookahead_on)
DayLow := request.security(syminfo.tickerid, "D", low, lookahead=barmerge.lookahead_on)
if session.ismarket
line.set_y1(DayHighLine, DayHigh) // shift DayHigh in real-time
line.set_y2(DayHighLine, DayHigh)
label.set_y(DayHighLabel, DayHigh)
if DayHighLabelPriceBool
//label.set_text(DayHighLabel, 'DH: ' + str.tostring(DayHigh,format.mintick))
label.set_text(DayHighLabel, DayHighLabelText + str.tostring(DayHigh, format.mintick))
line.set_y1(DayLowLine, DayLow) // shift DayLow in real-time
line.set_y2(DayLowLine, DayLow)
label.set_y(DayLowLabel, DayLow)
if DayLowLabelPriceBool
label.set_text(DayLowLabel, DayLowLabelText + str.tostring(DayLow, format.mintick))
//if session.isfirstbar_regular and session.ismarket
// DayHigh := high
// DayLow := low
//if high > DayHigh and session.ismarket
// DayHigh := high // update DayHigh
// line.set_y1(DayHighLine, DayHigh) // shift DayHigh in real-time
// line.set_y2(DayHighLine, DayHigh)
// label.set_y(DayHighLabel, DayHigh)
// if DayHighLabelPriceBool
// //label.set_text(DayHighLabel, 'DH: ' + str.tostring(DayHigh,format.mintick))
// label.set_text(DayHighLabel, DayHighLabelText + str.tostring(DayHigh, format.mintick))
//if low < DayLow and session.ismarket
// DayLow := low // update DayLow
// line.set_y1(DayLowLine, DayLow) // shift DayLow in real-time
// line.set_y2(DayLowLine, DayLow)
// label.set_y(DayLowLabel, DayLow)
// if DayLowLabelPriceBool
// label.set_text(DayLowLabel, DayLowLabelText + str.tostring(DayLow, format.mintick))
// After hours High and After hours Low
if session.ispostmarket and session.ispostmarket[1] == false // initialize after-hour prices for the day
AHHigh := high
AHLow := low
if session.ispostmarket and high > AHHigh
AHHigh := high
//plot(AHHigh)
line.set_y1(AHHighLine, AHHigh) // shift afterHigh in real-time
line.set_y2(AHHighLine, AHHigh)
label.set_y(AHHighLabel, AHHigh)
if AHHighLabelPriceBool
label.set_text(AHHighLabel, AHHighLabelText + str.tostring(AHHigh, format.mintick))
if session.ispostmarket and low < AHLow
AHLow := low
line.set_y1(AHLowLine, AHLow) // shift afterHigh in real-time
line.set_y2(AHLowLine, AHLow)
label.set_y(AHLowLabel, AHLow)
if AHLowLabelPriceBool
label.set_text(AHLowLabel, AHLowLabelText + str.tostring(AHLow, format.mintick))
if session.ispostmarket and session.ispostmarket[1] == false
line.set_extend(AHHighLine, extend.none) // afterhourlines should only be drawn starting from first after-hour bar
line.set_extend(AHLowLine, extend.none)
if LvlSetting!='a'
line.delete(AHHighLine)
line.delete(AHLowLine)
label.delete(AHLowLabel)
label.delete(AHHighLabel)
if timeframe.isintraday
if AHHighLvl
AHHighLine := line.new(bar_index, AHHigh, bar_index+1, AHHigh, color=AHHighColour, style=AHHighLineStyle, width=AHHighLineWidth, extend=LvlSetting=='c' ? extend.both : extend.right)
if AHHighLabelBool
AHHighLabel := label.new(bar_index + AHHighOffset, AHHigh, text=AHHighLabelPriceBool ? AHHighLabelText + str.tostring(AHHigh,format.mintick) : AHHighLabelText, color=AHHighColour, style=label.style_label_left, textcolor=AHHighLabelTextColour, size=size.normal, textalign=AHHighLabelAlign)
if AHLowLvl
AHLowLine := line.new(bar_index, AHLow, bar_index+1, AHLow, color=AHLowColour, style=AHLowLineStyle, width=AHLowLineWidth, extend=LvlSetting=='c' ? extend.both : extend.right)
if AHLowLabelBool
AHLowLabel := label.new(bar_index + AHLowOffset, AHLow, text=AHLowLabelPriceBool ? AHLowLabelText + str.tostring(AHLow,format.mintick) : AHLowLabelText, color=AHLowColour, style=label.style_label_left, textcolor=AHLowLabelTextColour, size=size.normal, textalign=AHLowLabelAlign)
else
line.set_x2(AHHighLine, bar_index)
line.set_x2(AHLowLine, bar_index)
// Previous Day Hig hand Previous Day Low
PrevHigh := request.security(syminfo.tickerid,'D',(syminfo.session==session.extended?high:high[1]),lookahead=barmerge.lookahead_on) // session.isfirstbar does not work here
PrevLow := request.security(syminfo.tickerid,'D',(syminfo.session==session.extended?low:low[1]),lookahead=barmerge.lookahead_on)
PrevClose := request.security(syminfo.tickerid,'D',(syminfo.session==session.extended?close:close[1]),lookahead=barmerge.lookahead_on)
if not session.isfirstbar
PrevHigh := PrevHigh[1]
PrevLow := PrevLow[1]
PrevClose := PrevClose[1]
if session.isfirstbar
line.set_extend(PMHighLine, extend.none) // so that lines from Prev days will not extend right to price axis
line.set_extend(PMLowLine, extend.none)
line.set_extend(PrevHighLine, extend.none)
line.set_extend(PrevLowLine, extend.none)
line.set_extend(PrevCloseLine, extend.none)
line.set_extend(DayHighLine, extend.none)
line.set_extend(DayLowLine, extend.none)
// PrevHigh := DayHigh[1] // since this is first bar, the previous value will be that of Prev day
// PrevLow := DayLow[1]
// PrevOpen := DayOpen[1]
// PrevClose := DayClose[1]
if LvlSetting!='a' // delete the old lines if option 'a' is not selected. Only show for current day
line.delete(PMHighLine)
line.delete(PMLowLine)
line.delete(PrevHighLine)
line.delete(PrevLowLine)
line.delete(PrevCloseLine)
line.delete(DayHighLine)
line.delete(DayLowLine)
label.delete(PMHighLabel)
label.delete(PMLowLabel)
label.delete(PrevHighLabel)
label.delete(PrevLowLabel)
label.delete(PrevCloseLabel)
label.delete(DayHighLabel)
label.delete(DayLowLabel)
if timeframe.isintraday
if DayHighLvl
DayHighLine := line.new(bar_index, DayHigh, bar_index+1, DayHigh, color=DayHighColour, style=DayHighLineStyle, width=DayHighLineWidth, extend=LvlSetting=='c' ? extend.both : extend.right)
if DayHighLabelBool
DayHighLabel := label.new(bar_index + DayHighOffset, DayHigh, text=DayHighLabelPriceBool ? DayHighLabelText + str.tostring(DayHigh,format.mintick) : DayHighLabelText, color=DayHighColour, style=label.style_label_left, textcolor=DayHighLabelTextColour, size=size.normal, textalign=DayHighLabelAlign)
if DayLowLvl
DayLowLine := line.new(bar_index, DayLow, bar_index+1, DayLow, color=DayLowColour, style=DayLowLineStyle, width=DayLowLineWidth, extend=LvlSetting=='c' ? extend.both : extend.right)
if DayLowLabelBool
DayLowLabel := label.new(bar_index + DayLowOffset, DayLow, text=DayLowLabelPriceBool ? DayLowLabelText + str.tostring(DayLow,format.mintick) : DayLowLabelText, color=DayLowColour, style=label.style_label_left, textcolor=DayLowLabelTextColour, size=size.normal, textalign=DayLowLabelAlign)
if PMHighLvl
PMHighLine := line.new(bar_index, PMHigh, bar_index+1, PMHigh, color=PMHighColour, style=PMHighLineStyle, width=PMHighLineWidth, extend=LvlSetting=='c' ? extend.both : extend.right)
if PMHighLabelBool
PMHighLabel := label.new(bar_index + PMHighOffset, PMHigh, text=PMHighLabelPriceBool ? PMHighLabelText + str.tostring(PMHigh,format.mintick) : PMHighLabelText, color=PMHighColour, style=label.style_label_left, textcolor=PMHighLabelTextColour, size=size.normal, textalign=PMHighLabelAlign)
if PMLowLvl
PMLowLine := line.new(bar_index, PMLow, bar_index+1, PMLow, color=PMLowColour, style=PMLowLineStyle, width=PMLowLineWidth, extend=LvlSetting=='c' ? extend.both : extend.right)
if PMLowLabelBool
PMLowLabel := label.new(bar_index + PMLowOffset, PMLow, text=PMLowLabelPriceBool ? PMLowLabelText + str.tostring(PMLow,format.mintick) : PMLowLabelText, color=PMLowColour, style=label.style_label_left, textcolor=PMLowLabelTextColour, size=size.normal, textalign=PMLowLabelAlign)
if PrevHighLvl
PrevHighLine := line.new(bar_index, PrevHigh, bar_index+1, PrevHigh, color=PrevHighColour, style=PrevHighLineStyle, width=PrevHighLineWidth, extend=LvlSetting=='c' ? extend.both : extend.right)
if PrevHighLabelBool
PrevHighLabel := label.new(bar_index + PrevHighOffset, PrevHigh, text=PrevHighLabelPriceBool ? PrevHighLabelText + str.tostring(PrevHigh,format.mintick) : PrevHighLabelText, color=PrevHighColour, style=label.style_label_left, textcolor=PrevHighLabelTextColour, size=size.normal, textalign=PrevHighLabelAlign)
if PrevLowLvl
PrevLowLine := line.new(bar_index, PrevLow, bar_index+1, PrevLow, color=PrevLowColour, style=PrevLowLineStyle, width=PrevLowLineWidth, extend=LvlSetting=='c' ? extend.both : extend.right)
if PrevLowLabelBool
PrevLowLabel := label.new(bar_index + PrevLowOffset, PrevLow, text=PrevLowLabelPriceBool ? PrevLowLabelText + str.tostring(PrevLow,format.mintick) : PrevLowLabelText, color=PrevLowColour, style=label.style_label_left, textcolor=PrevLowLabelTextColour, size=size.normal, textalign=PrevLowLabelAlign)
if PrevCloseLvl
PrevCloseLine := line.new(bar_index, PrevClose, bar_index+1, PrevClose, color=PrevCloseColour, style=PrevCloseLineStyle, width=PrevCloseLineWidth, extend=LvlSetting=='c' ? extend.both : extend.right)
if PrevCloseLabelBool
PrevCloseLabel := label.new(bar_index + PrevCloseOffset, PrevClose, text=PrevCloseLabelPriceBool ? PrevCloseLabelText + str.tostring(PrevClose,format.mintick) : PrevCloseLabelText, color=PrevCloseColour, style=label.style_label_left, textcolor=PrevCloseLabelTextColour, size=size.normal, textalign=PrevCloseLabelAlign)
if not session.isfirstbar
line.set_x2(PMHighLine, bar_index)
line.set_x2(PMLowLine, bar_index)
line.set_x2(PrevHighLine, bar_index)
line.set_x2(PrevLowLine, bar_index)
line.set_x2(PrevCloseLine, bar_index)
line.set_x2(DayHighLine, bar_index)
line.set_x2(DayLowLine, bar_index)
label.set_x(PMHighLabel, bar_index + PMHighOffset)
label.set_x(PMLowLabel, bar_index + PMLowOffset)
label.set_x(PrevHighLabel, bar_index + PrevHighOffset)
label.set_x(PrevLowLabel, bar_index + PrevLowOffset)
label.set_x(PrevCloseLabel, bar_index + PrevCloseOffset)
label.set_x(AHHighLabel, bar_index + AHHighOffset)
label.set_x(AHLowLabel, bar_index + AHLowOffset)
label.set_x(DayHighLabel, bar_index + DayHighOffset)
label.set_x(DayLowLabel, bar_index + DayLowOffset)
//if session.ispremarket
// line.delete(DayHighLine)
// line.delete(DayLowLine)
// label.delete(DayHighLabel)
// label.delete(DayLowLabel)
plot(timeframe.isintraday and PMHighPrice and timeframePlot ? PMHigh : na, color=PMHighColour, editable=false, display=display.price_scale) // plot the value on price axis without the line
plot(timeframe.isintraday and PMLowPrice and timeframePlot? PMLow : na, color=PMLowColour, editable=false, display=display.price_scale)
plot(timeframe.isintraday and PrevHighPrice and timeframePlot ? PrevHigh : na, color=PrevHighColour, editable=false, display=display.price_scale)
plot(timeframe.isintraday and PrevLowPrice and timeframePlot ? PrevLow : na, color=PrevLowColour, editable=false, display=display.price_scale)
plot(timeframe.isintraday and PrevClosePrice and timeframePlot ? PrevClose : na, color=PrevCloseColour, editable=false, display=display.price_scale)
plot(timeframe.isintraday and AHHighPrice and timeframePlot ? AHHigh : na, color=AHHighColour, editable=false, display=display.price_scale)
plot(timeframe.isintraday and AHLowPrice and timeframePlot ? AHLow : na, color=AHLowColour, editable=false, display=display.price_scale)
plot(timeframe.isintraday and DayHighPrice and timeframePlot ? DayHigh : na, color=DayHighColour, editable=false, display=display.price_scale)
plot(timeframe.isintraday and DayLowPrice and timeframePlot ? DayLow : na, color=DayLowColour, editable=false, display=display.price_scale)
alertcondition(session.ismarket and close>=PMHigh and close[1]<PMHigh, title='Cross abpve PMH', message='Price crossed above Pre-market high!')
alertcondition(session.ismarket and close<=PMLow and close[1]>PMLow, title='Cross above PML', message='Price crossed below Pre-market low!')
alertcondition(session.ismarket and close>=PrevHigh and close[1]<PrevHigh, title='Cross above PDH', message='Price crossed above Pre-market high!')
alertcondition(session.ismarket and close<=PrevLow and close[1]>PrevLow, title='Cross below PDL)', message='Price crossed below Pre-market low!')