rohan sawant
rohan sawant

Reputation: 121

How to get the exact time of market open and market close

I want to get the exact time of marketclose & maketopen.

Each Value must be stored in their own respective time-based variables for further calculations

//@version=5

indicator('time market open close', overlay=true, precision=1)

market_open = time(

market_close = time

plot(market_open )  // the stock market starts


plot(market_close ) //  the stock market  ends for the day

MY ENTIRE CODE FOR MANY INDICATORS HAS COMPLETED BEEN HALTED BASED ON THIS ISSUE

Upvotes: 1

Views: 2098

Answers (1)

Bjorn Mistiaen
Bjorn Mistiaen

Reputation: 6865

This will give you the open/close times of your ticker.
You can find out more about date/time formatting in the User manual on Time.

//@version=5
indicator('time market open close', overlay=true, precision=1)

var string  dateTimeFormat = "{0,time,full}"
var color   myColor        = color.new(color.yellow, 70)

var int market_open  = na
var int market_close = na

newDay = dayofmonth != dayofmonth[1]

if newDay
    market_open  := time
    market_close := time_close[1]

if barstate.islast
    market_open_str  = str.format(dateTimeFormat, market_open)
    market_close_str = str.format(dateTimeFormat, market_close)
    label_str        = 'open : ' + market_open_str + '\nclose : ' + market_close_str
    label.new(bar_index, close, label_str, style=label.style_label_left)

bgcolor(newDay ? myColor : na) // show start of a new day

Which yields

screenshot

Upvotes: 3

Related Questions