For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Candlestick plotting wrongly displayed



  • Dear all,

    Thanks again for the backtrader library. I have an error with the plotting. The candlesticks are not correctly displayed. The body of the candle is displayed as the wick of the candle, and the wick of the candle is displayed as the body of the candle. The data in self.datas[0] is ok though as in, close, high, low, open are all as they should be. Just the plotting is not displayed correctly. See picture here:

    backtrader_plotting.JPG

    
    code: 
    
    class PandasData(bt.feeds.PandasData):
        params = (
            # Possible values for datetime (must always be present)
            #  None : datetime is the "index" in the Pandas Dataframe
            #  -1 : autodetect position or case-wise equal name
            #  >= 0 : numeric index to the colum in the pandas dataframe
            #  string : column name (as index) in the pandas dataframe
            ('datetime', None),
    
            # Possible values below:
            #  None : column not present
            #  -1 : autodetect position or case-wise equal name
            #  >= 0 : numeric index to the colum in the pandas dataframe
            #  string : column name (as index) in the pandas dataframe
            ('open', 'op'),
            ('high', 'hi'),
            ('low', 'lo'),
            ('close', 'clo'),
            ('volume', 'volume'),
            ('openinterest', None),
            ('number_of_trades', 'number_of_trades')
    
    cerebro = bt.Cerebro()
    
    data = PandasData(dataname=htf_train, timeframe=bt.TimeFrame.Minutes, compression=60, plot=True)
    
    cerebro.adddata(data)
    
    #cerebro.addstrategy(TestCrossStrategy)
    cerebro.broker.set_cash(10000)
     
    cerebro.run(runonce=False)
    
    fig = cerebro.plot(style='candlestick', iplot=True)[0][0]
    fig.set_size_inches(18.5, 10.5)
    fig
    

    Matplotlib version: 3.0.3
    Python version: 3.7.6

    Thanks for the help!

    Kind regards,

    Monstrar



  • @monstrar

    Hope to hear from any of you! :)



  • Definitely something wrong with your data or with the approach you use to import your data. If you want to hear more, you may want to share your data feed.


Log in to reply
 

});