diff --git a/workflows/trading/moneyline_v8_sticky_trend.pinescript b/workflows/trading/moneyline_v8_sticky_trend.pinescript index 20c6bfb..303d3c5 100644 --- a/workflows/trading/moneyline_v8_sticky_trend.pinescript +++ b/workflows/trading/moneyline_v8_sticky_trend.pinescript @@ -40,8 +40,8 @@ macdSigLen = input.int(9, "Signal", minval=1, inline="macdLens") // Signal timing (ALWAYS applies to all signals) groupTiming = "Signal Timing" -confirmBars = input.int(0, "Bars to confirm after flip", minval=0, maxval=2, group=groupTiming, tooltip="V8: Keep at 0 for immediate flips with threshold protection.") -flipThreshold = input.float(0.5, "Flip threshold %", minval=0.0, maxval=2.0, step=0.1, group=groupTiming, tooltip="V8 NEW: Require price to move this % beyond line before flip confirms. Reduces noise.") +confirmBars = input.int(2, "Bars to confirm after flip", minval=0, maxval=3, group=groupTiming, tooltip="V8: Wait X bars after flip to confirm trend change. Filters rapid flip-flops.") +flipThreshold = input.float(0.8, "Flip threshold %", minval=0.0, maxval=2.0, step=0.1, group=groupTiming, tooltip="V8: Require price to move this % beyond line before flip. Increased to 0.8% to filter small bounces.") // Entry filters (optional) groupFilters = "Entry filters" @@ -131,14 +131,30 @@ tsl := nz(tsl[1], up1) // V8: Apply flip threshold - require price to move X% beyond line before flip thresholdAmount = tsl * (flipThreshold / 100) +// Track consecutive bars in potential new direction (anti-whipsaw) +var int bullMomentumBars = 0 +var int bearMomentumBars = 0 + if trend == 1 tsl := math.max(up1, tsl) - // Require price to close below line by threshold % before flipping bearish - trend := calcC < (tsl - thresholdAmount) ? -1 : 1 + // Count consecutive bearish bars + if calcC < (tsl - thresholdAmount) + bearMomentumBars := bearMomentumBars + 1 + bullMomentumBars := 0 + else + bearMomentumBars := 0 + // Flip only after X consecutive bars below threshold + trend := bearMomentumBars >= (confirmBars + 1) ? -1 : 1 else tsl := math.min(dn1, tsl) - // Require price to close above line by threshold % before flipping bullish - trend := calcC > (tsl + thresholdAmount) ? 1 : -1 + // Count consecutive bullish bars + if calcC > (tsl + thresholdAmount) + bullMomentumBars := bullMomentumBars + 1 + bearMomentumBars := 0 + else + bullMomentumBars := 0 + // Flip only after X consecutive bars above threshold + trend := bullMomentumBars >= (confirmBars + 1) ? 1 : -1 supertrend = tsl