TL;DR
The BTC 20/100 moving-average rule returned 49.78% in its 2024 backtest, with 42.03% maximum drawdown, while the plotted BTC holding comparison gained 119.27%. It enters with 95% of buying power when the shorter average is above the longer one and exits when that state ends. Crypto fills cost 0.7% of traded notional. Inspect the captured trades and holdings before testing a separate allocation change.
Completed 2024 backtest
- BTC 20/100 moving-average regime 2024-12-31, 21:00:00 UTC
- 14,977.73
- SPY buy and hold 2024-12-31, 21:00:00 UTC
- 12,530.29
- BTC buy and hold 2024-12-31, 21:00:00 UTC
- 21,926.92
Show the table · 11 rows, 2 columns
Scroll sideways to compare all columns. Select a heading to sort.
| Status | COMPLETE |
| Backtest return | 49.78% |
| Reported maximum drawdown | 42.03% |
| SPY buy-and-hold return | 25.30% |
| BTC buy-and-hold return | 119.27% |
| Total recorded trading fees | $585.80 |
| Engine closed-trade count | 9 |
| Starting capital | $10000.00 |
| Ending portfolio value | $14977.73 |
| Ending cash | $465.61 |
| Ending position value | $14512.11 |
No matching rows. Clear the filter to see all records.
This saved algorithm completed a Day backtest from 2024-01-01 through 2024-12-31, with $10000.00 starting capital. The chart includes all 744 exported history points.
Compare the strategy with SPY and BTC buy and hold. Each benchmark invests the full $10000.00 starting balance over the same 2024 period. SPY follows its trading sessions; BTC includes weekends. This algorithm follows its own allocation and entry/exit rules, with 0.7% of traded notional charged on each fill. Explore cash and position values to see how capital was deployed.
Follow the example
Read this pair's entry and exit
Read this pair’s entry condition, purchase amount and exit in the saved rules below.
- Entry
- Saved rule: SMA(20, Day) > SMA(100, Day) AND position value = 0
- Exit
- Saved rule: SMA(20, Day) <= SMA(100, Day) AND position value > 0
- Allocation
- Saved rule: 95% of buying power per entry; sell 100% of held units on exit
- Pair
- Saved rule: BTC-USD
The plain-language purpose matches the saved rules below. Keep the rule, purchase size and exit together when creating your version.
- BTC 20/100 moving-average regime 2024-12-31, 21:00:00 UTC
- 14,977.73
- SPY buy and hold 2024-12-31, 21:00:00 UTC
- 12,530.29
- BTC buy and hold 2024-12-31, 21:00:00 UTC
- 21,926.92
Completed 2024 backtest
Explore the completed 2024 simulation shown near the top. Compare its recorded return and drawdown with the plotted benchmarks, then follow the captured fills. The original history, fees and execution assumptions remain available.
The exact stored history shown here, with its source's period, comparisons and limits. Opening the walkthrough does not rerun it.
Preview this strategy in Aurora
Review the provided strategy request without changing its pair or sizing. Ask for a draft preview before any saved candidate or paid test.
An inspectable candidate. New dates or a changed rule define another experiment, not the published result.
Choose a step to follow the example. Opening a request lets you review it; it does not submit a job or change your account.
Inspect the recorded trades
Jan 01, 2024
PairBTC-USD
SideBuy
Units (rounded)0.22279509
Submitted price$42640.08
Filled price$42640.08
Fee$66.50
May 16, 2024
PairBTC-USD
SideSell
Units (rounded)0.22123552
Submitted price$66061.56
Filled price$66061.56
Fee$102.31
May 16, 2024
PairBTC-USD
SideSell
Units (rounded)0.00154865
Submitted price$65212.10
Filled price$65212.10
Fee$0.71
May 17, 2024
PairBTC-USD
SideSell
Units (rounded)0.00001092
Submitted price$66295.37
Filled price$66295.37
Fee$0.01
May 21, 2024
PairBTC-USD
SideBuy
Units (rounded)0.20171114
Submitted price$70868.63
Filled price$70868.63
Fee$100.06
Jun 26, 2024
PairBTC-USD
SideSell
Units (rounded)0.20029916
Submitted price$61482.27
Filled price$61482.27
Fee$86.20
Jun 26, 2024
PairBTC-USD
SideSell
Units (rounded)0.00140209
Submitted price$60969.03
Filled price$60969.03
Fee$0.60
Jun 27, 2024
PairBTC-USD
SideSell
Units (rounded)0.00000988
Submitted price$61576.05
Filled price$61576.05
Fee$0.00
Recorded rows in source order; spacing does not represent elapsed time.
Show the table · 8 rows, 7 columns
Scroll sideways to compare all columns. Select a heading to sort.
| Jan 01, 2024 | BTC-USD | Buy | 0.22279509 | $42640.08 | $42640.08 | $66.50 |
| May 16, 2024 | BTC-USD | Sell | 0.22123552 | $66061.56 | $66061.56 | $102.31 |
| May 16, 2024 | BTC-USD | Sell | 0.00154865 | $65212.10 | $65212.10 | $0.71 |
| May 17, 2024 | BTC-USD | Sell | 0.00001092 | $66295.37 | $66295.37 | $0.01 |
| May 21, 2024 | BTC-USD | Buy | 0.20171114 | $70868.63 | $70868.63 | $100.06 |
| Jun 26, 2024 | BTC-USD | Sell | 0.20029916 | $61482.27 | $61482.27 | $86.20 |
| Jun 26, 2024 | BTC-USD | Sell | 0.00140209 | $60969.03 | $60969.03 | $0.60 |
| Jun 27, 2024 | BTC-USD | Sell | 0.00000988 | $61576.05 | $61576.05 | $0.00 |
No matching rows. Clear the filter to see all records.
Follow the Filled events by pair, side and time. Compare the submitted price, filled price, fractional quantity and fee. This table shows up to eight orders from the captured excerpt (13 Filled events).
For a percentage fee, multiply the traded notional by 0.007. To follow a position, start with a purchase and inspect subsequent sale quantities, remaining holdings and cash flows. For the weekly accumulation example, follow each purchase and the resulting position value.
The algorithm
Entry
SMA(20, Day) > SMA(100, Day) AND position value = 0
Exit
SMA(20, Day) <= SMA(100, Day) AND position value > 0
Allocation
95% of buying power per entry; sell 100% of held units on exit
Pair
BTC-USD
Execution
Market; fractional units enabled
Starting capital
$10,000; no additional deposits
Show the table · 6 rows, 2 columns
| Decision | Saved rule |
|---|---|
| Entry | SMA(20, Day) > SMA(100, Day) AND position value = 0 |
| Exit | SMA(20, Day) <= SMA(100, Day) AND position value > 0 |
| Allocation | 95% of buying power per entry; sell 100% of held units on exit |
| Pair | BTC-USD |
| Execution | Market; fractional units enabled |
| Starting capital | $10,000; no additional deposits |
No matching rows. Clear the filter to see all records.
This example trades BTC-USD as a spot Cryptocurrency asset. The saved rules were read back and verified with automated trading off.
Create the same strategy
Ask Aurora to build the rules above, review the preview, then save the draft with automated trading off. Confirm the Cryptocurrency pair, allocation and entry and exit conditions in the saved rules.
In the native Strategies editor, use Buy and Sell actions with the same Cryptocurrency pair. Add the indicator and position-value conditions shown above. The weekly accumulation example uses a single Buy rule with a seven-day DaysSinceOrder condition.
Plan a separate variant and later test
Review the optional next experiment
After reviewing the recorded example, use the prepared request above for the original rules. This optional plan covers a separate variant and a later test.
Create one variant, then test unseen dates
Ask: "Change only the entry allocation from 95% to 75% of buying power. Show the rule diff and compare both candidates on the 2024 development period with every other setting fixed." After choosing, freeze the rules and select another test period you have not inspected. The displayed 2024 results already make 2024 a viewed development period. Keep any later revisions in a new research cycle.
Create and backtest with Python
Use the Python SDK instead of Aurora
Python SDK 1.42.0. Save the runner below as run_btc_moving_average_regime.py.
Install and download
python3 -m pip install nexustrade==1.42.0
export NEXUSTRADE_API_KEY="YOUR_API_KEY"
curl --fail --output btc_moving_average_regime.py https://nexustrade.io/seo/strategy-examples/btc-moving-average-regime.py
Create, test and inspect
from btc_moving_average_regime import create_btc_moving_average_regime, backtest_btc_moving_average_regime
book = create_btc_moving_average_regime()
completed = backtest_btc_moving_average_regime()
print(completed["result"])
Run
python3 run_btc_moving_average_regime.py
Python strategy and backtest functions
View complete Python SDK functions
The backtest function submits the 2024 test with SPY as its benchmark, records events and waits for the result. Use a new request key when changing rules, dates or fees.
import nexustrade as nt
def create_btc_moving_average_regime():
asset = nt.crypto_asset("BTC-USD")
return nt.portfolio(
"Public SEO crypto example - BTC 20/100 moving-average regime",
[
nt.strategy(
"Enter BTC 20/100 moving-average regime",
((nt.SMA(asset, 20, "Day") > nt.SMA(asset, 100, "Day")) & (nt.PositionValue(asset) == nt.Value(0))),
nt.buy(asset, 95, "percent of buying power")
),
nt.strategy(
"Exit BTC 20/100 moving-average regime",
((nt.SMA(asset, 20, "Day") <= nt.SMA(asset, 100, "Day")) & (nt.PositionValue(asset) > nt.Value(0))),
nt.sell(asset, 100, "percent of current positions")
),
],
initial_value=10000,
supports_crypto=True,
supports_fractional_shares=True,
alerts_enabled=False,
dividend_policy='cash',
)
def backtest_btc_moving_average_regime(client=None):
client = client or nt.NexusTradeClient.from_environment()
operation = client.create_backtest(
nt.backtest(
create_btc_moving_average_regime(),
start_date="2024-01-01", end_date="2024-12-31",
interval="Day", baseline_symbol="SPY",
initial_value=10000, generate_events=True,
dividend_policy="cash",
fee_config={"Stock": {"type": "percent", "amount": 0.1},
"Cryptocurrency": {"type": "percent", "amount": 0.7},
"Option": {"type": "dollars", "amount": 0.65}},
),
idempotency_key="explore-btc-moving-average-regime-2024-spy-v1",
)
return client.wait_for_backtest(operation["id"])
# Build locally: book = create_btc_moving_average_regime()
# Run and inspect: completed = backtest_btc_moving_average_regime(); print(completed["result"])
Create and backtest with TypeScript
Use the TypeScript SDK instead of Aurora
TypeScript SDK 1.42.0. Save the runner below as run-btc-moving-average-regime.ts.
Install and download
npm install nexustrade@1.42.0
npm install --save-dev tsx
export NEXUSTRADE_API_KEY="YOUR_API_KEY"
curl --fail --output btc-moving-average-regime.ts https://nexustrade.io/seo/strategy-examples/btc-moving-average-regime.ts
Create, test and inspect
import { createBtcMovingAverageRegime, backtestBtcMovingAverageRegime } from "./btc-moving-average-regime";
async function main() {
const book = createBtcMovingAverageRegime();
const completed = await backtestBtcMovingAverageRegime();
console.log(completed.result);
}
main().catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
});
Run
npx tsx run-btc-moving-average-regime.ts
TypeScript strategy and backtest functions
View complete TypeScript SDK functions
The same rules, dates and fees are used in both SDKs. The backtest function keeps its request key across retries.
import * as nt from "nexustrade";
export function createBtcMovingAverageRegime() {
const asset = nt.cryptoAsset("BTC-USD");
return nt.portfolio(
"Public SEO crypto example - BTC 20/100 moving-average regime",
[
nt.strategy(
"Enter BTC 20/100 moving-average regime",
nt.and(
nt.gt(nt.SMA(asset, 20, "Day"), nt.SMA(asset, 100, "Day")),
nt.eq(nt.PositionValue(asset), nt.Value(0))
),
nt.buy(asset, 95, "percent of buying power")
),
nt.strategy(
"Exit BTC 20/100 moving-average regime",
nt.and(
nt.lte(nt.SMA(asset, 20, "Day"), nt.SMA(asset, 100, "Day")),
nt.gt(nt.PositionValue(asset), nt.Value(0))
),
nt.sell(asset, 100, "percent of current positions")
),
],
{ initialValue: 10000, supportsCrypto: true, supportsFractionalShares: true, alertsEnabled: false, dividendPolicy: "cash" }
);
}
export async function backtestBtcMovingAverageRegime(client = new nt.NexusTradeClient()) {
const operation = await client.createBacktest(
nt.backtest(createBtcMovingAverageRegime(), {
startDate: "2024-01-01", endDate: "2024-12-31",
interval: "Day", baselineSymbol: "SPY",
initialValue: 10000, generateEvents: true,
dividendPolicy: "cash",
feeConfig: {
Stock: { type: "percent", amount: 0.1 },
Cryptocurrency: { type: "percent", amount: 0.7 },
Option: { type: "dollars", amount: 0.65 },
},
}),
{ idempotencyKey: "explore-btc-moving-average-regime-2024-spy-v1" }
);
if (typeof operation.id !== "string") throw new Error("Missing backtest ID");
return client.waitForBacktest(operation.id);
}
// Build locally: const book = createBtcMovingAverageRegime();
// Run and inspect: const completed = await backtestBtcMovingAverageRegime(); console.log(completed.result);
Understand this entry with Aurora
BTC-USD 20 day SMA > BTC-USD 100 day SMA
Left value61,182.8456>Right value61,059.0783ResultTrueBTC-USD position value = constant
Left value0=Right value0ResultTrue
Show the table · 2 rows, 5 columns
Scroll sideways to compare all columns. Select a heading to sort.
| BTC-USD 20 day SMA > BTC-USD 100 day SMA | 61,182.8456 | > | 61,059.0783 | True |
| BTC-USD position value = constant | 0 | = | 0 | True |
No matching rows. Clear the filter to see all records.
At 2024-09-28T20:00:00.000Z, the recorded rule was: 20 Day BTC-USD SMA > 100 Day BTC-USD SMA and Position market value (BTC-USD) = Constant 0. Its overall result was true. Read the individual comparisons below, then ask Aurora to explain how they led to the action.
The signal requested 95 percent of buying power at a submitted price of 65,739.4609. 1 captured Filled order shares this timestamp; Aurora receives those fields with the signal.
Inspect the original signal record
View captured signal JSON
{
"eventType": "BuySignal",
"event": {
"eventType": "BuySignal",
"timestamp": "2024-09-28T20:00:00.000Z",
"signals": [
{
"conditionName": "20 Day BTC-USD SMA > 100 Day BTC-USD SMA and Position market value (BTC-USD) = Constant 0",
"audit": {
"type": "minimal",
"results": {
"0.0": {
"isTrue": true,
"lhsValue": 61182.84560546875,
"rhsValue": 61059.078262405776,
"lhsError": null,
"rhsError": null,
"comparison": "greaterThan"
},
"0.1": {
"isTrue": true,
"lhsValue": 0,
"rhsValue": 0,
"lhsError": null,
"rhsError": null,
"comparison": "equal"
}
},
"failuresOnly": false
},
"isTrue": true,
"actionName": "Buy",
"actionMetadata": {
"buyOrSell": {
"targetAsset": {
"name": "BTC-USD",
"symbol": "BTC-USD",
"type": "Cryptocurrency",
"underlyingSymbol": null,
"optionType": null,
"expirationDate": null,
"strikePrice": null,
"multiplier": null
},
"allocation": {
"type": "percent of buying power",
"amount": 95
},
"price": 65739.4609375,
"orderType": "Market Order"
}
},
"orderExecution": {
"type": "Market"
}
}
]
},
"timestamp": 1727553600000
}Explore a drawdown period
Show the table · 2 rows, 4 columns
Scroll sideways to compare all columns. Select a heading to sort.
| 2024-03-13T20:00:00.000Z | $16787.29 | $433.50 | $16353.79 |
| 2024-10-10T20:00:00.000Z | $9731.83 | $465.61 | $9266.21 |
No matching rows. Clear the filter to see all records.
Follow the decline from Mar 13, 2024 to Oct 10, 2024. The table retains the recorded portfolio, cash and position values. The engine reported maximum drawdown of 42.03%.
Test another version
Change one rule or choose a different date range, then compare the resulting curve and trade events with this saved experiment. Explore which trades, fees and periods explain the difference.
Exact captured fill fields
2024-01-01T14:30:00.000Z
PairBTC-USD
SideBuy
Units0.22279508898062086
Submitted price$42640.08
Filled price$42640.08
Fee$66.50
2024-05-16T13:30:00.000Z
PairBTC-USD
SideSell
Units0.22123552335775656
Submitted price$66061.56
Filled price$66061.56
Fee$102.31
2024-05-16T20:00:00.000Z
PairBTC-USD
SideSell
Units0.0015486486635042506
Submitted price$65212.10
Filled price$65212.10
Fee$0.71
2024-05-17T13:30:00.000Z
PairBTC-USD
SideSell
Units0.000010916959360050089
Submitted price$66295.37
Filled price$66295.37
Fee$0.01
2024-05-21T13:30:00.000Z
PairBTC-USD
SideBuy
Units0.20171113769008428
Submitted price$70868.63
Filled price$70868.63
Fee$100.06
2024-06-26T13:30:00.000Z
PairBTC-USD
SideSell
Units0.20029915972625367
Submitted price$61482.27
Filled price$61482.27
Fee$86.20
2024-06-26T20:00:00.000Z
PairBTC-USD
SideSell
Units0.0014020941180837934
Submitted price$60969.03
Filled price$60969.03
Fee$0.60
2024-06-27T13:30:00.000Z
PairBTC-USD
SideSell
Units0.000009883845746813972
Submitted price$61576.05
Filled price$61576.05
Fee$0.00
Recorded rows in source order; spacing does not represent elapsed time.
Inspect full UTC times and exact fractional quantities
Scroll sideways to compare all columns. Select a heading to sort.
| 2024-01-01T14:30:00.000Z | BTC-USD | Buy | 0.22279508898062086 | $42640.08 | $42640.08 | $66.50 |
| 2024-05-16T13:30:00.000Z | BTC-USD | Sell | 0.22123552335775656 | $66061.56 | $66061.56 | $102.31 |
| 2024-05-16T20:00:00.000Z | BTC-USD | Sell | 0.0015486486635042506 | $65212.10 | $65212.10 | $0.71 |
| 2024-05-17T13:30:00.000Z | BTC-USD | Sell | 0.000010916959360050089 | $66295.37 | $66295.37 | $0.01 |
| 2024-05-21T13:30:00.000Z | BTC-USD | Buy | 0.20171113769008428 | $70868.63 | $70868.63 | $100.06 |
| 2024-06-26T13:30:00.000Z | BTC-USD | Sell | 0.20029915972625367 | $61482.27 | $61482.27 | $86.20 |
| 2024-06-26T20:00:00.000Z | BTC-USD | Sell | 0.0014020941180837934 | $60969.03 | $60969.03 | $0.60 |
| 2024-06-27T13:30:00.000Z | BTC-USD | Sell | 0.000009883845746813972 | $61576.05 | $61576.05 | $0.00 |
No matching rows. Clear the filter to see all records.
Exact drawdown measurement
Read the exact snapshot timestamps and measurement comparison
The largest decline between exported snapshots was 42.03%, from $16787.29 at 2024-03-13T20:00:00.000Z to $9731.83 at 2024-10-10T20:00:00.000Z. The reported maximum drawdown is 42.03%. Explore the trades and holdings around those dates.
No comments yet.