happydasch / btplotting

btplotting provides plotting for backtests, optimization results and live data from backtrader.
GNU General Public License v3.0
338 stars 84 forks source link

The last candle is missing #48

Closed helloboy110 closed 5 months ago

helloboy110 commented 1 year ago

The last candle is missing

happydasch commented 1 year ago

can you provide more details?

helloboy110 commented 1 year ago

run demos/blackly_single.py image image bokeh plot: image

happydasch commented 1 year ago

The last candle is not complete so it will not be generated. Will look into changing this behaviour.

zgpnuaa commented 1 year ago

+1. The first candlestick is not displayed, and the time of all other candlesticks is reduced by one period (1 minute) when timeframe is 1min. My code as follow:

feed = SimpleLivingData(exchange=exchange, symbol=symbol, timeframe=bt.TimeFrame.Minutes, compression=1, backfill_start=True, backfill_from=data_start)

cerebro.adddata(feed, name=symbol)
cerebro.addanalyzer(BacktraderPlottingLive, barup='red',bardown='green', port=8065,lookback=99, scheme=Tradimo(hovertool_timeformat='%F %R:%S')) 

data_start as follow: 2023-07-26_230435 The first candlestick displayed is actually the second data in the dataframe.But time is reduced by 1 minute. image The last displayed candlestick is actually the last data entry in the dataframe, but the time has been reduced by 1 minute. image

zgpnuaa commented 1 year ago

It does not draw the first candlestick whether it is in live trading or backtesting. Instead, it starts drawing from the second candlestick. The overall time remains unchanged, meaning that the chart starts from the second candlestick but with time starting from the first candlestick's time. This results in all candlesticks having incorrect timestamps, as there is a shift of one period in time. For example, when plotting 30-minute candlesticks, the OHLC data displayed at 10:00 actually corresponds to 10:30 OHLC data and so on.

2023/06/19 10:00:00, 1_prenext: open:271.758-high:271.758-low:271.168-close:271.258 2023/06/19 10:30:00, 2_prenext: open:271.228-high:271.768-low:268.408-close:268.878 2023/06/19 11:00:00, 3_prenext: open:268.898-high:270.458-low:268.898-close:269.238 2023/06/19 11:30:00, 4_prenext: open:269.238-high:269.238-low:266.868-close:268.158 image image

qsyao commented 1 year ago

same question, expecting a nice fix ! @happydasch

Balzac1799 commented 5 months ago

@zgpnuaa @qsyao @happydasch It seems that change this line to if c_start and c_start >= t_end can fix the missing first candle error