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 along
indication -
< 0
is ashort
indication
There are 5 types of Signals, broken in 2 groups.
Main Group:
-
LONGSHORT
: bothlong
andshort
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 noLONGEXIT
is available , it will be used to close along
before opening ashort
-
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 noSHORTEXIT
is available , it will be used to close ashort
before opening along
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 exitlong
positions -
SHORTEXIT
:long
indications are taken to exitshort
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 typeThis 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 (parametername
) or when adding it cerebro withcerebro.adddata(..., name=)
-
A
data
instance
-
Lines:
* datetime
Params:
* signals ([])
* _accumulate (False)
* _concurrent (False)
* _data (None)