Strategies ReferenceΒΆ

Reference for the built-in strategies

MA_CrossOver

Alias:
  • SMA_CrossOver

This is a long-only strategy which operates on a moving average cross

Note:
  • Although the default
Buy Logic:
  • No position is open on the data
  • The fast moving averagecrosses over the slow strategy to the upside.
Sell Logic:
  • A position exists on the data
  • The fast moving average crosses over the slow strategy to the downside
Order Execution Type:
  • Market
Lines:
  • datetime
Params:
  • fast (10)
  • slow (30)
  • _movav (<class ‘backtrader.indicators.sma.SMA’>)

SignalStrategy

This subclass of Strategy is meant to to auto-operate using signals.

Signals are usually indicators and the expected output values:

  • > 0 is a long indication
  • < 0 is a short indication

There are 5 types of Signals, broken in 2 groups.

Main Group:

  • LONGSHORT: both long and short indications from this signal are taken

  • LONG: - long indications are taken to go long - short indications are taken to close the long position. But:

    • If a LONGEXIT (see below) signal is in the system it will be used to exit the long
    • If a SHORT signal is available and no LONGEXIT is available , it will be used to close a long before opening a short
  • SHORT: - short indications are taken to go short - long indications are taken to close the short position. But:

    • If a SHORTEXIT (see below) signal is in the system it will be used to exit the short
    • If a LONG signal is available and no SHORTEXIT is available , it will be used to close a short before opening a long

Exit Group:

This 2 signals are meant to override others and provide criteria for exitins a long/short position

  • LONGEXIT: short indications are taken to exit long positions
  • SHORTEXIT: long indications are taken to exit short positions

Order Issuing

Orders execution type is Market and validity is None (Good until Canceled)

Params:

  • signals (default: []): a list/tuple of lists/tuples that allows the instantiation of the signals and allocation to the right type

    This parameter is expected to be managed through cerebro.add_signal

  • _accumulate (default: False): allow to enter the market (long/short) even if already in the market

  • _concurrent (default: False): allow orders to be issued even if orders are already pending execution

  • _data (default: None): if multiple datas are present in the system which is the target for orders. This can be

    • None: The first data in the system will be used
    • An int: indicating the data that was inserted at that position
    • An str: name given to the data when creating it (parameter name) or when adding it cerebro with cerebro.adddata(..., name=)
    • A data instance
Lines:
  • datetime
Params:
  • signals ([])
  • _accumulate (False)
  • _concurrent (False)
  • _data (None)