策略参考#
内置策略的参考
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
fastmoving averagecrosses over theslowstrategy to the upside.
- Sell Logic:
A position exists on the data
The
fastmoving average crosses over theslowstrategy 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:
> 0is alongindication
< 0is ashortindication
There are 5 types of Signals, broken in 2 groups.
Main Group:
LONGSHORT: bothlongandshortindications from this signal are taken
LONG: -longindications are taken to go long -shortindications 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 longIf a
SHORTsignal is available and noLONGEXITis available , it will be used to close alongbefore opening ashort
SHORT: -shortindications are taken to go short -longindications 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 shortIf a
LONGsignal is available and noSHORTEXITis available , it will be used to close ashortbefore opening along
Exit Group:
This 2 signals are meant to override others and provide criteria for exitins a
long/shortposition
LONGEXIT:shortindications are taken to exitlongpositions
SHORTEXIT:longindications are taken to exitshortpositions
Order Issuing
Orders execution type is
Marketand validity isNone(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 usedAn
int: indicating the data that was inserted at that positionAn
str: name given to the data when creating it (parametername) or when adding it cerebro withcerebro.adddata(..., name=)A
datainstance
- Lines:
datetime
- Params:
signals ([])
_accumulate (False)
_concurrent (False)
_data (None)