Volume Weighted Average Price for Haas V4
stableDescription
VWAP built in same manner as TWAP script - choose interval to draw/calculate values, and second interval to reset VWAP. If draw/reset values are the same, script will draw VWAP per candle which can come in handy on certain scalping strategies.
HaasScript
--Author: Fogg
DefineCommand("VWAP_V4", "User Defined VWAP")
local interval = DefineParameter(NumberType, 'Interval', 'The interval to draw the VWAP, defaults to Current Interval', false, CurrentInterval(), 'InputInterval/CurrentInterval')
local vwapint = DefineParameter(NumberType, 'VWAP Interval', 'The time interval to reset the VWAP, defaults to 1D', false, 1440, 'InputInterval/CurrentInterval')
local plot = DefineParameter(BooleanType, 'Plot', 'Enable plotting the chart, defaults to true', false, true, 'true/false')
local hlc3 = HLCPrices(interval, true, PriceMarket(), true)
local vol = GetVolume(interval, true, PriceMarket(), true)
local trigger = Load('trigger', true)
local newSession = trigger == OptimizedForInterval(vwapint, function()
local trigger = Load('trigger', true)
Save('trigger', not trigger)
return trigger
end)
local vwapsum = Load('vwapsum', hlc3*vol)
local volsum = Load('volsum', vol)
vwapsum = newSession and hlc3*vol or vwapsum+hlc3*vol
volsum = newSession and vol or volsum+vol
local vwap = vwapsum/volsum
if plot == true then
local V
if vwap > 0 then
V=Plot(0, "VWAP", vwap, {c=Fuchsia})
end
PlotCircle(V, Fuchsia(50))
end
Save('vwapsum', vwapsum)
Save('volsum', volsum)
DefineOutput(ListNumberType, vwap, 'VWAP')
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!