Reputation: 55
I am trying to create a cumulative histogram based on NYSE Tick for Intra-Day trading. The accumulative indicator should be reset to zero on each day at 9:30am. I have so far created the cumulative histogram but I have no idea how to reset it to zero. Can anyone help?
study(title="NYSE Ticks")
x = security ("TICK.NY", period, close)
c = x > x[1] ? green : red
cti = cum(x)
plot(cti,style=histogram,color=c,linewidth=4)
I am day 1 new to Pine Script. I have also searched similar topic but in vane. Please help.
Upvotes: 1
Views: 2368
Reputation: 8789
This uses the time()
function with session information to detect if the chart's bar is in the required time period.
Your code is now v4:
//@version=4
study(title="NYSE Ticks")
resetTime = input("0930-1000", "Reset time", input.session)
x = security ("TICK.NY", timeframe.period, close)
// Returns non `na` value when in session.
trigger = not na(time(timeframe.period, resetTime))
// Detect when reset time is hit.
reset = trigger and not trigger[1]
var cti = 0.
cti := reset ? 0. : cti + x
c = x > x[1] ? color.green : color.red
plot(cti, "cti", c, 4, plot.style_histogram)
// For debugging.
bgcolor(reset ? color.silver : na)
Upvotes: 3