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

Candlestick barup plotting color not working correctly?

  • Hi everyone,

    I'm doing the most basic examples from the README page and simple tutorials online, and I'm plotting my graph the following way:



    cerebro.plot(style='candlestick', barup='green', bardown='red')

    However, my graph looks almost entirely red when plotted:


    Verbatim copy/paste examples are showing the above type of output, but blog posts show red/green gray/green mixtures (as it should). Any thoughts on what is going wrong?

    I appreciate the help, thanks!

  • administrators

    Let's assume that you have recently downloaded that data from Yahoo ... and given that the data is now not really usable and what's adjusted close and real close is just a matter of in which direction the wind blows ... it could be a reason for the candles looking downwards in most cases.

    See a recent thread for example:

  • @nomnom, I agree with what @backtrader says. If you retrieved the data from Yahoo like I did (in my case using YahooFinanceData), you will observe random inconsistencies (sometimes, everything is fine, sometimes, everything is bad up to a point and then gets better**, sometimes the whole dataset is bad). If you read the post which @backtrader referenced, you will see that I had exactly the same issues when I tried to plot the data using candlesticks.

    Try seeing if you get the same problem with a different data source (e.g. Quandl).

    ** Try extending the timeframe for your example (make it go all the way up to yesterday). I'm willing to bet that you'll see that it "improves" after a certain date.

  • Oh wow, thanks for the feedback. That post certainly has a lot of information. I'm a bit confused though, getting this data is an absolute critical part to be able to perform meaningful backtesting. How is everyone getting their data? Surely everyone isn't making one-off modifications, are they? I have to assume I'm being dumb here and there is a common source/service/method that everyone uses to get reliable, meaningful data.

  • I don't know how accurate this is, but this ended up working:

    import backtrader as bt
    import pandas_datareader as web
    feed = web.DataReader("AAPL", "google", datetime(2016, 1, 1), datetime(2017, 1, 1))
    data = bt.feeds.PandasData(dataname=feed, name="AAPL")
    cerebro.plot(style='candlestick', barup='green', bardown='red')

    The graph looks as expected. Not sure if the data is exactly correct though.

Log in to reply