Skip to content
This repository was archived by the owner on Mar 27, 2026. It is now read-only.

Commit 8243ada

Browse files
feat: add trigger-happy paper strategy example
1 parent 3d99d86 commit 8243ada

4 files changed

Lines changed: 48 additions & 3 deletions

File tree

crates/palmscript/examples/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Checked-in `.ps` strategies live under `crates/palmscript/examples/strategies/`.
2727

2828
Representative files:
2929

30+
- `crates/palmscript/examples/strategies/paper_trigger_happy.ps`: high-churn Binance USD-M paper-trading example with market entries, short holding windows, and tight ATR-based stop/target orders to stress the paper execution path
3031
- `crates/palmscript/examples/strategies/adaptive_trend_backtest.ps`: adaptive multi-timeframe long-only backtest strategy with optimizer-tuned EMA, RSI, MACD, entry sizing, ATR target, and post-target stop-ratchet inputs around staged `entry1` / `entry2` and `target1` / `target2` order flow, including inline `input ... optimize(...)` metadata for durable CLI optimization
3132
- `crates/palmscript/examples/strategies/portfolio_caps_backtest.ps`: multi-alias portfolio backtest example using `portfolio_group`, position-count caps, and gross/net exposure caps under repeated `--execution-source` CLI selection
3233
- `crates/palmscript/examples/strategies/risk_controls_backtest.ps`: staged spot backtest example using declarative `cooldown` and `max_bars_in_trade` controls to gate same-side re-entry and time-box open trades
@@ -67,6 +68,7 @@ execution scripts that omit them.
6768
The same checked-in strategies can also be queued into the local paper daemon with `run paper`:
6869

6970
```bash
71+
./palmscript run paper crates/palmscript/examples/strategies/paper_trigger_happy.ps --maker-fee-bps 2 --taker-fee-bps 5
7072
./palmscript run paper crates/palmscript/examples/strategies/bybit_usdt_perps_backtest.ps --execution-source perp --maker-fee-bps 2 --taker-fee-bps 5
7173
./palmscript execution serve --once
7274
./palmscript run paper-export <session-id> --format json
2.57 KB
Binary file not shown.

crates/palmscript/tests/docs_examples.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fn bars(start_ms: i64, spacing_ms: i64, len: usize, start_close: f64) -> Vec<Bar
4545
#[test]
4646
fn referenced_docs_examples_compile() {
4747
let examples = [
48+
"examples/strategies/paper_trigger_happy.ps",
4849
"examples/strategies/adaptive_trend_backtest.ps",
4950
"examples/strategies/portfolio_caps_backtest.ps",
5051
"examples/strategies/sma_cross.ps",
@@ -328,6 +329,48 @@ fn explicit_order_backtest_docs_example_runs_with_local_feeds() {
328329
assert!(!result.equity_curve.is_empty(), "{path} should emit equity");
329330
}
330331

332+
#[test]
333+
fn paper_trigger_happy_example_runs_with_local_feeds() {
334+
let path = "examples/strategies/paper_trigger_happy.ps";
335+
let compiled = compile(&read_strategy(path)).expect("paper_trigger_happy should compile");
336+
let runtime = SourceRuntimeConfig {
337+
base_interval: palmscript::Interval::Min1,
338+
feeds: vec![SourceFeed {
339+
source_id: 0,
340+
interval: palmscript::Interval::Min1,
341+
bars: bars(JAN_1_2024_UTC_MS, MINUTE_MS, 240, 100.0),
342+
}],
343+
};
344+
345+
let outputs = run_with_sources(&compiled, runtime.clone(), VmLimits::default())
346+
.expect("paper_trigger_happy should run");
347+
assert!(!outputs.plots.is_empty(), "{path} should emit plots");
348+
349+
let result = run_backtest_with_sources(
350+
&compiled,
351+
runtime,
352+
VmLimits::default(),
353+
BacktestConfig {
354+
execution_source_alias: "exec".to_string(),
355+
portfolio_execution_aliases: Vec::new(),
356+
spot_virtual_rebalance: false,
357+
activation_time_ms: None,
358+
initial_capital: 10_000.0,
359+
maker_fee_bps: 0.0,
360+
taker_fee_bps: 0.0,
361+
execution_fee_schedules: std::collections::BTreeMap::new(),
362+
slippage_bps: 0.0,
363+
diagnostics_detail: DiagnosticsDetailMode::SummaryOnly,
364+
perp: None,
365+
perp_context: None,
366+
portfolio_perp_contexts: std::collections::BTreeMap::new(),
367+
},
368+
)
369+
.expect("paper_trigger_happy should backtest");
370+
assert!(!result.orders.is_empty(), "{path} should emit orders");
371+
assert!(!result.equity_curve.is_empty(), "{path} should emit equity");
372+
}
373+
331374
#[test]
332375
fn source_aware_docs_examples_run_with_local_feeds() {
333376
let spread = compile(&read_strategy("examples/strategies/cross_source_spread.ps"))

infra/docker/paper-sessions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ once = false
1111

1212
[[session]]
1313
enabled = true
14-
script = "strategy.ps"
14+
script = "paper_trigger_happy.ps"
1515

16-
# Current validated paper target from /mnt/4tbscratch/projects/palmscript-build-futures:
16+
# Default bundled paper smoke-test target:
1717
# - execution alias: exec
1818
# - symbol / segment: Binance USD-M BTCUSDT
19-
# - exact validation artifact: opt_probe_iter52_cooldown1_exact.json
19+
# - strategy goal: frequent fills plus tight stop/target churn
2020

2121
initial_capital = 10000.0
2222
maker_fee_bps = 2.0

0 commit comments

Comments
 (0)