//@version=6 strategy("HMA Strat", shorttitle="HMAstrat", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1) // === INPUTS === length = input.int(24, minval=1, title="HMA Length") src = input.source(hl2, "Source") showSignals = input.bool(true, "Show Buy/Sell Signals") // === FUNCTIONS === hma(_src, _length) => wma1 = ta.wma(_src, _length) wma2 = ta.wma(_src, _length / 2) rawHMA = 2 * wma2 - wma1 ta.wma(rawHMA, 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) // === HMA CALCULATIONS === a = hma(src, length) b = hma3(src, length) // === COLOR LOGIC === isBull = b > a colorLine = isBull ? #00ffdd : #80010a fillColor = color.new(colorLine, 80) // === PLOTTING === p1 = plot(a, color=colorLine, linewidth=1) p2 = plot(b, color=colorLine, linewidth=1) fill(p1, p2, color=fillColor) // === SIGNALS === crossUp = b > a and b[1] < a[1] crossDown = a > b and a[1] < b[1] plotshape(showSignals and crossUp, title="Buy Signal", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.green, text="Buy") plotshape(showSignals and crossDown, title="Sell Signal", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.red, text="Sell") // === STRATEGY LOGIC === // Close opposite position before opening a new one if crossUp strategy.close("Short") strategy.entry("Long", strategy.long) if crossDown strategy.close("Long") strategy.entry("Short", strategy.short)