[pshaiCmd] VWMA v2 (Optimized)
stableDescription
Optimized version of CC_VWMA_SE.
HaasScript
DefineCommand('VWMA_v2', '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')
DefineIntervalOptimization(CurrentInterval(source))
local vwma = Load('vwma', {})
local base, tmp, value
local limit = 250
if Load('warmup', true) then
LogWarning('Warming up VWMA...')
for i=99, 0, -1 do
tmp = Grab(volume, i, period)
base = Sum(Grab(source, i, period) * tmp)
value = base / Sum(tmp)
vwma = ArrayUnshift(vwma, value)
end
LogWarning('Completed.')
Save('warmup', false)
else
tmp = Grab(volume, 0, period)
base = Sum(Grab(source, 0, period) * tmp)
vwma = ArrayUnshift(vwma, base / Sum(tmp))
end
if #vwma > limit then
vwma = Grab(vwma, 0, limit)
end
Save('vwma', vwma)
DefineOutput(ListDynamicType, vwma, 'VWMA values', 'Plot')
1 Comment
Sign in to leave a comment.
Thanks a million for this!