feat: add triple-Supertrend consensus flip as strategy family 7
Adds awareness of the multi-Supertrend any_of flip pattern (based on the reference strategy at swym/assets/reference/supertrend-triple.json, itself a DSL port of the popular TradingView triple-Supertrend script). - prompts.rs: add strategy family 7 (Supertrend consensus flip) with guidance on any_of vs all_of, period/multiplier tuning, and the always-in-market / reverse-as-stop-loss trade-off - prompts.rs: add risk management exception for always-in-market flip strategies (reverse: true means the opposite signal is the stop) - prompts.rs: add Example 7 — correctly gated 2-rule triple-Supertrend flip with position state guards to prevent unintended scale-ins Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -163,6 +163,13 @@ Use higher timeframes as trend filters, lower timeframes for entry precision.
|
||||
6. **Composite / hybrid**: Combine families. Trend filter + mean-reversion entry.
|
||||
Momentum confirmation + volatility sizing.
|
||||
|
||||
7. **Supertrend consensus flip (futures only)**: Use `any_of` across multiple
|
||||
Supertrend configs (e.g. period=7/mul=1.5, period=10/mul=2.0, period=20/mul=3.0)
|
||||
so that ANY flip triggers a long or short entry. Combine with `"reverse": true`
|
||||
for an always-in-market approach where the opposite signal is the stop-loss.
|
||||
Varying multiplier tightens/loosens the band; varying period controls sensitivity.
|
||||
Risk: choppy markets generate many whipsaws — best on daily or 4h.
|
||||
|
||||
## Risk management (always include)
|
||||
|
||||
Every strategy MUST have:
|
||||
@@ -170,6 +177,10 @@ Every strategy MUST have:
|
||||
- A time-based exit: use bars_since_entry to avoid holding losers indefinitely
|
||||
- Reasonable position sizing: prefer ATR-based or percent-of-balance over fixed quantity
|
||||
|
||||
Exception: always-in-market flip strategies (using `"reverse": true`) do not need an
|
||||
explicit stop-loss or time exit — the opposite signal acts as the stop. These are
|
||||
only valid on futures. See Example 6 and Example 7.
|
||||
|
||||
{output_instructions}
|
||||
|
||||
## Interpreting backtest results
|
||||
@@ -626,7 +637,76 @@ Key flip-strategy notes:
|
||||
- Gate each rule on `flat OR opposite` (using `any_of`) so it fires both on initial entry and on flip
|
||||
- `reverse: true` handles the flip math automatically — no need to size for `position_qty + new_qty`
|
||||
- This pattern works best for trend-following where you want continuous market exposure
|
||||
- Still add a time-based or ATR stop if you want a safety exit when the trend stalls"##;
|
||||
- Still add a time-based or ATR stop if you want a safety exit when the trend stalls
|
||||
|
||||
### Example 7 — Futures triple-Supertrend consensus flip
|
||||
|
||||
Multiple Supertrend instances with different period/multiplier combos act as a tiered
|
||||
signal. `any_of` fires on the FIRST flip — the fastest line (7/1.5) reacts quickly,
|
||||
the slowest (20/3.0) confirms strong trends. `reverse: true` makes it always-in-market:
|
||||
the opposite signal is the stop-loss. No explicit stop or time exit needed.
|
||||
|
||||
Varying parameters to tune:
|
||||
- Tighter multipliers (1.0–2.0) → more signals, more whipsaws
|
||||
- Looser multipliers (2.5–4.0) → fewer signals, longer holds
|
||||
- Try `all_of` instead of `any_of` to require consensus across all three (stronger filter)
|
||||
|
||||
```json
|
||||
{{
|
||||
"type": "rule_based",
|
||||
"candle_interval": "4h",
|
||||
"rules": [
|
||||
{{
|
||||
"comment": "LONG (or flip short→long): any Supertrend flips bullish",
|
||||
"when": {{
|
||||
"kind": "all_of",
|
||||
"conditions": [
|
||||
{{"kind": "any_of", "conditions": [
|
||||
{{"kind": "position", "state": "flat"}},
|
||||
{{"kind": "position", "state": "short"}}
|
||||
]}},
|
||||
{{
|
||||
"kind": "any_of",
|
||||
"conditions": [
|
||||
{{"kind": "cross_over", "left": {{"kind": "field", "field": "close"}}, "right": {{"kind": "func", "name": "supertrend", "period": 7, "multiplier": "1.5"}}}},
|
||||
{{"kind": "cross_over", "left": {{"kind": "field", "field": "close"}}, "right": {{"kind": "func", "name": "supertrend", "period": 10, "multiplier": "2.0"}}}},
|
||||
{{"kind": "cross_over", "left": {{"kind": "field", "field": "close"}}, "right": {{"kind": "func", "name": "supertrend", "period": 20, "multiplier": "3.0"}}}}
|
||||
]
|
||||
}}
|
||||
]
|
||||
}},
|
||||
"then": {{"side": "buy", "quantity": {{"method": "percent_of_balance", "percent": "5", "asset": "usdc"}}, "reverse": true}}
|
||||
}},
|
||||
{{
|
||||
"comment": "SHORT (or flip long→short): any Supertrend flips bearish",
|
||||
"when": {{
|
||||
"kind": "all_of",
|
||||
"conditions": [
|
||||
{{"kind": "any_of", "conditions": [
|
||||
{{"kind": "position", "state": "flat"}},
|
||||
{{"kind": "position", "state": "long"}}
|
||||
]}},
|
||||
{{
|
||||
"kind": "any_of",
|
||||
"conditions": [
|
||||
{{"kind": "cross_under", "left": {{"kind": "field", "field": "close"}}, "right": {{"kind": "func", "name": "supertrend", "period": 7, "multiplier": "1.5"}}}},
|
||||
{{"kind": "cross_under", "left": {{"kind": "field", "field": "close"}}, "right": {{"kind": "func", "name": "supertrend", "period": 10, "multiplier": "2.0"}}}},
|
||||
{{"kind": "cross_under", "left": {{"kind": "field", "field": "close"}}, "right": {{"kind": "func", "name": "supertrend", "period": 20, "multiplier": "3.0"}}}}
|
||||
]
|
||||
}}
|
||||
]
|
||||
}},
|
||||
"then": {{"side": "sell", "quantity": {{"method": "percent_of_balance", "percent": "5", "asset": "usdc"}}, "reverse": true}}
|
||||
}}
|
||||
]
|
||||
}}
|
||||
```
|
||||
|
||||
Key Supertrend-specific notes:
|
||||
- `supertrend` ignores `field` — it uses OHLC internally; omit the `field` param
|
||||
- `multiplier` controls band width: lower = tighter, more reactive; higher = wider, more stable
|
||||
- `any_of` → first flip triggers (responsive); `all_of` → all three must agree (conservative)
|
||||
- Gate on position state to prevent re-entries scaling into an existing position"##;
|
||||
|
||||
/// Build the user message for the first iteration (no prior results).
|
||||
/// `prior_summary` contains a formatted summary of results from previous runs, if any.
|
||||
|
||||
Reference in New Issue
Block a user