Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- strategy("RSI Strategy", overlay=true)
- // Input for RSI periods
- rsiLongPeriod = input(14, title="RSI Long Period", minval=1)
- rsiShortPeriod = input(5, title="RSI Short Period", minval=1)
- // Calculate RSI values
- rsiLong = rsi(close, rsiLongPeriod)
- rsiShort = rsi(close, rsiShortPeriod)
- // Long Entry Condition
- longEntry = crossover(rsiLong, 50) and crossover(rsiShort, 70)
- // Long Exit Condition
- longExit = crossunder(rsiShort, 55)
- // Short Entry Condition
- shortEntry = crossunder(rsiLong, 50) and crossunder(rsiShort, 30)
- // Short Exit Condition
- shortExit = crossover(rsiShort, 35)
- // Execute trades
- strategy.entry("Long", strategy.long, when=longEntry)
- strategy.close("Long", when=longExit)
- strategy.entry("Short", strategy.short, when=shortEntry)
- strategy.close("Short", when=shortExit)
- // Plot RSI values and levels - Comment below code if you want to hide the RSI Plotting in Tradingview
- plot(rsiLong, title="RSI Long", color=color.blue)
- hline(50, "Long Level", color=color.green)
- plot(rsiShort, title="RSI Short", color=color.red)
- hline(70, "Long Entry", color=color.green)
- hline(55, "Long Exit", color=color.red)
- hline(30, "Short Entry", color=color.red)
- hline(35, "Short Exit", color=color.green)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement