frien_dd
frien_dd

Reputation: 164

Script plots on 1 min TF but not on other TFs

The below script aims to plot the opening times of Asia, London and New York for Daily and Weekly.

It displays Market Regular Opening hours as per the below links (For daily and weekly):

Tokyo https://www.tradinghours.com/markets/jpx/hours

London https://www.tradinghours.com/markets/lse/hours

New York https://www.tradinghours.com/markets/nyse/hours

It displays perfectly on the 1 min timeframe but I cant see why it will not display on other timeframes.

I thought it was the below line of code so changed it but still no joy.

//AsiaWOpen = time("1", AsiaWOpenInput)
AsiaDOpen = time(timeframe.period, AsiaDOpenInput)

Any advice would be gratefully received. Would I have to use security to resolve?

//@version=4
study("Market Opening Hours", overlay=true)

offset_val = input(title="Label Offset", type=input.integer, defval=15)

//--------------Asia Configuration
AsiaDOpenInput = input('2359-0000:234567', title="Asia Daily Open") //set the opening range you are interested in
AsiaWOpenInput = input('2359-0000:1', title="Asia Weekly Open") //set the opening range you are interested in

//AsiaDOpen = time("1", AsiaDOpenInput)
//AsiaWOpen = time("1", AsiaWOpenInput)
AsiaDOpen = time(timeframe.period, AsiaDOpenInput)
AsiaWOpen = time(timeframe.period, AsiaWOpenInput)


var AsiaDOpenPA = 0.0
if AsiaDOpen
    if not AsiaDOpen[1]
        AsiaDOpenPA := open

var AsiaWOpenPA = 0.0
if AsiaWOpen
    if not AsiaWOpen[1]
        AsiaWOpenPA := open


plot(not AsiaDOpen ? AsiaDOpenPA : na, title="Asia D Open", color=color.orange, linewidth=1, style=plot.style_linebr)
plotshape(AsiaDOpenPA, style=shape.labeldown, location=location.absolute, color=color.orange,  textcolor=color.white, show_last=1, text="Asia D Open",  offset = offset_val, transp=20, title="Asia D Open")

plot(not AsiaWOpen ? AsiaWOpenPA : na, title="Asia W Open", color=color.orange, linewidth=2, style=plot.style_linebr)
plotshape(AsiaWOpenPA, style=shape.labeldown, location=location.absolute, color=color.orange,  textcolor=color.white, show_last=1, text="Asia W Open",  offset = offset_val, transp=20, title="Asia W Open")



//--------------London Configuration
LonDOpenInput = input('0759-0800:134567', title="London Daily Open") //set the opening range you are interested in
LonWOpenInput = input('0759-0800:2', title="London Weekly Open") //set the opening range you are interested in

//LonDOpen = time("1", LonDOpenInput)
//LonWOpen = time("1", LonWOpenInput)
LonDOpen = time(timeframe.period, LonDOpenInput)
LonWOpen = time(timeframe.period, LonWOpenInput)


var LonDOpenPA = 0.0
if LonDOpen
    if not LonDOpen[1]
        LonDOpenPA := open

var LonWOpenPA = 0.0
if LonWOpen
    if not LonWOpen[1]
        LonWOpenPA := open


plot(not LonDOpen ? LonDOpenPA : na, title="London D Open", color=color.yellow, linewidth=1, style=plot.style_linebr)
plotshape(LonDOpenPA, style=shape.labeldown, location=location.absolute, color=color.yellow,  textcolor=color.white, show_last=1, text="London D Open",  offset = offset_val, transp=20, title="London D Open")

plot(not LonWOpen ? LonWOpenPA : na, title="London W Open", color=color.yellow, linewidth=2, style=plot.style_linebr)
plotshape(LonWOpenPA, style=shape.labeldown, location=location.absolute, color=color.yellow,  textcolor=color.white, show_last=1, text="London W Open",  offset = offset_val, transp=20, title="London W Open")



//--------------New York Configuration
NYDOpenInput = input('1429-1430:134567', title="New York Daily Open") //set the opening range you are interested in
NYWOpenInput = input('1429-1430:2', title="New York Weekly Open") //set the opening range you are interested in

