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?



  • 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()
    


  • One of the ways:

    sma_up = sma1(0) > sma1(-1)
    sma_dn = sma1(0) < sma1(-1)
    

Log in to reply
 

});