Lona Create Strategy
lona_create_strategyFull Description
Use this when the user has existing Backtrader Python code to upload as a new strategy.
Prefer lona_create_strategy_from_description if the user wants to create a strategy from a description instead of uploading existing code.
Requirements for the code:
- Must import backtrader:
import backtrader as bt - Must define a class inheriting from
bt.Strategy - Parameters use tuple format:
params = (('name', value), ...) - Initialize indicators in
__init__, trading logic innext()
Example:
import backtrader as bt
class Strategy(bt.Strategy):
params = (('period', 20),)
def __init__(self):
self.sma = bt.indicators.SMA(period=self.p.period)
def next(self):
if self.data.close[0] > self.sma[0]:
self.buy()Parameters (2 required, 2 optional)
codestringPython Backtrader strategy code (must inherit from bt.Strategy)
namestringName of the strategy
descriptionstringDescription of what the strategy does
versionstringVersion string (e.g., "1.0.0")