//NYDOpen = time("1", NYDOpenInput)
//NYWOpen = time("1", NYWOpenInput)
NYDOpen = time(timeframe.period, NYDOpenInput)
NYWOpen = time(timeframe.period, NYWOpenInput)



var NYDOpenPA = 0.0
if NYDOpen
    if not NYDOpen[1]
        NYDOpenPA := open

var NYWOpenPA = 0.0
if NYWOpen
    if not NYWOpen[1]
        NYWOpenPA := open


plot(not NYDOpen ? NYDOpenPA : na, title="New York D Open", color=color.blue, linewidth=1, style=plot.style_linebr)
plotshape(NYDOpenPA, style=shape.labeldown, location=location.absolute, color=color.blue,  textcolor=color.white, show_last=1, text="New York D Open",  offset = offset_val, transp=20, title="New York D Open")

plot(not NYWOpen ? NYWOpenPA : na, title="New York W Open", color=color.blue, linewidth=2, style=plot.style_linebr)
plotshape(NYWOpenPA, style=shape.labeldown, location=location.absolute, color=color.blue,  textcolor=color.white, show_last=1, text="New York W Open",  offset = offset_val, transp=20, title="New York W Open")

Below is the final product. My aim was to be able map pre market trading with markets opening (based on links above) and easily see days of the week.

//@version=4
study("StackOverFlow", overlay=true)

offset_val = input(title="Label Offset", type=input.integer, defval=20)


// London Daily Open
LonDOpenInput = input('0800-0801:134567', title="London Daily Open")
LonDOpen = time(timeframe.period, LonDOpenInput)

var LonDOpenPA = float(na)
if LonDOpen and not LonDOpen[1]
    LonDOpenPA := open

plot(not LonDOpen ? LonDOpenPA : na, title="London Daily Open", color=color.yellow, linewidth=1, style=plot.style_linebr)
plotshape(LonDOpenPA, style=shape.labeldown, location=location.absolute, color=color.yellow,  textcolor=color.white, show_last=1, text="London Daily Open",  offset = offset_val, transp=20, title="London Daily Open")



// London Weekly Open
LonWOpenInput = input('0800-0801:2', title="London Weekly Open")
LonWOpen = time(timeframe.period, LonWOpenInput)

var LonWOpenPA = float(na)
if LonWOpen and not LonWOpen[1]
    LonWOpenPA := open

plot(not LonWOpen ? LonWOpenPA : na, title="London Weekly Open", color=color.yellow, linewidth=1, style=plot.style_linebr)
plotshape(LonWOpenPA, style=shape.labeldown, location=location.absolute, color=color.yellow,  textcolor=color.white, show_last=1, text="London Weekly Open",  offset = offset_val, transp=20, title="London Weekly Open")



// New York Daily Open
NYDOpenInput = input('1430-1431:134567', title="New York Daily") //set the opening range you are interested in
NYDOpen = time(timeframe.period, NYDOpenInput)

var NYDOpenPA = float(na)
if NYDOpen and not NYDOpen[1]
    NYDOpenPA := open

plot(not NYDOpen ? NYDOpenPA : na, title="New York Open", color=color.blue, linewidth=1, style=plot.style_linebr)
plotshape(NYDOpenPA, style=shape.labeldown, location=location.absolute, color=color.blue,  textcolor=color.white, show_last=1, text="New York Daily Open",  offset = offset_val, transp=20, title="New York Daily Open")



// New York Weekly Open
NYWOpenInput = input('1430-1431:2', title="New Weekly York") //set the opening range you are interested in
NYWOpen = time(timeframe.period, NYWOpenInput)

var NYWOpenPA = float(na)
if NYWOpen and not NYWOpen[1]
    NYWOpenPA := open

plot(not NYWOpen ? NYWOpenPA : na, title="New York Open", color=color.blue, linewidth=1, style=plot.style_linebr)
plotshape(NYWOpenPA, style=shape.labeldown, location=location.absolute, color=color.blue,  textcolor=color.white, show_last=1, text="New York Weekly Open",  offset = offset_val, transp=20, title="New York Weekly Open")



