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

Setting Open = High = Low = Close



  • Hi,

    My data source has OHLC values, how can I make it so Backtrader only looks at the "Close" column, i.e. Backtrader sets Open = High = Low = Close.

    I am using a Pandas custom data loader, is the following appropriate?

    class CustomBTStockLoader(btfeeds.PandasData):
    
        params = (
                     ('openinterest', None),
                     ('open', 'Close'),
                     ('high', 'Close'),
                     ('low', 'Close'),
                 ) 
        datafields = btfeeds.PandasData.datafields
    

    ... and then later on:

    data = CustomBTStockLoader(dataname=datarange) #allows load additional "Opportunity" column
                data.plotinfo.plot=False
                cerebro.adddata(data, name=ticker)
    

    Thank you!



  • @backtrader the above appears to work as I would expect. Can you please confirm this is a reasonable approach and is indeed setting O = H = L = Close?

    Thanks!



  • Your approach will ruin indicators which use full OHLC values and limit/stop order execution.

    If you want orders to be executed on close than probably better to use cheat-on-close and market orders and original OHLC data.

    So depends on your goals.