implement a high timeframe option to this indicator?

Viewed 15

I'm trying to implement a high timeframe option to this indicator, but I can't figure it out. Anyone can help me? I think I am wrong with entering an expression on the security

Thanks in advance!

//@version=5
indicator("Kahlman", shorttitle="Kahlman", overlay=true)

useHtf = input(false, title='Timeframe', group="Kahlman")
htf = input.timeframe('240', title='Higher Timeframe', group="Kahlman")
src       = input(hl2,   "Price Data", group="Kahlman")
length    = input(24,    "Lookback", group="Kahlman")
showcross = input(true,  "Show cross over/under", group="Kahlman")
gain      = input(10000, "Gain", group="Kahlman")
j         = input(false,  "Use Kahlman", group="Kahlman")

Timeframe = request.security(syminfo.ticker, htf, a)

hma(_src, _length) =>
    ta.wma((2 * ta.wma(_src, _length / 2)) - ta.wma(_src, _length), math.round(math.sqrt(_length)))
    
hma3(_src, _length) =>
    p = length/2
    ta.wma(ta.wma(close,p/3)*3 - ta.wma(close,p/2) - ta.wma(close,p),p)

kahlman(x, g) =>
    kf = 0.0
    dk = x - nz(kf[1], x)
    smooth = nz(kf[1],x)+dk*math.sqrt((g/10000)*2)
    velo = 0.0
    velo := nz(velo[1],0) + ((g/10000)*dk)
    kf := smooth+velo
  
a = j ? kahlman(hma(src, length), gain) : hma(src, length)
b = j ? kahlman(hma3(src, length), gain) : hma3(src, length)
c = b > a ? color.yellow : color.gray
crossdn = a > b and a[1] < b[1]
crossup = b > a and b[1] < a[1]

p1 = plot(a,color=c,linewidth=1,transp=75)
p2 = plot(b,color=c,linewidth=1,transp=75)
fill(p1,p2,color=c,transp=55)
plotshape(showcross and crossdn ? a : na, location=location.abovebar, style=shape.triangledown, color=color.gray, size=size.tiny, transp=0, offset=-1)
plotshape(showcross and crossup ? a : na, location=location.belowbar, style=shape.triangleup, color=color.yellow, size=size.tiny, transp=0, offset=-1)
0 Answers
Related