Hi,
Could anyone help me?
I dont know which Buy and Sell price I am getting. Wheather on actuel closing bar or next closing price.
Please take a quick look on my code.
I have backtested since months with following logic.
if not self.position:
# Not yet ... we MIGHT BUY if ...
if self.bcross == 1.0:
# BUY, BUY, BUY!!! (with default parameters)
price = self.data.close
self.log("BUY CREATE, {}".format(price))
# Keep track of the created order to avoid a 2nd order
self.order = self.buy(
exectype=bt.Order.Limit,
price=price)
else:
# Already in the market ... we might sell
if self.scross == -1.0:
# SELL, SELL, SELL!!! (with all possible default parameters)
price = self.data.close
self.log("SELL CREATE, {}".format(price))
# Keep track of the created order to avoid a 2nd order
self.order = self.sell(
exectype=bt.Order.Limit,
price=price)
As you can see I used price = self.data.close instead self.data.close[0]
My log function is this and unfortunatly it was off.
def log(self, txt, dt=None):
dt = dt or self.data.datetime[0]
if debug:
print("{}, {}".format(bt.num2date(dt), txt))
I got good and bad end results and they all were reproduceable! plotting, sharpratio, vwr, sqn, Analyzer everything was working well.
my datafeed is
symbol = 'BTC/USDT'
# 2018-10-24T14:10:00Z - 2018-10-24T17:50:00Z
# 2018-10-24T23:00:00Z - 2018-10-25T01:45:00Z
hist_start_date = datetime.utcnow() - timedelta(days=500)
hist_stop_date = datetime.utcnow() - timedelta(hours=1)
data = bt.feeds.CCXT(exchange='binance',
symbol=symbol,
timeframe=bt.TimeFrame.Minutes,
fromdate=hist_start_date,
todate=hist_stop_date,
compression=60)
Today I debug and came to know that something is going wrong and got these results

@backtrader How could I go live, if I tested my strategies with self.data.close ? Is buy price, "buy at closing price of next bar" ?
Sell = "selling at closing price of next bar"?
Or did I backtested something unrealistic and I have to make new strategies with self.data.close[0] ?
Thanks for helping.