Follow the example
Choose a step to follow the example. Opening a request lets you review it; it does not submit a job or change your account.
Write rules the builder can test
A strategy needs more than a name such as long call. Specify when to open, which contracts qualify, how much capital to use and when to close. The long call and bull call spread walkthroughs use SPY, a price above its 50-day average, a $1,000 premium budget and two exit rules. Other strategies declare their own signals and sizing. These choices define an educational test, not a recommendation.
- Entry
- Example rule: SPY price > SMA(50, Day) and zero matching long calls · What to verify: An existing matching position prevents another opening.
- Contracts
- Example rule: ATM call; nearest expiry between 30 and 45 DTE · What to verify: Actual symbol, strike and expiry chosen on each signal.
- Allocation
- Example rule: $1,000 dollars from $10,000 starting capital · What to verify: Whole-contract quantity, debit, commissions and buying power.
- Trend exit
- Example rule: SPY price <= SMA(50, Day) · What to verify: Close all matching SPY spreads, not just one leg.
A named field or event to inspect, rather than a generic options preset.
Build a reviewable draft with Aurora
Review the saved draft in Aurora. Confirm all three rules, spread type, contract selectors and allocation. The $1,000 budget determines how many whole contracts fit; ratio 1 specifies the leg proportions. After running the test, follow contract-resolution and Filled-order events to inspect the actual contracts and quantities.
An explained difference between intended selector, resolved contract, sent size and simulated fill.
Inspect or preview deliberately
Open the contextual request with your actual returned backtest identifier when required. Review the request before sending; do not rerun simply because a result is disappointing.
A bounded review of the requested task, without automatic deployment or broker orders.
Write rules the builder can test
A strategy needs more than a name such as long call. Specify when to open, which contracts qualify, how much capital to use and when to close. The long call and bull call spread walkthroughs use SPY, a price above its 50-day average, a $1,000 premium budget and two exit rules. Other strategies declare their own signals and sizing. These choices define an educational test, not a recommendation.
Scroll sideways to compare all columns. Select a heading to sort.
| Entry | SPY price > SMA(50, Day) and zero matching long calls | An existing matching position prevents another opening. |
| Contracts | ATM call; nearest expiry between 30 and 45 DTE | Actual symbol, strike and expiry chosen on each signal. |
| Allocation | $1,000 dollars from $10,000 starting capital | Whole-contract quantity, debit, commissions and buying power. |
| Trend exit | SPY price <= SMA(50, Day) | Close all matching SPY spreads, not just one leg. |
| Time exit | 14 or fewer days to expiration | A separate close rule with maxDte 14. |
No matching rows. Clear the filter to see all records.
Build a reviewable draft with Aurora
Review the saved draft in Aurora. Confirm all three rules, spread type, contract selectors and allocation. The $1,000 budget determines how many whole contracts fit; ratio 1 specifies the leg proportions. After running the test, follow contract-resolution and Filled-order events to inspect the actual contracts and quantities.
Create an undeployed research draft named SPY long call with $10,000 initial value. Underlying SPY. Open a custom long call only when Price(SPY) > SMA(SPY,50,Day) AND matching long call custom OptionPositionCount equals zero. Allocate $1,000 dollars. Buy an at-the-money (ATM) call, ratio 1, nearest expiration 30 to 45 days away. Close all matching SPY custom spreads when Price(SPY) <= SMA(SPY,50,Day). Add a separate close-all matching-spread rule with maxDte 14. Review the draft, correct any validation issues, save it and show its exact saved rules and identifier. Keep automated trading off. Stop after saving.Check the same inputs in the native editor
For a paper portfolio, open Strategies, choose Open Options Position and the Long Call or Bull Call Spread preset. Set Underlying Asset, each leg's strike distance, Min DTE, Max DTE, expiration preference and Allocation. Add conditions and both Close Options Position rules separately. The preset supplies legs; it does not supply the whole strategy.
A chat draft and a native paper portfolio use different routes. In Portfolio, choose Drafts to inspect a chat draft or open it in Aurora. The native Strategies editor belongs to a paper or live portfolio. Keep the authoring example inactive and separate from other matching SPY positions, since close-all rules may close those too.
Compare your draft with tested examples
The strategy guides include exact authoring configurations, saved rule inputs and completed historical backtests. The long call and bull call spread also show the Python authoring example. Use those records to compare your own draft before submitting a test.
Create, test and iterate in Aurora
Start this worked example in the NexusTrade app. Review the filled-in request, open it in Aurora, then send it when ready. Continue in the same conversation through these steps.
Create the exact strategy
Ask: "Review Long call. Entry: SPY price > SMA(50, Day) AND zero matching long-call positions; $1,000 premium budget. Exit: Close all matching spreads when SPY price <= SMA50 or at 14 or fewer DTE. Show the resolved rules and selectors before saving." The request includes this example's complete draft.
Run the 2024 development comparison
Ask: "Backtest the saved rules from January 1 through December 31, 2024, daily, starting with $10,000. Keep the displayed fees and capture detailed events." Compare the completed curve with SPY buy and hold.
Explain what happened
Ask: "Explain one entry signal and its Filled orders using the recorded indicator values, comparisons, allocation, prices, quantity and fees. Then follow the largest drawdown through trades, cash and holdings."
Create one variant, then test unseen dates
Ask: "Change only the timed close trigger from 14 DTE to 10 DTE. 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
Python SDK 1.42.0. Save the runner below as run_long_call.py.
Install and download
python3 -m pip install nexustrade==1.42.0
export NEXUSTRADE_API_KEY="YOUR_API_KEY"
curl --fail --output long_call.py https://nexustrade.io/seo/strategy-examples/long-call.py
Create, test and inspect
from long_call import create_long_call, backtest_long_call
book = create_long_call()
completed = backtest_long_call()
print(completed["result"])
Run
python3 run_long_call.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_long_call():
asset = nt.stock_asset("SPY")
return nt.portfolio(
"Public SEO example - Long call",
[
nt.strategy(
"Open Long call",
((nt.Price(asset) > nt.SMA(asset, 50, "Day")) & (nt.OptionPositionCount("SPY", "call", "long", "custom") == nt.Value(0))),
nt.open_option(
builder=nt.options_builder(
legs=[nt.leg(option_type="call", direction="long", min_days_to_expiration=30, max_days_to_expiration=45, preference="nearest", distance=0, ratio=1)],
underlying_symbol="SPY",
spread_type="custom"
),
allocation={'type': 'dollars', 'amount': 1000}
)
),
nt.strategy(
"Close when trend breaks",
(nt.Price(asset) <= nt.SMA(asset, 50, "Day")),
nt.close_option(
underlyings=['SPY'],
spread_type="custom",
close_scope="spread",
quantity={'type': 'all'}
)
),
nt.strategy(
"Close at 14 DTE",
(nt.Value(1) > nt.Value(0)),
nt.close_option(
underlyings=['SPY'],
spread_type="custom",
close_scope="spread",
quantity={'type': 'all'},
triggers=[nt.dte_trigger(max_dte=14)]
)
),
],
initial_value=10000,
alerts_enabled=False,
)
def backtest_long_call(client=None):
client = client or nt.NexusTradeClient.from_environment()
operation = client.create_backtest(
nt.backtest(
create_long_call(),
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-long-call-2024-spy-v1",
)
return client.wait_for_backtest(operation["id"])
# Build locally: book = create_long_call()
# Run and inspect: completed = backtest_long_call(); print(completed["result"])
Create and backtest with TypeScript
TypeScript SDK 1.42.0. Save the runner below as run-long-call.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 long-call.ts https://nexustrade.io/seo/strategy-examples/long-call.ts
Create, test and inspect
import { createLongCall, backtestLongCall } from "./long-call";
async function main() {
const book = createLongCall();
const completed = await backtestLongCall();
console.log(completed.result);
}
main().catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
});
Run
npx tsx run-long-call.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 createLongCall() {
const asset = nt.stockAsset("SPY");
return nt.portfolio(
"Public SEO example - Long call",
[
nt.strategy(
"Open Long call",
nt.and(
nt.gt(nt.Price(asset), nt.SMA(asset, 50, "Day")),
nt.eq(nt.OptionPositionCount("SPY", "call", "long", "custom"), nt.Value(0))
),
nt.openOption({ builder: nt.optionsBuilder({ legs: [nt.leg({ optionType: "call", direction: "long", minDaysToExpiration: 30, maxDaysToExpiration: 45, preference: "nearest", distance: 0, ratio: 1 })], underlyingSymbol: "SPY", spreadType: "custom" }), allocation: {"type": "dollars", "amount": 1000} })
),
nt.strategy(
"Close when trend breaks",
nt.lte(nt.Price(asset), nt.SMA(asset, 50, "Day")),
nt.closeOption({ underlyings: ["SPY"], spreadType: "custom", closeScope: "spread", quantity: {"type": "all"} })
),
nt.strategy(
"Close at 14 DTE",
nt.gt(nt.Value(1), nt.Value(0)),
nt.closeOption({ underlyings: ["SPY"], spreadType: "custom", closeScope: "spread", quantity: {"type": "all"}, triggers: [nt.dteTrigger({ maxDte: 14 })] })
),
],
{ initialValue: 10000, alertsEnabled: false }
);
}
export async function backtestLongCall(client = new nt.NexusTradeClient()) {
const operation = await client.createBacktest(
nt.backtest(createLongCall(), {
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-long-call-2024-spy-v1" }
);
if (typeof operation.id !== "string") throw new Error("Missing backtest ID");
return client.waitForBacktest(operation.id);
}
// Build locally: const book = createLongCall();
// Run and inspect: const completed = await backtestLongCall(); console.log(completed.result);