KDJ indicator

stable
By Bunka in Momentum Published February 2021 👁 1,635 views 💬 0 comments

Description

KDJ indicator, useful to detect those moments in time... use with caution and combine with some other indicator(s) Bunka's HS port of "KDJ_indicator" from pinescript (TV) created by "iamaltcoin"
HaasScript
-- Bunka's port of "KDJ_indicator" 
-- from TV pinescript from creator "iamaltcoin"

DefineCommand("KDJ_indicator", "KDJ_indicator")

local interval = DefineParameter(NumberType,"KDJ interval", "KDJ inteval", false, InputInterval("KDJ interval", 1, "KDJ interval", "KDJ indicator"))
local ilong = DefineParameter(NumberType, "KDJ period", "KDJ period", false, Input("KDJ period", 9, "KDJ period", "KDJ indicator"))
local isig = DefineParameter(NumberType, "KDJ signal", "KDJ signal", false, Input("KDJ signal", 3, "KDJ signal", "KDJ indicator"))
local plot_or_not = DefineParameter(BooleanType, "plot KDJ", "enable or disable plot", false, Input("plot KDJ", true, "enable or disable plot", "KDJ indicator"))

DefineIntervalOptimization(interval)

local function bcwsma(s,l,m,index) 
    local _s = s
    local _l = l
    local _m = m
    local _bcwsma = (_m*_s + (_l-_m) * Load("prev_bcwsma"..index, 0)) / _l
    Save("prev_bcwsma"..index, _bcwsma)
    return _bcwsma
    end

local c = ClosePrices(interval)
local h = GetHighs(HighPrices(interval), ilong)
local l = GetLows(LowPrices(interval), ilong)

local RSV = 100*((c-l)/(h-l))
local pK = bcwsma(RSV, isig, 1,1)
local pD = bcwsma(pK, isig, 1,2)
local pJ = 3 * pK-2 * pD
--Log(pK)
--Log(pD)
--Log(pJ)

if plot_or_not then
    Plot(5, "pK", pK, {c = Cyan})
    Plot(5, "pD", pD, {c = Orange})
    Plot(5, "pJ", pJ, {c = Purple})
    Plot(5,"upper", 80, {c=Gray(30)})
    Plot(5,"lower", 20, {c=Gray(30)})
    
    --if pJ > pD then
    --    PlotVerticalLine(5, "zone", Green(30), Time() )
    --else
    --    PlotVerticalLine(5, "zone", Red(30), Time() )
    --end
end

local results = {
    pK = pK,
    pD = pD,
    pJ = pJ,
    }

DefineOutput(ListDynamicType, results, 'KDJ Indicator lines')
DefineOutputIndex(1, ListNumberType, "pK", 'longest')
DefineOutputIndex(2, ListNumberType, "pD", 'long line')
DefineOutputIndex(3, ListNumberType, "pJ", 'short line')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!