feat: Add momentum confirmation to v8 - filter rapid flip-flops
V8 improvements to handle small bounces in strong trends: - Increased flip threshold: 0.5% → 0.8% (stronger move required) - Added confirmBars: 2 bars required after threshold breach - Momentum tracking: Counts consecutive bars in new direction - Anti-whipsaw: Flip only after 3 consecutive bars (confirmBars+1) beyond threshold Example: In downtrend, price must close >0.8% above line for 3 bars before flipping bullish This filters 1-2 bar bounces that don't change the macro trend Result: Far fewer false reversals during strong directional moves
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user