Reputation: 27
I am trying to show cumulative premarket volume on the daily chart. I cannot get pine script to show anything on the daily chart during premarket. I am trying to debug my problem (and hence put in 100K as a default for now. I thought this should create a volume candle of 100K volume on the daily chart in the premarket. But nothing shows up.
plotVolume = timeInRange(timeframe.period, "0400-0930") ? 100000 : volume
plot(plotVolume, color = color.new(palette,15), style=plot.style_columns, title="Volume")
My thought process: Get the 100K volume candle to show up on the daily chart in the premarket...once that is successful, replace 100K with a cumulative volume function of the 5M chart using request.security. Appreciate any help!
Upvotes: 0
Views: 1005
Reputation: 6905
This will do it.
You must also enable extended hours on your chart.
//@version=5
indicator('Cumulative volume', 'CV')
var float cv = 0
// Reset volume when a new day has started, or when market session begins
if (dayofmonth != dayofmonth[1]) or (session.ismarket and session.ispremarket[1])
cv := 0
cv += volume
plot(cv, style=plot.style_columns)
Edit 1 in response to this comment
For the previous solution, you must be on a lower timeframe than daily.
But I see now you want to keep your chart on the daily timeframe, AND see the pre-market volume.
To make that happen, you'll have to look inside the bar, to the lower timeframe (1 minute in my example below).
But I doubt it will work, because you need a bar on the daily timeframe to look inside of, and in the pre-market you don't have a bar yet. You can try though.
If it doesn't work, then I don't think it can be done in Pine afaik, unless someone else knows of a way to do this.
Should it work, also be aware that the data will not be the most accurate, because:
security()
on lower intervals doesn’t always return reliable data. Intrabar volume information on stocks, for example, will not match >1D volume, as data for both is reported differently by exchanges.
For more information about intrabar inspection, you can take a look at Is it possible to use security() on lower intervals than the chart’s current interval?
//@version=5
indicator('IntraBar Volume')
f_intrabar(_src, _res) =>
var int _barNo = 0
var float _value = na
if ta.change(time(_res))
_value := 0
_value += _src
intraBarVolume = request.security(syminfo.tickerid, '1', f_intrabar(volume, 'D'))
plot(intraBarVolume, style=plot.style_columns)
Upvotes: 1