Simple Moving-Average Crossover
This example is a simple daily moving-average crossover strategy on BTC/USDT.
Two moving averages, fast and slow, are defined with three possible types: sma, ema, and wma. That creates 9 candidate type pairs. The constraint fast.type = slow.type keeps only the 3 coherent grids where both averages use the same type: sma/sma, ema/ema, and wma/wma.
Within each grid, fast.length and slow.length range from 2 to 50. The constraint fast.length < slow.length keeps only the pairs where the fast average remains shorter than the slow average, yielding 1,176 valid combinations per grid (49 × 48 / 2 = 1,176).
In total, this example runs 3,528 backtests, and results are ranked by Sortino ratio.
# Illustrative example only, do not use for live trading. Public domain (CC0 1.0).
# Backtest configuration
[backtest]
symbol = ["BINANCE:BTCUSDT"]
timeframe = ["D"]
start_date = 2024-01-01
end_date = 2026-01-01
initial_capital = 1000
# 95% keeps position size below 1x to avoid an immediate 1x margin call
# caused by trading fees and the gap between signal and execution price.
default_qty_value = 95
# Ranks results by Sortino ratio.
[[objective]]
id = "sortino"
formula = "sortino_ratio"
ascending = false
# Enable detailed trade output in the results.
[logging]
include_trades = true
timestamp_enabled = false
# Fast moving average, tests sma, ema, and wma with lengths from 2 to 50.
[[moving_average]]
id = "fast"
type = ["sma", "ema", "wma"]
length.start = 2
length.stop = 50
# Slow moving average, tests sma, ema, and wma with lengths from 2 to 50.
[[moving_average]]
id = "slow"
type = ["sma", "ema", "wma"]
length.start = 2
length.stop = 50
# Hyperparameter constraint:
# Fast must stay shorter than slow, and both averages must use the same type.
[constraints]
condition = "fast.length < slow.length and fast.type = slow.type"
# Entry point of the state machine: the strategy starts at the bullish crossover block.
[start]
id = "origin"
next_block_id = "golden_cross"
# Wait for the fast average to cross above the slow average.
# When it happens, the strategy moves to the long entry block.
[[crossover]]
id = "golden_cross"
reference = "fast"
comparison = "slow"
next_block_id = "open_position"
# Open the long position, then switch to the bearish crossover watcher.
[[entry]]
id = "open_position"
order_id = "main"
next_block_id = "death_cross"
# Once open, close the position when the fast average crosses below the slow one.
[[crossunder]]
id = "death_cross"
reference = "fast"
comparison = "slow"
next_block_id = "close_position"
# Close the position and return to the bullish crossover watcher.
[[close]]
id = "close_position"
order_id = "main"
next_block_id = "golden_cross"Console output
The first lines correspond to the analysis phase before backtests start. The message “Detected 9 grids in the strategy” comes from combining the three moving-average types tested for fast and slow, which produces 9 possible grids. The fast.type = slow.type constraint then keeps only the cases where both blocks use the same type. That leaves 3 valid grids, each with 1,176 length pairs.
The [Run 1/3] to [Run 3/3] lines correspond to the three jobs launched to explore the three valid grids. Each job uses all CPU cores assigned to the software. If some cores become available during execution, a new grid can start before the previous one has finished. Exploring each grid takes less than 10 milliseconds.
Results are ranked by Sortino ratio because this strategy explicitly defines that objective. The line starting with Result 1 identifies the best result in the explored search space. The G1C2196 code is the identifier for that result: G1 refers to the grid, and C2196 to the combination number within the hyperparameter search space. This is the code to use with the --export-pinescript option when exporting that combination to Pine Script.
The Grid Parameters table shows the selected type grid, here fast.type = sma and slow.type = sma. The Hyperparameters table then gives the winning lengths: fast.length = 42 and slow.length = 46. The rest of the output shows the detailed result of that backtest.
If you export this combination to Pine Script and enough history is available on TradingView, you get the same result on BINANCE:BTCUSDT spot, except for certain Whale‑E-specific metrics.
[info]
[info] ================================================================
[info] Whale Engine 1.0.1044
[info] Backtesting & Strategy Optimization Software
[info] (c) 2025 Almageste - https://Whale-E.com
[info] ================================================================
[info] Strategy : C:\Whale-E_Project\dragon\doc\examples\simple-crossover.toml
[info] Using 31 threads for parallel computation.
[info] Using database cache directory: C:\Users\Tony\AppData\Local\Almageste\Whale-E
[info] Detected 9 grids in the strategy.
[info] Analyzing hyperparameter grids.
[info] Grid 1/9 has 1 176 valid combinations out of 2 401 total combinations.
[info] Grid 5/9 has 1 176 valid combinations out of 2 401 total combinations.
[info] Grid 9/9 has 1 176 valid combinations out of 2 401 total combinations.
[info] Skipped 6 grids because they have no valid combinations.
[info] Hyperparameter grid analysis completed in 1 ms.
[info] Starting exploration of 3 grids.
[info] [Run 1/3] Grid 1 BINANCE:BTCUSDT (D): Price series ready.
[info] [Run 1/3] Grid 1 BINANCE:BTCUSDT (D): Exploring 1 176 valid combinations (fast.type="sma"; slow.type="sma").
[info] [Run 2/3] Grid 5 BINANCE:BTCUSDT (D): Price series ready.
[info] [Run 2/3] Grid 5 BINANCE:BTCUSDT (D): Exploring 1 176 valid combinations (fast.type="ema"; slow.type="ema").
[info] [Run 1/3] Grid 1 BINANCE:BTCUSDT (D): Completed in 7 ms with 1 176 backtests, 22 228 positions, and 123.0M candles/s.
[info] [Run 3/3] Grid 9 BINANCE:BTCUSDT (D): Price series ready.
[info] [Run 2/3] Grid 5 BINANCE:BTCUSDT (D): Completed in 6 ms with 1 176 backtests, 13 335 positions, and 143.5M candles/s.
[info] [Run 3/3] Grid 9 BINANCE:BTCUSDT (D): Exploring 1 176 valid combinations (fast.type="wma"; slow.type="wma").
[info] [Run 3/3] Grid 9 BINANCE:BTCUSDT (D): Completed in 6 ms with 1 176 backtests, 20 305 positions, and 143.5M candles/s.
[info] Completed 3 528 backtests in total.
[info]
[info] +======================================================================+
[info] | OBJECTIVE RANKING |
[info] | Name: sortino |
[info] | Sort order: descending |
[info] +======================================================================+
[info]
[info] ========================================================================
[info] Result 1 | score 2.458143085209 | G1C2196 | BINANCE:BTCUSDT | D
[info] ========================================================================
[info]
[info] Backtest Settings
[info] ------------------------------------------------------
[info] Strategy | simple-crossover
[info] Timezone | UTC
[info] Price history start date |
[info] Backtest start | 2024-01-01 00:00:00
[info] Backtest end | 2026-01-01 23:59:59
[info] Initial capital | 1000.00 USDT
[info] Quantity type | percent_of_equity
[info] Default quantity value | 95.00 %
[info] Long size multiplier | x1.00
[info] Short size multiplier | x1.00
[info] Pyramiding | 1
[info] Long margin | 100.00 %
[info] Short margin | 100.00 %
[info] Process orders on close | No
[info] Bar Magnifier | No
[info] Close open position at end | Yes
[info] Close entries rule | fifo
[info] Backtest fill limits assumption | 0
[info] Automatic slippage | No
[info] Automatic slippage ratio | 0.000000
[info] Slippage | 0
[info] Commission type | percent
[info] Commission value | 0.100000 %
[info] ------------------------------------------------------
[info]
[info] Grid Parameters
[info] ----------------
[info] fast.type | sma
[info] slow.type | sma
[info] ----------------
[info]
[info] Hyperparameters
[info] -----------------
[info] fast.length | 42
[info] slow.length | 46
[info] -----------------
[info]
[info] Overview
[info] --------------------------------------------------------------------------------
[info] Total P&L | Max equity drawdown | Trades | Profitable trades | Profit factor
[info] --------------------------------------------------------------------------------
[info] 1493.25 USDT | 562.64 USDT | 21 | 61.90 % | 2.536
[info] 149.33 % | 21.30 % | | 13/21 |
[info] --------------------------------------------------------------------------------
[info]
[info] Performance
[info] --------------------------------------------------------------
[info] Metric | All | Long | Short
[info] --------------------------------------------------------------
[info] Open P&L | 0.00 USDT | |
[info] | 0.00 % | |
[info] --------------------------------------------------------------
[info] Net profit | 1493.25 USDT | 1493.25 USDT | 0.00 USDT
[info] | 149.33 % | 149.33 % | 0.00 %
[info] --------------------------------------------------------------
[info] Gross profit | 2465.32 USDT | 2465.32 USDT | 0.00 USDT
[info] | 246.53 % | 246.53 % | 0.00 %
[info] --------------------------------------------------------------
[info] Gross loss | 972.07 USDT | 972.07 USDT | 0.00 USDT
[info] | 97.21 % | 97.21 % | 0.00 %
[info] --------------------------------------------------------------
[info] Commission paid | 74.42 USDT | 74.42 USDT | 0.00 USDT
[info] --------------------------------------------------------------
[info] Buy & hold return | 1010.86 USDT | |
[info] | 101.09 % | |
[info] --------------------------------------------------------------
[info] Max equity run-up | 1890.85 USDT | |
[info] | 65.43 % | |
[info] --------------------------------------------------------------
[info] Max equity drawdown | 562.64 USDT | |
[info] | 21.30 % | |
[info] --------------------------------------------------------------
[info]
[info] Trade Analysis
[info] ----------------------------------------------------------------------
[info] Metric | All | Long | Short
[info] ----------------------------------------------------------------------
[info] Total trades | 21 | 21 | 0
[info] ----------------------------------------------------------------------
[info] Total open trades | 0 | |
[info] ----------------------------------------------------------------------
[info] Winning trades | 13 | 13 | 0
[info] ----------------------------------------------------------------------
[info] Losing trades | 8 | 8 | 0
[info] ----------------------------------------------------------------------
[info] Percent profitable | 61.90 % | 61.90 % | 0.00 %
[info] ----------------------------------------------------------------------
[info] Avg P&L | 71.11 USDT | 71.11 USDT | 0.00 USDT
[info] | 5.65 % | 5.65 % | 0.00 %
[info] ----------------------------------------------------------------------
[info] Avg winning trade | 189.64 USDT | 189.64 USDT | 0.00 USDT
[info] | 12.73 % | 12.73 % | 0.00 %
[info] ----------------------------------------------------------------------
[info] Avg losing trade | 121.51 USDT | 121.51 USDT | 0.00 USDT
[info] | 5.86 % | 5.86 % | 0.00 %
[info] ----------------------------------------------------------------------
[info] Largest winning trade | 967.04 USDT | 967.04 USDT | 0.00 USDT
[info] ----------------------------------------------------------------------
[info] Largest winning trade percent | 62.73 % | 62.73 % | 0.00 %
[info] ----------------------------------------------------------------------
[info] Largest losing trade | 286.97 USDT | 286.97 USDT | 0.00 USDT
[info] ----------------------------------------------------------------------
[info] Largest losing trade percent | 12.01 % | 12.01 % | 0.00 %
[info] ----------------------------------------------------------------------
[info]
[info] Risk and Performance Ratios
[info] ---------------------------------------------
[info] Metric | All | Long | Short
[info] ---------------------------------------------
[info] Sharpe ratio | 1.493 | |
[info] ---------------------------------------------
[info] Sortino ratio | 2.458 | |
[info] ---------------------------------------------
[info] Calmar ratio | 2.709 | |
[info] ---------------------------------------------
[info] Profit factor | 2.536 | |
[info] ---------------------------------------------
[info] Market Exposure | 59.02 % | 59.02 % | 0.00 %
[info] ---------------------------------------------
[info] Margin call | 0 | 0 | 0
[info] ---------------------------------------------
[info]
[info] Trade List
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] Trade # | Type | Date | Signal | Price | Qty | P&L | Run-up | Drawdown | Cumulative P&L
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 21 Long | Exit | 2025-11-12 00:00:00 | main | 103059.00 USDT | 2372.42 USDT | 34.73 USDT | 139.33 USDT | -50.33 USDT | 1493.25 USDT
[info] | | | | | | 1.49 % | 5.97 % | -2.16 % | 149.33 %
[info] | Entry | 2025-11-07 00:00:00 | main | 101346.04 USDT | 2332.99 USDT | | | |
[info] | | | | | 0.02302 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 20 Long | Exit | 2025-10-26 00:00:00 | main | 111646.27 USDT | 2326.71 USDT | -206.73 USDT | 57.16 USDT | -405.43 USDT | 1458.53 USDT
[info] | | | | | | -8.17 % | 2.26 % | -16.02 % | 145.85 %
[info] | Entry | 2025-10-08 00:00:00 | main | 121332.96 USDT | 2528.58 USDT | | | |
[info] | | | | | 0.02084 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 19 Long | Exit | 2025-09-18 00:00:00 | main | 116447.60 USDT | 2535.06 USDT | 20.64 USDT | 41.44 USDT | -21.75 USDT | 1665.25 USDT
[info] | | | | | | 0.82 % | 1.65 % | -0.87 % | 166.53 %
[info] | Entry | 2025-09-15 00:00:00 | main | 115268.01 USDT | 2509.38 USDT | | | |
[info] | | | | | 0.02177 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 18 Long | Exit | 2025-08-25 00:00:00 | main | 113493.59 USDT | 2509.34 USDT | -94.30 USDT | 150.99 USDT | -154.00 USDT | 1644.62 USDT
[info] | | | | | | -3.63 % | 5.80 % | -5.92 % | 164.46 %
[info] | Entry | 2025-07-12 00:00:00 | main | 117527.66 USDT | 2598.54 USDT | | | |
[info] | | | | | 0.02211 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 17 Long | Exit | 2025-07-03 00:00:00 | main | 108849.59 USDT | 2629.81 USDT | 510.67 USDT | 588.93 USDT | -12.75 USDT | 1738.92 USDT
[info] | | | | | | 24.13 % | 27.83 % | -0.60 % | 173.89 %
[info] | Entry | 2025-04-22 00:00:00 | main | 87516.22 USDT | 2114.39 USDT | | | |
[info] | | | | | 0.02416 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 16 Long | Exit | 2025-03-01 00:00:00 | main | 84349.95 USDT | 2104.53 USDT | -286.97 USDT | 92.50 USDT | -436.85 USDT | 1228.25 USDT
[info] | | | | | | -12.01 % | 3.87 % | -18.28 % | 122.82 %
[info] | Entry | 2025-02-19 00:00:00 | main | 95671.74 USDT | 2387.01 USDT | | | |
[info] | | | | | 0.02495 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 15 Long | Exit | 2025-02-18 00:00:00 | main | 95780.01 USDT | 2384.92 USDT | -125.80 USDT | 43.92 USDT | -236.68 USDT | 1515.22 USDT
[info] | | | | | | -5.02 % | 1.75 % | -9.44 % | 151.52 %
[info] | Entry | 2025-02-02 00:00:00 | main | 100635.66 USDT | 2505.83 USDT | | | |
[info] | | | | | 0.02490 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 14 Long | Exit | 2025-01-19 00:00:00 | main | 104556.23 USDT | 2513.53 USDT | 50.82 USDT | 84.80 USDT | -314.47 USDT | 1641.02 USDT
[info] | | | | | | 2.07 % | 3.45 % | -12.78 % | 164.10 %
[info] | Entry | 2025-01-07 00:00:00 | main | 102235.60 USDT | 2457.74 USDT | | | |
[info] | | | | | 0.02404 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 13 Long | Exit | 2025-01-06 00:00:00 | main | 98363.61 USDT | 2511.22 USDT | 967.04 USDT | 1224.58 USDT | -7.64 USDT | 1590.20 USDT
[info] | | | | | | 62.73 % | 79.43 % | -0.50 % | 159.02 %
[info] | Entry | 2024-10-11 00:00:00 | main | 60326.40 USDT | 1540.13 USDT | | | |
[info] | | | | | 0.02553 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 12 Long | Exit | 2024-10-05 00:00:00 | main | 62086.00 USDT | 1541.60 USDT | -29.58 USDT | 81.51 USDT | -84.10 USDT | 623.16 USDT
[info] | | | | | | -1.88 % | 5.19 % | -5.36 % | 62.32 %
[info] | Entry | 2024-09-26 00:00:00 | main | 63152.01 USDT | 1568.06 USDT | | | |
[info] | | | | | 0.02483 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 11 Long | Exit | 2024-09-22 00:00:00 | main | 63348.97 USDT | 1577.39 USDT | 124.83 USDT | 145.94 USDT | -16.49 USDT | 652.74 USDT
[info] | | | | | | 8.60 % | 10.06 % | -1.14 % | 65.27 %
[info] | Entry | 2024-09-17 00:00:00 | main | 58213.99 USDT | 1449.53 USDT | | | |
[info] | | | | | 0.02490 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 10 Long | Exit | 2024-08-28 00:00:00 | main | 59415.00 USDT | 1455.07 USDT | 43.03 USDT | 181.26 USDT | -12.24 USDT | 527.91 USDT
[info] | | | | | | 3.05 % | 12.85 % | -0.87 % | 52.79 %
[info] | Entry | 2024-08-16 00:00:00 | main | 57541.05 USDT | 1409.18 USDT | | | |
[info] | | | | | 0.02449 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 9 Long | Exit | 2024-08-14 00:00:00 | main | 60587.16 USDT | 1417.74 USDT | 124.90 USDT | 176.82 USDT | -10.74 USDT | 484.88 USDT
[info] | | | | | | 9.67 % | 13.69 % | -0.83 % | 48.49 %
[info] | Entry | 2024-08-08 00:00:00 | main | 55133.76 USDT | 1290.13 USDT | | | |
[info] | | | | | 0.02340 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 8 Long | Exit | 2024-07-02 00:00:00 | main | 62900.00 USDT | 1284.42 USDT | -164.03 USDT | 23.02 USDT | -254.59 USDT | 359.97 USDT
[info] | | | | | | -11.33 % | 1.59 % | -17.59 % | 36.00 %
[info] | Entry | 2024-06-07 00:00:00 | main | 70799.06 USDT | 1445.72 USDT | | | |
[info] | | | | | 0.02042 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 7 Long | Exit | 2024-06-05 00:00:00 | main | 70537.83 USDT | 1450.96 USDT | 41.15 USDT | 53.41 USDT | -36.96 USDT | 524.00 USDT
[info] | | | | | | 2.92 % | 3.79 % | -2.62 % | 52.40 %
[info] | Entry | 2024-05-29 00:00:00 | main | 68398.40 USDT | 1406.96 USDT | | | |
[info] | | | | | 0.02057 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 6 Long | Exit | 2024-05-07 00:00:00 | main | 63165.18 USDT | 1414.27 USDT | 89.16 USDT | 142.86 USDT | -6.90 USDT | 482.85 USDT
[info] | | | | | | 6.74 % | 10.79 % | -0.52 % | 48.29 %
[info] | Entry | 2024-05-03 00:00:00 | main | 59060.60 USDT | 1322.37 USDT | | | |
[info] | | | | | 0.02239 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 5 Long | Exit | 2024-05-02 00:00:00 | main | 58364.97 USDT | 1322.55 USDT | -54.97 USDT | 2.47 USDT | -94.72 USDT | 393.69 USDT
[info] | | | | | | -3.99 % | 0.18 % | -6.88 % | 39.37 %
[info] | Entry | 2024-05-01 00:00:00 | main | 60672.01 USDT | 1374.83 USDT | | | |
[info] | | | | | 0.02266 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 4 Long | Exit | 2024-04-22 00:00:00 | main | 64941.15 USDT | 1391.69 USDT | 284.09 USDT | 474.83 USDT | -15.39 USDT | 448.66 USDT
[info] | | | | | | 25.68 % | 42.92 % | -1.39 % | 44.87 %
[info] | Entry | 2024-02-25 00:00:00 | main | 51568.21 USDT | 1105.11 USDT | | | |
[info] | | | | | 0.02143 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 3 Long | Exit | 2024-02-20 00:00:00 | main | 51774.74 USDT | 1106.94 USDT | -9.69 USDT | 6.68 USDT | -33.17 USDT | 164.58 USDT
[info] | | | | | | -0.87 % | 0.60 % | -2.97 % | 16.46 %
[info] | Entry | 2024-02-17 00:00:00 | main | 52124.10 USDT | 1114.41 USDT | | | |
[info] | | | | | 0.02138 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 2 Long | Exit | 2024-02-16 00:00:00 | main | 51880.01 USDT | 1121.65 USDT | 100.49 USDT | 121.87 USDT | -8.21 USDT | 174.27 USDT
[info] | | | | | | 9.85 % | 11.95 % | -0.81 % | 17.43 %
[info] | Entry | 2024-02-10 00:00:00 | main | 47132.78 USDT | 1019.01 USDT | | | |
[info] | | | | | 0.02162 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------
[info] 1 Long | Exit | 2024-02-02 00:00:00 | main | 43082.95 USDT | 1024.51 USDT | 73.77 USDT | 93.81 USDT | -10.78 USDT | 73.77 USDT
[info] | | | | | | 7.77 % | 9.88 % | -1.14 % | 7.38 %
[info] | Entry | 2024-01-24 00:00:00 | main | 39897.59 USDT | 948.76 USDT | | | |
[info] | | | | | 0.02378 | | | |
[info] ---------------------------------------------------------------------------------------------------------------------------------------------