Positive Volume Index indicator - PVI

beta
By Bunka in Hybrid Published March 2022 👁 1,387 views 💬 0 comments

Description

Positive Volume Index indicator - PVI The theory behind the indexes is as follows: On days of increasing volume, you can expect prices to increase, and on days of decreasing volume, you can expect prices to decrease. This goes with the idea of the market being in-gear and out-of-gear. Both PVI and NVI work in similar fashions: Both are a running cumulative of values, which means you either keep adding or subtracting price rate of change each day to the previous day's sum. In the case of PVI, if today's volume is less than yesterday's, don't add anything; if today's volume is greater, then add today's price rate of change. For NVI, add today's price rate of change only if today's volume is less than yesterday`s.
HaasScript
-- Author of haascript version: Bunka
-- Positive Volume Index indicator - PVI

--------------------------------------------------------------------------------------
--  Copyright by HPotter v1.0 11/06/2014
-- The theory behind the indexes is as follows: On days of increasing volume, 
-- you can expect prices to increase, and on days of decreasing volume, you can 
-- expect prices to decrease. This goes with the idea of the market being in-gear 
-- and out-of-gear. Both PVI and NVI work in similar fashions: Both are a running 
-- cumulative of values, which means you either keep adding or subtracting price 
-- rate of change each day to the previous day`s sum. In the case of PVI, if today`s 
-- volume is less than yesterday`s, don`t add anything; if today`s volume is greater, 
-- then add today`s price rate of change. For NVI, add today`s price rate of change 
-- only if today`s volume is less than yesterday`s.
--------------------------------------------------------------------------------------

DefineCommand("PVI","Positive Volume Index indicator - PVI")

local interval = DefineParameter(NumberType,"PVI interval", "PVI inteval", false, InputInterval("PVI interval", 0, "PVI interval", "PVI indicator"))
local EMA_Len = DefineParameter(NumberType, "EMA length", "EMA length", false, Input("EMA length", 10, "EMA length", "PVI indicator"))
local market = DefineParameter(StringType, "Market", "Market", false, InputMarket("Market", PriceMarket(), "Market", "PVI indicator"))
local plot_or_not = DefineParameter(BooleanType, "plot PVI", "enable or disable plot", false, Input("plot PVI", true, "enable or disable plot", "PVI indicator"))

--local interval = DefineParameter(NumberType,"PVI interval", "PVI inteval", false, 0)
--local EMA_Len = DefineParameter(NumberType, "EMA length", "EMA length", false, 10)
--local market = DefineParameter(StringType, "Market", "Market", false, PriceMarket())
--local plot_or_not = DefineParameter(BooleanType, "plot PVI", "enable or disable plot", false, true)

local c = ClosePrices(interval,true,market)
local v = GetVolume(interval,true,market)

OptimizedForInterval(
    0,
    function()
        --local EMA_Len = Input("EMA_Len", 10)
        local xROC = ROC(c, 1)
        local nRes = Load("nRes",HNC(EMA_Len,0))
        local nRes = ArrayUnshift(nRes,IfElse(v[1] > v[2], nRes + xROC, nRes))
        local nRes = ArrayPop(nRes)

        local nResEMA = EMA(nRes, EMA_Len)

        if plot_or_not then
            Plot(1,"PVI",nRes,Red)
            Plot(1,"EMA of PVI",nResEMA,Aqua)
        end
        
        local results = {
            PVI = nRes,
            EMA_PVI = nResEMA,
            }

        DefineOutput(ListDynamicType, results, 'PVI & Ema of PVI')
        DefineOutputIndex(1,ListNumberType,"PVI","Positive Volume Index indicator - PVI")
        DefineOutputIndex(2,ListNumberType,"EMA of PVI","EMA of PVI")
    end
)

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!