backtrader.linebuffer.LineBuffer object at
-
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.
-
@abyaby said in backtrader.linebuffer.LineBuffer object at:
I dont know which Buy and Sell price I am getting
Neither do we.
@abyaby said in backtrader.linebuffer.LineBuffer object at:
As you can see I used price = self.data.close instead self.data.close[0]
I guess you already realized that's wrong.
@abyaby said in backtrader.linebuffer.LineBuffer object at:
How could I go live, if I tested my strategies with self.data.close ?
If could means you already did ... I hope you had luck.
If could means you plan to ... I would do proper backtesting.
@abyaby said in backtrader.linebuffer.LineBuffer object at:
Is buy price, "buy at closing price of next bar" ?
Sell = "selling at closing price of next bar"?Your orders are
Limit
and your data is unknown ... my guess is as good as any other as to what you got. -
@backtrader Thanks a lot of your fast and brief answer.
-
@backtrader Thanks that you mentioned the Limit Order. I thought, it doesnt matter, if I add
cerebro.broker.setcommission(commission=0.002)
Regarding unkown data
I have backtest self.data.close and self.data.close[0] again.PnL with Limit order are different
PnL with Market order are the same. What could it mean? I was especting data.close with market order a random number but surprisingly its the same.
data.close[0] vs. data.close
order.market -478.3 order.market -478.3
order.limit -634.26 order.limit 2370.7And if some one know why data.close and data.close[0] have defferent limit order PnL ?