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/

    How to check the line of SimpleMovingAverage is going up?

    General Discussion
    code ema indicator
    2
    2
    42
    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.
    • Tom Sony
      Tom Sony last edited by

      How to check the line of SimpleMovingAverage is going up?

      class MyStrategy(bt.Strategy):
      
          def __init__(self):
      
              sma1 = btind.SimpleMovingAverage(self.data)
              ema1 = btind.ExponentialMovingAverage()
      
              close_over_sma = self.data.close > sma1
              close_over_ema = self.data.close > ema1
              sma_ema_diff = sma1 - ema1
      
              buy_sig = bt.And(close_over_sma, close_over_ema, sma_ema_diff > 0)
      
          def next(self):
      
              if buy_sig:
                  self.buy()
      
      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        One of the ways:

        sma_up = sma1(0) > sma1(-1)
        sma_dn = sma1(0) < sma1(-1)
        
        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }