# Code Generation - AI-Powered Strategy Creation

**Last Updated**: 2026-03-17
**Version**: 1.0.0

## How It Works

### Define Strategy Logic in the Builder

Use the Arena workflow builder to specify your trading conditions and execution steps. The visual configuration serves as the input specification for AI code generation.

### Select AI Model for Generation

Choose which AI model provider will generate your strategy code. Different models may produce varying code styles and optimization approaches based on their training.

### Submit for Code Generation

Click the Generate Code button to send your strategy parameters to the AI engine. The system translates your visual workflow into a structured prompt for the selected model.

### Monitor Generation Progress

Watch the real-time progress indicator as the AI processes your strategy. Complex multi-condition strategies with multiple indicators may take longer to generate.

### Review Generated Python Code

Examine the generated Python code in the syntax-highlighted code viewer. The code follows Backtrader framework conventions and includes comments explaining each strategy component.

### Execute or Iterate on the Code

Run the generated code directly through the backtest engine to validate its performance, or modify the workflow conditions and regenerate to explore different strategy variations.

> Code Generation converts your visual strategy configurations into executable Python code using AI models for backtesting and analysis

## Tips & Best Practices

- Define clear and specific strategy conditions in the workflow builder before generating code — vague configurations lead to generic or overly broad trading logic

- Always review the generated code line by line to verify that entry signals, exit conditions, and position sizing match your intended strategy before running a backtest

- Try generating code with different AI models for the same strategy to compare approaches — each model may implement indicators or exit logic differently

## Frequently Asked Questions

### What programming language and framework does the generated code use?

All generated code is Python using the Backtrader framework. This is the standard framework used by the platform's backtest engine, ensuring seamless execution without any additional setup or library installation.

### Can I manually edit the generated code before execution?

Yes, the generated code is fully editable in the code viewer. You can modify indicator parameters, adjust entry/exit logic, add custom conditions, or refactor the structure. Any manual edits are preserved until you regenerate from the workflow builder.

### How many credits does code generation consume?

Code generation credit cost depends on the AI model selected and the complexity of your strategy. GPT-4 and Claude models typically consume more credits than lighter models. Check your credits balance on the Billing page before generating.

## Important Notes

> AI-generated code should be thoroughly reviewed and backtested before any live trading application. The AI may produce code with logical errors or suboptimal implementations. Past backtest performance does not guarantee future results.

---

Source: https://stratcraft.ai/help/code-generation/