Change TradingView Indicator Daily Start Time

300 views Asked by At

I want my Pinescript code to start with UTC-4 (GMT-5) instead of the default UTC. You can see my indicator starts at 17:00 in the images. So 17:00-17:00 is a daily span instead of 00:00-00:00 in UTC-4. Any help with a function I can add that changes what a daily value is would be appreciated.Thank you. I have an image of the chart attached with the code below.

Indicator Picture

//@version=5

//
indicator(title='CPR, VWAP, EMAs, MASTER - CAM', shorttitle='CPR,VWAP,EMAs, MASTER', overlay=true)

//TIMEZONE
zone = input("GMT-5")

daily_cpr = input.int(title='Number of Daily CPR Back', defval=100, minval=0)
onehr_cpr = input.int(title='Number of 1HR CPR Back', defval=0, minval=0)
fourhr_cpr = input.int(title='Number of 4HR CPR Back', defval=0, minval=0)
eighthr_cpr = input.int(title='Number of 8HR CPR Back', defval=0, minval=0)
weekly_cpr = input.int(title='Number of Weekly CPR Back', defval=0, minval=0)
monthly_cpr = input.int(title='Number of Monthly CPR Back', defval=0, minval=0)

new_bar(res) =>
    ta.change(time(res)) != 0
new_period(condition, src) =>
    result = 0.0
    result := condition ? src : result[1]
    result

pivot = (high + low + close) / 3.0
bc = (high + low) / 2.0
tc = pivot - bc + pivot


//Daily Central Pivot Range
dpp = request.security(syminfo.tickerid, 'D', pivot[1], lookahead=barmerge.lookahead_on)
dbc = request.security(syminfo.tickerid, 'D', bc[1], lookahead=barmerge.lookahead_on)
dtc = request.security(syminfo.tickerid, 'D', tc[1], lookahead=barmerge.lookahead_on)

one_day = 1000 * 60 * 60 * 24
new_day = daily_cpr > 0 and timenow - time < one_day * daily_cpr and new_bar('D')
dpp_ = new_period(new_day, dpp)
dtc_ = new_period(new_day, dtc)
dbc_ = new_period(new_day, dbc)

plot(timeframe.isintraday ? dtc_ >= dbc_ ? dtc_ : dbc_ : na, title='Daily TC',     style=plot.style_steplinebr, color=color.new(#238859, 0), linewidth=1)
plot(timeframe.isintraday ? dpp_ : na, title='Daily PP', style=plot.style_steplinebr,     color=color.new(#238859, 0), linewidth=1)
plot(timeframe.isintraday ? dtc_ >= dbc_ ? dbc_ : dtc_ : na, title='Daily BC',     style=plot.style_steplinebr, color=color.new(#238859, 0), linewidth=1)`

I've tried adding the Timezone option and having a drop down timezone option does not change when the indicator starts and stops.

I've attempted utilizing syminfo.timezone as well but couldn't properly add it to the code.

1

There are 1 answers

2
vitruvius On

That is because you are using request.security(). It will always use exchange's timezone.

These are what you pass to and get from the security() call.

pivot = (high + low + close) / 3.0
bc = (high + low) / 2.0
tc = pivot - bc + pivot

You need to calculate those values yourself.

Below is an example of how you can get the high price of a day with a custom timezone.

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

time_hour = 00
time_min = 00

is_new_day = timestamp("GMT-5", year, month, dayofmonth, time_hour, time_min, 0) == timestamp(year, month, dayofmonth, hour, minute, 0)

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

var float high_adjusted = na

if (is_new_day)
    high_adjusted := high
else
    if (high > high_adjusted)
        high_adjusted := high

plot(high_adjusted, "High - Adj", color.green)

enter image description here