Skip to content

fix: SuperTrend direction checks wrong band - #77

Merged
trsdn merged 1 commit into
mainfrom
fix/issue-75-supertrend-direction
Feb 13, 2026
Merged

fix: SuperTrend direction checks wrong band#77
trsdn merged 1 commit into
mainfrom
fix/issue-75-supertrend-direction

Conversation

@trsdn

@trsdn trsdn commented Feb 13, 2026

Copy link
Copy Markdown
Owner

Fixes #75

Root cause: Direction logic checked the opposite band — bullish checked close < upper (always true between bands), bearish checked close > lower (always true). Price between bands caused direction to flip every 1.1 bars.

Fix: Bullish checks close < lower_band (support broken), bearish checks close > upper_band (resistance broken). Matches TradingView's ta.supertrend behavior.

Metric Before After
Return -88% 1,906%
Trades 1,366 40
Sharpe -0.65 0.70
Max DD -91% -43%

8 lines changed. All 128 tests pass.

The direction logic checked the opposite band:
- Bullish checked close < upper_band (always true) → instant flip
- Bearish checked close > lower_band (always true) → instant flip back

Correct logic (matches TradingView ta.supertrend):
- Bullish: only flip bearish if close < LOWER band (support broken)
- Bearish: only flip bullish if close > UPPER band (resistance broken)

Before: -88% return, 1366 trades, -0.65 Sharpe (whipsaw)
After: 1906% return, 40 trades, 0.70 Sharpe (proper trend-following)

Fixes #75
@trsdn
trsdn merged commit e2273c3 into main Feb 13, 2026
2 checks passed
@trsdn
trsdn deleted the fix/issue-75-supertrend-direction branch February 13, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix SuperTrend: direction checks wrong band causing whipsaw

1 participant