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/

    Bbands using Ema instead of sma

    General Code/Help
    2
    5
    1687
    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.
    • Y
      you last edited by

      Hi

      Can I use ema instead of default sma for bbands indicator? I tried to pass bt.indicators.MovAv.EMA to param movav when creating bands , the code starts and run without isssue but the bbands top and bot values are much bigger than the expected value.. it works perfectly fine with sma.

      Thanks

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        As you have already used and documented under Docs - Indicators Reference the BollingerBands can use any moving average for the calculations (it could actually use any indicator which you throw at it)

        The questions:

        but the bbands top and bot values are much bigger than the expected value

        • What is the expected value?
        • Do you have a reference to compare against?
        1 Reply Last reply Reply Quote 0
        • Y
          you last edited by

          Hi

          Here is one example:
          Live data from IB on AUD-201706-GLOBEX

          bbands with SMA: (period=20, devfactor=2.0)
          top: 0.751921 mid: 0.751146 bot: 0.750371 2017-04-07T14:21:30
          
          bbands with EMA: (period=20, devfactor=2.0, movav=bt.indicators.MovAv.EMA)
          top: 0.792232 mid: 0.751423 bot: 0.710615 2017-04-07T14:21:30
          

          Compare to IB, the EMA top and bot point in the program are much higher (IB value : top 0.7524 bot: 0.7504) but the mid point matches at 0.751423. Also SMA values matches with IB.

          Any suggestion how I can further check on this?

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

            The StandardDeviation would use a SimpleMovingAverage in all cases. This seems to have a jumping-jack effect for the values.

            This commit makes the BollingerBands pass the chosen moving average: https://github.com/mementum/backtrader/commit/817fed29ccb7374e38bd0ab700f96fd4737ba514

            After the commit:
            0_1491585617894_upload-0c1e2ef7-5351-452c-a548-d25770fb36cd

            Before the commit
            0_1491585659450_upload-5ae23cc6-6faa-4794-9f77-6ff676532856

            This will be the final straw for a release later today.

            1 Reply Last reply Reply Quote 0
            • Y
              you last edited by

              Thanks - will test with the latest version

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