Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Heiken Ashi bars not calculated correctly with compression

    General Code/Help
    1
    1
    16
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Jyrki Nummela
      Jyrki Nummela last edited by

      Hi,

      I want to use both 1h and 4h Heiken Ashi bars.

      First, I tried to read the 1-minute data in with resample and compression=60 and compression=240, but the Heiken Ashi bars are not calculated correctly (my guess is that as Heiken Ashi uses the previous bar open and close values that [-1] is not refereeing correctly to previous hour and previous 4-hour bar).

      Next, I decided to try reading 1-hour bar data:

      data = bt.feeds.GenericCSVData(
      ....
      timeframe=bt.TimeFrame.Minutes,
      compression=60,
      ...)

      dataHK = bt.feeds.GenericCSVData(
      ....
      timeframe=bt.TimeFrame.Minutes,
      compression=60,
      ...)

      #Add the filter
      dataHK.addfilter(bt.filters.HeikinAshi(dataHK))

      #Add the data to Cerebro
      cerebro.adddata(data, name="Real")
      cerebro.adddata(dataHK, name="Heikin")

      and Heiken Ashi bars are calculated correctly.

      Now I have problems (or don't understand how to configure), to add 4h-data. I can't use the same data of 1-hour bars with resample and different compression (because Heiken Ashi is not calculated correctly), so I tried to read both 1h- and 4h-data. In addition to the data definitions above, I added:

      data4HK = bt.feeds.GenericCSVData(
      ...
      timeframe=bt.TimeFrame.Minutes,
      compression=240,
      ... )

      #Add the filter
      dataHK.addfilter(bt.filters.HeikinAshi(dataHK))
      data4HK.addfilter(bt.filters.HeikinAshi(data4HK))

      #Add the data to Cerebro
      cerebro.adddata(data, name="Real")
      cerebro.adddata(dataHK, name="Heikin")
      cerebro.adddata(data4HK, name="Heikin4")

      BUT it doesn't work either.... because def(next) can't process 1h and 4h-data correctly.

      Any help, how to go on? The easiest solution would be to somehow define Heiken Ashi to calculate bars correctly with compression=60 and compression =240.... but any solution is appreciated.

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors