For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Beginer help / Simple RSI strategy

  • Hello,

    Very beginner question, I wanted to build a very simple RSI strategy which is long/short. In other words, it does reversals so we are always in position. Can anyone guide me how to begin, so far I'm able to do long-only strategy but struggling with coding reversal logic

    class RSIStrategy(bt.Strategy):

    def __init__(self):
        self.rsi = bt.indicators.RSI_SMA(, period=14)
    def next(self):
        if not self.position:
            if self.rsi < 30:
            if self.rsi > 70:

  • administrators

    Instead of sell when you are in the market, use close (which obviously closes the existing position)

    And use the < 30 and > 70 comparisons as the entry points if you are not in the market.