self.initialize

strategies.strategy.Strategy.initialize(self, parameters=None)

Initialize the strategy. Use this lifecycle method to initialize parameters.

This method is called once before the first time the strategy is run.

Returns

Return type

None

Example

>>> # Initialize the strategy
>>> def initialize(self):
>>>   self.sleeptime = 5
>>>   self.ticker = "AAPL"
>>>   self.minutes_before_closing = 5
>>>   self.max_bars = 100
>>> # Initialize the strategy
>>> def initialize(self):
>>>   # Set the strategy to call on_trading_interation every 5 seconds
>>>   self.sleeptime = "2S"
>>>   self.count = 0
>>> # Initialize the strategy
>>> def initialize(self):
>>>   # Set the strategy to call on_trading_interation every 10 minutes
>>>   self.sleeptime = "10M"
>>>   self.count = 0
>>> # Initialize the strategy
>>> def initialize(self):
>>>   # Set the strategy to call on_trading_interation every 20 hours
>>>   self.sleeptime = "20H"
>>>   self.count = 0
>>> # Initialize the strategy
>>> def initialize(self):
>>>   # Set the strategy to call on_trading_interation every 2 days (48 hours)
>>>   self.sleeptime = "2D"
>>>   self.count = 0