// Asia Daily Open
AsiaDOpenInput = input('0000-0001:124567', title="Asia Daily Open")
AsiaDOpen = time(timeframe.period, AsiaDOpenInput)

var AsiaDOpenPA = float(na)
if AsiaDOpen and not AsiaDOpen[1]
    AsiaDOpenPA := open

plot(not AsiaDOpen ? AsiaDOpenPA : na, title="Asia Daily Open", color=color.purple, linewidth=1, style=plot.style_linebr)
plotshape(AsiaDOpenPA, style=shape.labeldown, location=location.absolute, color=color.purple,  textcolor=color.white, show_last=1, text="Asia Daily Open",  offset = offset_val, transp=20, title="Asia Daily Open")



// Asia Weekly Open
AsiaWOpenInput = input('0000-0001:3', title="Asia Weekly Open")
AsiaWOpen = time(timeframe.period, AsiaWOpenInput)

var AsiaWOpenPA = float(na)
if AsiaWOpen and not AsiaWOpen[1]
    AsiaWOpenPA := open

plot(not AsiaWOpen ? AsiaWOpenPA : na, title="Asia Weekly Open", color=color.purple, linewidth=1, style=plot.style_linebr)
plotshape(AsiaWOpenPA, style=shape.labeldown, location=location.absolute, color=color.purple,  textcolor=color.white, show_last=1, text="Asia Weekly Open",  offset = offset_val, transp=20, title="Asia Weekly Open")



//----------------------------------------------------------------------------------------------------------------------

showDOW = input(true, title="Show Chart Text and Background Color")

inputMaxInterval = input(30, title="Hides sessions above specified time")
loadIndicator = timeframe.multiplier <= inputMaxInterval

PreNY = time(timeframe.period, "1130-1430:1234567")
NYOpen = time(timeframe.period, "1430-2100:1234567")

PreLondon = time(timeframe.period, "0505-0750:1234567")
LondonOpen = time(timeframe.period, "0800-1130:1234567")
LondonClose = time(timeframe.period, "1530-1700:1234567")

MorningAsia = time(timeframe.period, "0000-0230:1234567")
AfternoonAsia = time(timeframe.period, "0330-0505:1234567")


bgcolor(loadIndicator and showDOW and not na(PreNY) ? color.blue : na, transp=95, title='Pre New York')
bgcolor(loadIndicator and showDOW and not na(NYOpen) ? color.blue : na, transp=90, title='New York Open')

bgcolor(loadIndicator and showDOW and not na(PreLondon) ? color.yellow : na, transp=95, title='Pre London')
bgcolor(loadIndicator and showDOW and not na(LondonOpen) ? color.yellow : na, transp=90, title='London Open')

bgcolor(loadIndicator and showDOW and not na(MorningAsia) ? color.purple : na, transp=90, title='Morning Asia')
bgcolor(loadIndicator and showDOW and not na(AfternoonAsia) ? color.purple : na, transp=90, title='Afternoon Asia')


//Wednesday Opening Text
plotshape(showDOW and loadIndicator ? hour == 0 and minute == 0 and dayofweek == dayofweek.monday    : false, offset=0, style=shape.diamond, transp=0, text="Monday"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 5 and minute == 0 and dayofweek == dayofweek.monday    : false, offset=0, style=shape.square, transp=0, text="London Pre"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 8 and minute == 0 and dayofweek == dayofweek.monday    : false, offset=0, style=shape.square, transp=0, text="London Open"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 11 and minute == 30 and dayofweek == dayofweek.monday    : false, offset=0, style=shape.square, transp=0, text="New York Pre"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 14 and minute == 30 and dayofweek == dayofweek.monday    : false, offset=0, style=shape.square, transp=0, text="New York Open"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 16 and minute == 30 and dayofweek == dayofweek.monday    : false, offset=0, style=shape.square, transp=0, text="London Close"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 21 and minute == 00 and dayofweek == dayofweek.monday    : false, offset=0, style=shape.square, transp=0, text="New York Close"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 0 and minute == 0 and dayofweek == dayofweek.monday    : false, offset=0, style=shape.square, transp=0, text="Asia Morning"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 06 and minute == 00 and dayofweek == dayofweek.monday    : false, offset=0, style=shape.square, transp=0, text="Asia Close"   , color=color.white  , location = location.top, textcolor=color.white)


