Skip to content

feat: add SSL Channel (Securement Stop Loss Channel) (#119) - #210

Merged
jealous merged 1 commit into
jealous:masterfrom
huuan26:feat/add-ssl-channel
Oct 21, 2026
Merged

jealous merged 1 commit into
jealous:masterfrom
huuan26:feat/add-ssl-channel

Conversation

@huuan26

@huuan26 huuan26 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Resolves #119.

Summary

This PR adds support for SSL Channel (Securement Stop Loss Channel) as first-class indicator columns in StockDataFrame.

Features

  1. SSL Channel:

    • Implements Erwin Beckers' SSL Channel indicator.
    • Calculates dynamic support and resistance bands using SMA of High and Low prices and tracks the close price relative trend position:
      • sma_high = SMA(high, window)
      • sma_low = SMA(low, window)
      • hlv[i] = 1 if close[i] > sma_high[i] else (-1 if close[i] < sma_low[i] else hlv[i-1])
      • ssl_down = sma_high if hlv < 0 else sma_low
      • ssl_up = sma_low if hlv < 0 else sma_high
    • Exposes df['ssl'] (defaults to ssl_up), df['ssl_up'], df['ssl_down'].
    • Supports default window (10) and custom window (e.g., df['ssl_up_5'], df['ssl_down_5'], df['ssl_14']).
    • Supports crossover detection for buy/sell trading signals (e.g. df['ssl_up_xu_ssl_down'] for bullish crossover, df['ssl_up_xd_ssl_down'] for bearish crossunder).
    • Adds class method StockDataFrame.ssl_channel(high, low, close, window).
    • Handles edge cases cleanly (empty series, single row series, window bounds).
  2. Configuration & Handler:

    • Added "ssl": 10, "ssl_up": 10, "ssl_down": 10 to _dft_windows.
    • Registered ("ssl", "ssl_up", "ssl_down"): self._get_ssl in self.handler.

Verification & Documentation

  • Added unit tests in test.py:
    • test_ssl_channel: Verified against 30-day stock data benchmark, trend flipping verification (20110117), custom window evaluation (ssl_up_5), and crossunder detection (ssl_up_xd_ssl_down).
    • test_ssl_channel_edge_cases: Verified edge cases (empty series, single-element).
  • Updated README.md Summary table, Introduction list, and Trend section with formula and usage examples.
  • Code style: flake8 stockstats.py test.py passed with 0 errors.
  • Test suite: 137/137 tests passed (96% coverage).

@jealous
jealous merged commit 608dcea into jealous:master Oct 21, 2026
4 checks passed
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.

SSL Channel add

2 participants