feat: Implement HTS (Higher Timeframe Trend System) strategy

- Add HTS strategy engine with crossover and alignment-based entries
- Implement Auto HTS feature (computes on TF/4 from 1m data)
- Add 1H Red Zone filter to validate long signals
- Add channel-based stop loss with RTL functionality
- Enhanced visualization with 30% opacity channel lines
- Fixed data alignment in simulation (uses htsData instead of mismatched indices)
- Fixed syntax errors in hts-engine.js (malformed template literals)
- Fixed duplicate code in simulation.js
- Added showSimulationMarkers to window object for global access
- Enhanced logging for trade signals and simulation results
- Fix missing prevFastHigh/currFastHigh in hts-visualizer.js
- Disable trend zone overlays to prevent chart clutter
- Implement client-side visualization for trade markers using line series
- MA strategy indicator configuration fixed (was empty during engine run)
- Made entry conditions more permissive for shorter timeframes
- Added comprehensive error handling and console logging
This commit is contained in:
DiTus
2026-02-27 09:30:43 +01:00
parent 286975b01a
commit e457ce3e20
9 changed files with 1080 additions and 100 deletions

79
HTS_STRATEGY.md Normal file
View File

@ -0,0 +1,79 @@
# HTS (Higher Timeframe Trend System) Strategy
A trend-following strategy based on channel breakouts using fast and slow moving averages of High/Low prices.
## Strategy Rules
### 1. Core Trend Signal
- **Bullish Trend**: Price trading above the Red (Slow) Channel and Aqua (Fast) Channel is above Red Channel
- **Bearish Trend**: Price trading below the Red (Slow) Channel and Aqua (Fast) Channel is below Red Channel
### 2. Entry Rules
- **Long Entry**: Wait for price to break above Slow Red Channel. Candle close above shorth (Fast Low line) while fast lines are above slow lines.
- **Short Entry**: Wait for price to break below Slow Red Channel. Look for close below shortl (Fast Low line) while fast lines are below slow lines.
### 3. 1H Red Zone Filter
- Only take Longs if the price is above the 1H Red Zone (Slow Channel), regardless of fast line direction
- Can be disabled in configuration
### 4. Stop Loss & Trailing Stop
- **Stop Loss**: Place on opposite side of Red (Slow) Channel
- Long stop: longl (Slow Low) line
- Short stop: slowh (Slow High) line
- **Trailing Stop**: As Red Channel moves, move stop loss accordingly
### 5. RMA Default
- Uses RMA (Running Moving Average) by default - slower and smoother than EMA
- Designed for long-term trends, late to react to sudden crashes (feature, not bug)
## Configuration Parameters
| Parameter | Default | Range | Description |
|-----------|---------|-------|-------------|
| `shortPeriod` | 33 | 5-200 | Fast period for HTS |
| `longPeriod` | 144 | 10-500 | Slow period for HTS |
| `maType` | RMA | - | Moving average type (RMA/SMA/EMA/WMA/VWMA) |
| `useAutoHTS` | false | - | Compute HTS on timeframe/4 from 1m data |
| `use1HFilter` | true | - | Enable 1H Red Zone filter |
## Usage
1. Select "HTS Trend Strategy" from the strategies dropdown
2. Configure parameters:
- Periods: typically 33/144 for 15min-1hour charts
- Enable Auto HTS for multi-timeframe analysis
- Enable/disable 1H filter as needed
3. Run simulation to see backtesting results
4. View entry/exit markers on the chart
## Visualization
- **Cyan Lines**: Fast channels (33-period)
- **Red Lines**: Slow channels (144-period)
- **Green Arrows**: Buy signals (fast low crossover)
- **Red Arrows**: Sell signals (fast high crossover)
- **Background Shading**: Trend zones (green=bullish, red=bearish)
## Signal Strength
Pure HTS signals don't mix with other indicators. Signals are based solely on:
- Crossover detection
- Channel alignment
- Price position relative to channels
- Higher timeframe confirmation (1H filter if enabled)
## Example Setup
For a 15-minute chart:
- Fast Period: 33
- Slow Period: 144
- MA Type: RMA (default)
- Auto HTS: Disabled (or enable to see HTS on ~4-minute perspective)
- 1H Filter: Enabled (for better trade filtering)
## Notes
- This strategy is designed for trend-following, not ranging markets
- RMA is slower than EMA, giving smoother signals but later entries
- 1H filter significantly reduces false signals for long trades
- Works best in volatile but trending assets like BTC