Skip to content

RSI with a trend filter

Enter when RSI is above 50 and the 50-period EMA is above the 200-period EMA. Exit when RSI falls below 45.

Complete strategy

first_strategy.strat
//@version=1

symbol: TCS
run: daily
size: 5% of portfolio per instrument

entry:
    long when: rsi(14) > 50 and ema(50) > ema(200)
exit:
    long when: rsi(14) < 45

Read the rule

Entry requires RSI above 50; exit requires it below 45. Try changing the entry threshold to 55 while keeping other settings fixed. Read RSI's scale and arguments and EMA periods before choosing a variation.

Try it in the editor

Copy the script into a TradeScript draft, resolve diagnostics and use the historical backtest flow. Start by inspecting an entry and exit or a portfolio rebalance. Change one value at a time.

Follow a trade

Rule Declaration in the sample
Entry long when: rsi(14) > 50 and ema(50) > ema(200)
Exit long when: rsi(14) < 45
Size size: 5% of portfolio per instrument

Both entry tests must match. RSI at 52 with the shorter EMA below the longer one does not qualify. Once long, RSI at 48 leaves the position open because it does not satisfy the exit. The sample has no price stop; its exit is a signal rule.

Use sufficient history for the 200-period EMA. In a backtest, inspect the indicator values at a matched entry and the RSI at the exit, then compare actual orders and fills.

Make one deliberate variation

Raise the entry threshold from 50 to 55 to require a stronger RSI reading. Keep the exit at 45 while comparing. To change the maximum price movement before a protective exit, add a supported stop; increasing or decreasing size: changes allocation instead.

Learn the concept Walk through the strategy →