0

Hi i have looked endlessly and cannot figure out how to achieve this in pine. Would anyone be willing to help me with this? i want to ID the highest volume bar in say a session, or day, week, then launch a continuous vwap from that candle. whether it be a 1min candle or daily. can point me in the right direction or possibly what to start with as far as pine goes?

1 Answers1

0
//@version=4
study("Highest Volume Interval VWAP", overlay = true)

interval = input("D", title = "Interval")
src = input(hlc3, title = "source")

new_interval = change(time(interval)) != 0

var float highest_volume = na
var float pvsum = na
var float vsum = na

bool signal_new_vwap = false


if new_interval
    highest_volume := volume
    pvsum := volume * src
    vsum := volume
    signal_new_vwap := true
else if volume > highest_volume
    highest_volume := volume
    pvsum := volume * src
    vsum := volume
    signal_new_vwap := true
else
    pvsum := pvsum + volume * src
    vsum := vsum + volume


hvi_vwap = pvsum / vsum

plot(hvi_vwap)

plotshape(signal_new_vwap, location = location.belowbar, style = shape.triangleup, color = color.blue, size = size.small)

bgcolor(new_interval ? color.fuchsia : na)
rumpypumpydumpy
  • 3,435
  • 2
  • 5
  • 10
  • Thank you! your anchored vwap was what i was using as reference actually! Thank you so much! – James Ferreira Jul 25 '21 at 17:14
  • Can you elaborate on how this is returning the highest volume vwap? i see it in the code, but no where on the chart is it actually singling out the highest volume bar then launching a vwap from that point. it just resets a new vwap each day. Ive tried a ton of different things to get it to ID ONLY the highest volume bar within the resolution but it wont. – James Ferreira Aug 04 '21 at 22:44
  • At the beginning of the day we don't know what will be the highest volume bar for that day, so we can only calculate based on what we know. What the above code does is track the highest volume starting at the beginning of the day. At bar one, it is the highest volume because it is the ONLY bar so far. Every bar after that during the same day if we get a higher volume bar, it is reset again from that point. If it doesn't reset again, it means that no other bar had higher volume than the first bar. The `plotshape()` indicates when the calculation for the vwap was restarted. – rumpypumpydumpy Aug 04 '21 at 23:05
  • ok Thats where its going wrong then. I'm looking to plot from THE highest volume DAY, and show on any intraday resolution. so if the highest volume day was december 30th, 2020, i want to see a vwap launched from there and show on my intraday chart. And have the ability to change that vwaps resolution if wanted. so if i want to see only the highest volume bar i can do that, or highest volume day. in simple sentence, "ID highest volume day or bar and launch a vwap from there and have no time reset from that point. – James Ferreira Aug 04 '21 at 23:19
  • I see, it's probably not impossible, but it may be a little difficult to do. Are you trying to show the Daily resolution of the VWAP regardless of timeframe? – rumpypumpydumpy Aug 04 '21 at 23:57
  • is there a way i can share the current TOS version of the code? and show you images? – James Ferreira Aug 05 '21 at 00:03
  • You can message me on TV, but there are some significant differences between thinkscript and pine. In this case I would guess that the TOS script most likely uses future references, which is impossible in pine. You would still have to use something like the reset/recalc type approach as in the answer. Your shortest route is to either script or manually identify the anchor candle with one script and then input the anchor timestamp into a VWAP script. – rumpypumpydumpy Aug 05 '21 at 00:43