Skip to Content
Core WorkflowsRequirements & Code Generation

Requirements and code generation

Lona turns your conversation into structured rules, generates a Backtrader strategy, and validates the code.

Identified rules

The Canvas shows the current list in the collapsible Identified rules section. Each item contains:

  • A category: Strategy, Risk, Performance, Execution, or Custom
  • A concise description of the rule
  • Optional importance

The list represents the latest extraction. If something is missing or incorrect, continue the conversation and let Lona update the rules.

Choose a model

An available model is selected by default. You can choose another model from the chat input before sending your request:

  • GPT-5.6 Luna — default; fast responses and strong reasoning
  • GLM 5.3 Flash — fast open-source model
  • Sonnet 4.6 — balanced speed and quality
  • Opus 4.8 — advanced reasoning for complex tasks; available on Premium and Quant

Model availability can depend on your plan. For current details, see AI Model Selection.

The generation flow

When it has enough information, Lona automatically:

  1. Saves the current rules under Identified rules.
  2. Generates Python code for the Backtrader runtime.
  3. Explains the indicators, entries, exits, and parameters.
  4. Runs a dry-run validation and revises the code if needed.

The Canvas then provides Code, Run Backtest, and—when the strategy is ready—Optimize actions.

Generated code structure

Generated strategies follow Backtrader conventions. A simplified shape is:

class MovingAverageStrategy(bt.Strategy): params = ( ("fast_period", 10), ("slow_period", 30), ("order_size_pct", 0.10), ) def __init__(self): self.fast = {} self.slow = {} for data in self.datas: self.fast[data] = bt.indicators.SMA(data.close, period=self.p.fast_period) self.slow[data] = bt.indicators.SMA(data.close, period=self.p.slow_period) def next(self): for data in self.datas: if not self.getposition(data).size and self.fast[data][0] > self.slow[data][0]: self.buy(data=data) elif self.getposition(data).size and self.fast[data][0] < self.slow[data][0]: self.close(data=data)

The runtime provides the Backtrader environment. Generated code keeps indicators in __init__, evaluates rules in next(), and handles each selected data feed explicitly. The actual generated code may be more detailed than this example.

Parameters and simulation settings

Strategy parameters are values declared in the Backtrader params tuple, such as indicator periods, thresholds, and order_size_pct. They are exposed in the backtest dialog so you can change values without rewriting the rules.

Keep strategy parameters numeric or boolean when you want to configure or optimize them. Initial cash is not a strategy parameter: it belongs to the separate Simulation step, alongside commission, leverage, and Buy On Close.

Review and edit the code

Select Code in the Backtest Panel to open the strategy code and explanation. You can copy the code or edit it in the editor. If the behavior is wrong, updating the conversation and regenerating is usually easier to keep the rules and code aligned.

After editing or regenerating, use Run Backtest to validate the strategy against data. Use Optimize when you want to compare a grid of numeric parameter values instead of launching many manual runs; see Optimization best practices.

Versions and regeneration

When a saved strategy’s code or name changes, Lona creates a new strategy version. Earlier versions remain available in the strategy history, and each backtest report belongs to the version used for that run.

Troubleshooting

The rules are wrong. Continue the conversation with a precise correction, then regenerate.

The generated code is wrong. Ask Lona to revise the rule or code, or edit the code for an advanced change. Run a backtest after the change.

A parameter is not configurable. It may be a fixed implementation detail rather than a numeric or boolean strategy parameter. Ask Lona to expose it in params.

I cannot find the Canvas. Open the right-side Backtest Panel with the arrow control; its contents change with the current workflow step.

I need another framework. Lona currently generates strategies for Backtrader; framework selection is not a user configuration step.

Best practices

  • Review the identified rules and generated explanation before backtesting.
  • Use the default model for a first pass, then try another available model if the logic is complex.
  • Check parameter defaults and simulation settings before every run.
  • Keep the first strategy simple and add one rule at a time.
  • Read the explanation before editing implementation details.

Continue to Execution & Backtesting to configure a run.

Last updated on