// Tuesday Opening Text
plotshape(showDOW and loadIndicator ? hour == 0 and minute == 0 and dayofweek == dayofweek.tuesday   : false, offset=0, style=shape.diamond, transp=0, text="Tuesday"  , color=color.white   , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 5 and minute == 0 and dayofweek == dayofweek.tuesday    : false, offset=0, style=shape.square, transp=0, text="London Pre"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 8 and minute == 0 and dayofweek == dayofweek.tuesday    : false, offset=0, style=shape.square, transp=0, text="London Open"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 11 and minute == 30 and dayofweek == dayofweek.tuesday    : false, offset=0, style=shape.square, transp=0, text="New York Pre"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 14 and minute == 30 and dayofweek == dayofweek.tuesday    : false, offset=0, style=shape.square, transp=0, text="New York Open"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 16 and minute == 30 and dayofweek == dayofweek.tuesday    : false, offset=0, style=shape.square, transp=0, text="London Close"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 21 and minute == 00 and dayofweek == dayofweek.tuesday    : false, offset=0, style=shape.square, transp=0, text="New York Close"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 0 and minute == 0 and dayofweek == dayofweek.tuesday    : false, offset=0, style=shape.square, transp=0, text="Asia Morning"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 06 and minute == 00 and dayofweek == dayofweek.tuesday    : false, offset=0, style=shape.square, transp=0, text="Asia Close"   , color=color.white  , location = location.top, textcolor=color.white)

// Wednesday Opening Text
plotshape(showDOW and loadIndicator ? hour == 0 and minute == 0 and dayofweek == dayofweek.wednesday : false, offset=0, style=shape.diamond, transp=0, text="Wednesday", color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 5 and minute == 0 and dayofweek == dayofweek.wednesday    : false, offset=0, style=shape.square, transp=0, text="London Pre"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 8 and minute == 0 and dayofweek == dayofweek.wednesday    : false, offset=0, style=shape.square, transp=0, text="London Open"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 11 and minute == 30 and dayofweek == dayofweek.wednesday    : false, offset=0, style=shape.square, transp=0, text="New York Pre"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 14 and minute == 30 and dayofweek == dayofweek.wednesday    : false, offset=0, style=shape.square, transp=0, text="New York Open"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 16 and minute == 30 and dayofweek == dayofweek.wednesday    : false, offset=0, style=shape.square, transp=0, text="London Close"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 21 and minute == 00 and dayofweek == dayofweek.wednesday    : false, offset=0, style=shape.square, transp=0, text="New York Close"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 0 and minute == 0 and dayofweek == dayofweek.wednesday    : false, offset=0, style=shape.square, transp=0, text="Asia Morning"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 06 and minute == 00 and dayofweek == dayofweek.wednesday    : false, offset=0, style=shape.square, transp=0, text="Asia Close"   , color=color.white  , location = location.top, textcolor=color.white)

