trades not registering, but strategy is plotting
For a buy only and exit strategy, when I run the following code I am able to see the chart and data and the indicator. However it doesnt appear to run any trades. Is this because I need trade analyzers. I did this with a strategy before and it worked as designed. But when I changed the data to intraday it gave me loads of problems.
I end up with the following.
import backtrader as bt
from datetime import datetime
params = dict( pfast=10, pslow=30 ) def __init__(self): sma1 = bt.ind.SMA(period=self.p.pfast) sma2 = bt.ind.SMA(period=self.p.pslow) self.crossover = bt.ind.CrossOver(sma1, sma2) def next(self): if not self.position: if self.crossover > 0: self.buy() elif self.crossover < 0: self.close()
data = bt.feeds.GenericCSVData(
fromdate=datetime(2020, 1, 1),
todate=datetime(2021, 11, 4)
cerebro = bt.Cerebro()
ultra1971 last edited by
Pls include some data to check if you have enough cash to buy,
Try changing initial cash, set up a size in the buy function and define a notify_trade method (lot of examples just google) .
The crossover analyzer is working so if the buy fuction is executed then order is rejected for any reason.