Boxes for Intraday Sessions are not showing up

Viewed 17

This script paints Lines under specific sessions, however, it only allows sessions by the hour. How am I able to modify this to show timeframes such as 8:30 to 11:30?

I have not much experience with coding, but so far, this is what I've been trying for the last couple of hours:

  • Tried changing input.integer to input.session & input.float
  • Tried using plot function instead of line.new

With not much experience, it's been hard to find the right information to do this. I've been searching through the Reference Manuals and forums, and I've also been looking at other scripts to get new ideas, but I haven't had much luck with this type of script...

Thank you in advance!

//@version=4
study("Futures Killzone Boxes")

// ==== INPUTS ====
AS = input(title="Asian Start", type=input.integer, defval=1900, minval=0, maxval=25)
AE = input(title="Asian End", type=input.integer, defval=2300, minval=0, maxval=25)
LOS = input(title="London Open Start", type=input.integer, defval=0100, minval=0, maxval=25)
LOE = input(title="London Open End", type=input.integer, defval=0400, minval=0, maxval=25)
NYOS = input(title="New York Open Start", type=input.integer, defval=0730, minval=0, maxval=25)
NYOE = input(title="New York Open End", type=input.integer, defval=1000, minval=0, maxval=25)
NYCS  = input(title="New York Close Start", type=input.integer, defval=1200, minval=0, maxval=25)
NYCE  = input(title="New York Close End", type=input.integer, defval=1500, minval=0, maxval=25)
WIDTH = input(title="Lines Width", type=input.integer, defval=25, minval=0, maxval=25)

// ==== KZ COLOURS ====
color akzColour = input(#000000, "Asian Killzone")
color lokzColour = input(#FF0000, "London open Killzone")
color nyokzColour = input(#0000FF, "New York Open Killzone")
color nyckzColour = input(#008000, "New York Close Killzone")


// ===== VARIABLES =====
dt=3600000
newday = timestamp(year,month,dayofmonth,0,0,0)
x = newday == time


// ===== DRAW KILL ZONES ====
if x
    A = line.new(time + AS*dt, 1,time + AE*dt,1,xloc=xloc.bar_time, color = akzColour, style=line.style_solid,width=WIDTH)
    LO = line.new(time + LOS*dt, 1,time + LOE*dt,1,xloc=xloc.bar_time, color = lokzColour, style=line.style_solid,width=WIDTH)
    NYO = line.new(time + NYOS*dt, 1,time + NYOE*dt,1,xloc=xloc.bar_time, color = nyokzColour, style=line.style_solid,width=WIDTH)
    NYC = line.new(time + NYCS*dt, 1,time + NYCE*dt,1,xloc=xloc.bar_time, color = nyckzColour, style=line.style_solid,width=WIDTH)

// ===== VISIBILITY CHANGE ====
1 Answers

You can use input.session to get your session time. Then feed the time() function with this input.

//@version=5
indicator("My script", overlay=true)

timeAllowed = input.session("0830-1130", "Session")

// Check to see if we are in allowed hours using session info on all 7 days of the week.
timeIsAllowed = time(timeframe.period, timeAllowed + ":1234567")

bgcolor(timeIsAllowed ? color.new(color.blue, 85) : na)

enter image description here

Related