// Thursday Opening Text
plotshape(showDOW and loadIndicator ? hour == 0 and minute == 0 and dayofweek == dayofweek.thursday  : false, offset=0, style=shape.diamond, transp=0, text="Thursday" , color=color.white, location = location.bottom, textcolor=color.white )
plotshape(showDOW and loadIndicator ? hour == 5 and minute == 0 and dayofweek == dayofweek.thursday    : false, offset=0, style=shape.square, transp=0, text="London Pre"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 8 and minute == 0 and dayofweek == dayofweek.thursday    : false, offset=0, style=shape.square, transp=0, text="London Open"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 11 and minute == 30 and dayofweek == dayofweek.thursday    : false, offset=0, style=shape.square, transp=0, text="New York Pre"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 14 and minute == 30 and dayofweek == dayofweek.thursday    : false, offset=0, style=shape.square, transp=0, text="New York Open"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 16 and minute == 30 and dayofweek == dayofweek.thursday    : false, offset=0, style=shape.square, transp=0, text="London Close"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 21 and minute == 00 and dayofweek == dayofweek.thursday    : false, offset=0, style=shape.square, transp=0, text="New York Close"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 0 and minute == 0 and dayofweek == dayofweek.thursday    : false, offset=0, style=shape.square, transp=0, text="Asia Morning"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 06 and minute == 00 and dayofweek == dayofweek.thursday    : false, offset=0, style=shape.square, transp=0, text="Asia Close"   , color=color.white  , location = location.top, textcolor=color.white)

// Friday Opening Text
plotshape(showDOW and loadIndicator ? hour == 0 and minute == 0 and dayofweek == dayofweek.friday    : false, offset=0, style=shape.diamond, transp=0, text="Friday"   , color=color.white, location = location.bottom, textcolor=color.white )
plotshape(showDOW and loadIndicator ? hour == 5 and minute == 0 and dayofweek == dayofweek.friday    : false, offset=0, style=shape.square, transp=0, text="London Pre"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 8 and minute == 0 and dayofweek == dayofweek.friday    : false, offset=0, style=shape.square, transp=0, text="London Open"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 11 and minute == 30 and dayofweek == dayofweek.friday    : false, offset=0, style=shape.square, transp=0, text="New York Pre"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 14 and minute == 30 and dayofweek == dayofweek.friday    : false, offset=0, style=shape.square, transp=0, text="New York Open"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 16 and minute == 30 and dayofweek == dayofweek.friday    : false, offset=0, style=shape.square, transp=0, text="London Close"   , color=color.white  , location = location.bottom, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 21 and minute == 00 and dayofweek == dayofweek.friday    : false, offset=0, style=shape.square, transp=0, text="New York Close"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 0 and minute == 0 and dayofweek == dayofweek.friday    : false, offset=0, style=shape.square, transp=0, text="Asia Morning"   , color=color.white  , location = location.top, textcolor=color.white)
plotshape(showDOW and loadIndicator ? hour == 06 and minute == 00 and dayofweek == dayofweek.friday    : false, offset=0, style=shape.square, transp=0, text="Asia Close"   , color=color.white  , location = location.top, textcolor=color.white)

Upvotes: 0

Views: 65

Answers (1)

AnyDozer
AnyDozer

Reputation: 2568

In this form it works on all intraday timeframes.

//--------------New York Configuration
NYDOpenInput = input('0930-0931:134567', title="New York Daily Open") //set the opening range you are interested in
NYWOpenInput = input('0930-0931:2', title="New York Weekly Open") //set the opening range you are interested in

// NYDOpen = time("1", NYDOpenInput)
// NYWOpen = time("1", NYWOpenInput)
NYDOpen = time(timeframe.period, NYDOpenInput)
NYWOpen = time(timeframe.period, NYWOpenInput)
       
var NYDOpenPA = float(na)
if NYDOpen and not NYDOpen[1]
    NYDOpenPA := open

var NYWOpenPA = float(na)
if NYWOpen and not NYWOpen[1]
    NYWOpenPA := open

plot(not NYDOpen ? NYDOpenPA : na, title="New York D Open", color=color.blue, linewidth=1, style=plot.style_linebr)
plotshape(NYDOpenPA, style=shape.labeldown, location=location.absolute, color=color.blue,  textcolor=color.white, show_last=1, text="New York D Open",  offset = offset_val, transp=20, title="New York D Open")

plot(not NYWOpen ? NYWOpenPA : na, title="New York W Open", color=color.blue, linewidth=2, style=plot.style_linebr)
plotshape(NYWOpenPA, style=shape.labeldown, location=location.absolute, color=color.blue,  textcolor=color.white, show_last=1, text="New York W Open",  offset = offset_val, transp=20, title="New York W Open")

Upvotes: 1

Related Questions