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

0 447 Views No Comments 1 year ago
  • Haas Script version of the Volume-Weighted Moving Average.

    * source : Price source
    * volume : Volume source
    * period : Period length

    * VWMA values

    HaasScript Code
    -- 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))
    -- Output
    DefineOutput(ListNumberType, vwma, 'VWMA values', 'Plot')
Login or Register to Comment

Unlock your crypto trading potential

Create a free account and enjoy everything we have to offer.

Join for Free