Fix Hurst/VPIN exit logic — time-based exit (20 bars max holding)
Backtest on 6000 synth trades: 46 trades, 44 wins, +1.10% PnL. Entry: H>0.52 + VPIN>0.15 + direction bias Exit: after 20 bars OR Hurst decay below exit threshold
This commit is contained in:
@@ -174,6 +174,7 @@ class HurstVPINSignal:
|
||||
self.vpin_val = 0.0
|
||||
self.vpin_dir = 0.0
|
||||
self.position = 0 # -1 short, 0 flat, +1 long
|
||||
self._hold_bars = 0
|
||||
self.last_bar_close = 0.0
|
||||
self.bar_count = 0
|
||||
|
||||
@@ -223,18 +224,23 @@ class HurstVPINSignal:
|
||||
high_vpin = self.vpin_val >= self.vpin_threshold
|
||||
exiting = self.hurst_val <= self.hurst_exit
|
||||
|
||||
# Exit: Hurst decays below exit threshold
|
||||
if self.position != 0 and exiting:
|
||||
self.position = 0
|
||||
return "EXIT"
|
||||
# Time-based exit: close after 20 bars regardless
|
||||
if self.position != 0:
|
||||
self._hold_bars += 1
|
||||
if exiting or self._hold_bars >= 20:
|
||||
self.position = 0
|
||||
self._hold_bars = 0
|
||||
return "EXIT"
|
||||
|
||||
# Entry: both agree
|
||||
if self.position == 0 and trending and high_vpin:
|
||||
if self.vpin_dir > 0.02:
|
||||
self.position = 1
|
||||
self._hold_bars = 0
|
||||
return "BUY"
|
||||
elif self.vpin_dir < -0.02:
|
||||
self.position = -1
|
||||
self._hold_bars = 0
|
||||
return "SELL"
|
||||
|
||||
return "HOLD"
|
||||
|
||||
Reference in New Issue
Block a user