Backtrader Community

    • 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/

    Crossover doesn't working with prices which move in small decimal differences.

    General Code/Help
    2
    2
    27
    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.
    • Sumeet Badiger
      Sumeet Badiger last edited by

      class SlowFastEmaCrossOverStrategy(bt.Strategy):
      
          def __init__(self):
              self.fast_ema = bt.indicators.EMA(self.data.close, period=self.params.fast_ema)
              self.slow_ema = bt.indicators.EMA(self.data.close, period=self.params.slow_ema)
              # This doesn't work if prices move in decimal differences, its always returns 0
              self.signal = bt.ind.CrossOver(self.fast_ema, self.slow_ema)
              self.sma = bt.indicators.SMA(self.datas[0].close, period=200)
      
      

      The above code doesn't give crossover signal as the difference in prices movements is in decimal for example XRP moves between 0.7 to 0.8, it has something to do with NonZeroDifference indicator. Can anybody help how can I get it working with this?

      A 1 Reply Last reply Reply Quote 0
      • A
        adamb032 @Sumeet Badiger last edited by

        @Sumeet-Badiger after you load the data, just multiply the entire series by 1000 and then does it work?

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