[pshaiCmd] VMA (LB)

stable
By pshai in Momentum Published February 2021 👁 1,429 views 💬 0 comments

Description

Conversion of the LazyBear's VMA indicator: https://www.tradingview.com/script/6Ix0E5Yr-Variable-Moving-Average-LazyBear/ Command takes in price data and a number, and spits out the VMA values which you can plot and use. ~pshai
HaasScript
-- Author: [email protected]

DefineCommand('VMA_LB', 'Conversion of the LazyBears VMA indicator')

local src = DefineParameter(ListNumberType, 'source', 'Source data for VMA', true, ClosePrices(), 'Price Data')
local l = DefineParameter(NumberType, 'length', 'VMA calcualtion period length', true, 10, 'Number, Input, SessionGet')

DefineIntervalOptimization(CurrentInterval(src)) -- interval from source data

local k = 1.0 / l
local zeros = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
local pdm = Max((src - src[2]), zeros)
local mdm = Max((src[2] - src), zeros)
local pdmS = ((1 - k)*Load('pdmS', 0) + k*pdm)
local mdmS = ((1 - k)*Load('mdmS', 0) + k*mdm)
Save('pdmS', pdmS)
Save('mdmS', mdmS)
local s = pdmS + mdmS
local pdi = pdmS/s
local mdi = mdmS/s
local pdiS = ((1 - k)*Load('pdiS', 0) + k*pdi)
local mdiS = ((1 - k)*Load('mdiS', 0) + k*mdi)
Save('pdiS', pdiS)
Save('mdiS', mdiS)
local d = Abs(pdiS - mdiS)
local s1 = pdiS + mdiS
local iS = ((1 - k)*Load('iS', 0) + k*d/s1)
Save('iS', iS)
local hhv = GetHigh(iS, l) 
local llv = GetLow(iS, l) 
local d1 = hhv - llv
local vI = (iS - llv)/d1
local vma = (1 - k*vI)*Load('vma', src) + k*vI*src
Save('vma', vma)
local vmaC = (vma > vma[2]) and Green or (vma < vma[2]) and Red or (vma==vma[2]) and Blue or Black 
--Plot(0, "VMA", vma, {c = Yellow, w = 3})
--PlotSignalBar(-2, vmaC)

DefineOutput(ListNumberType, vma, 'VMA values', 'Plot')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!