diff --git a/Bullmania_Money_Line_v4.pine b/Bullmania_Money_Line_v4.pine new file mode 100644 index 0000000..a8c909e --- /dev/null +++ b/Bullmania_Money_Line_v4.pine @@ -0,0 +1,66 @@ +//@version=5 +indicator("Bullmania Money Line v4", overlay=true) + +// Base inputs +atrPeriod = input.int(10, "ATR Period", minval=1) +multiplier = input.float(3.0, "Multiplier", minval=0.1, step=0.1) + +// Noise reduction (optional) - defaults preserve v1 behavior +confirmBars = input.int(1, "Flip confirmation bars", minval=1, maxval=5, tooltip="Require this many consecutive closes beyond the Money Line before flipping trend. 1 = v1 behavior.") +bufferATR = input.float(0.0, "Flip buffer (×ATR)", minval=0.0, step=0.05, tooltip="Extra distance beyond the Money Line required to flip. Example: 0.3 means close must cross by 0.3 × ATR.") + +atr = ta.atr(atrPeriod) +src = (high + low) / 2 + +up = src - (multiplier * atr) +dn = src + (multiplier * atr) + +var float up1 = na +var float dn1 = na + +up1 := nz(up1[1], up) +dn1 := nz(dn1[1], dn) + +up1 := close[1] > up1 ? math.max(up, up1) : up +dn1 := close[1] < dn1 ? math.min(dn, dn1) : dn + +var int trend = 1 +var float tsl = na +var int buyCount = 0 +var int sellCount = 0 + +tsl := nz(tsl[1], up1) + +if trend == 1 + tsl := math.max(up1, tsl) + // Buffered cross + confirmation for flip down + sellCross = close < (tsl - bufferATR * atr) + sellCount := sellCross ? sellCount + 1 : 0 + trend := sellCount >= confirmBars ? -1 : 1 + if trend == -1 + buyCount := 0 +else + tsl := math.min(dn1, tsl) + // Buffered cross + confirmation for flip up + buyCross = close > (tsl + bufferATR * atr) + buyCount := buyCross ? buyCount + 1 : 0 + trend := buyCount >= confirmBars ? 1 : -1 + if trend == 1 + sellCount := 0 + +supertrend = tsl + +// Plot the Money Line +upTrend = trend == 1 ? supertrend : na +downTrend = trend == -1 ? supertrend : na + +plot(upTrend, "Up Trend", color=color.new(color.green, 0), style=plot.style_linebr, linewidth=2) +plot(downTrend, "Down Trend", color=color.new(color.red, 0), style=plot.style_linebr, linewidth=2) + +// Plot buy/sell signals +plotshape(trend == 1 and trend[1] == -1, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.circle, size=size.small) +plotshape(trend == -1 and trend[1] == 1, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.circle, size=size.small) + +// Fill area between price and Money Line +fill(plot(close, display=display.none), plot(upTrend, display=display.none), color=color.new(color.green, 90)) +fill(plot(close, display=display.none), plot(downTrend, display=display.none), color=color.new(color.red, 90))