[pshaiCmd] Volume-Weighted Moving Average (SE version)

stable
By pshai in Trend Published October 2019 👁 1,679 views 💬 0 comments

Description

Haas Script version of the Volume-Weighted Moving Average. Parameters: * source : Price source * volume : Volume source * period : Period length Output: * VWMA values
HaasScript
-- Command and parameter definitions
DefineCommand('VWMA_SE', 'Volume-Weighted Moving Average, Script Editor version')

local source = DefineParameter(ListNumberType, 'source', 'Price source', true, ClosePrices(), 'ClosePrices, HLPrices, HLCPrices, OHLCPrices')
local volume = DefineParameter(ListNumberType, 'volume', 'Volume source', true, GetVolume(), 'GetVolume')
local period = DefineParameter(NumberType, 'period', 'Period length', true, 20, 'Input, Number')

-- Variables
local base, vwma, tmp

-- Magic
for i=period, 0, -1 do
    tmp = Grab(volume, i, period)
    base = Sum(Grab(source, i, period) * tmp)
    vwma = SourceManager(base / Sum(tmp))
end

-- Output
DefineOutput(ListNumberType, vwma, 'VWMA values', 'Plot')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!