ProTraderKit
Home
Features
Pricing
Get Started
Home
Features
Pricing
Get Started
RSI Strategy Code
RSI Strategy Code
Copy Code
//@version=5 strategy("RSI Strategy", overlay=true) // Input parameters rsi_length = input.int(14, title="RSI Length") overbought_level = input.int(70, title="Overbought Level") oversold_level = input.int(30, title="Oversold Level") target_points = input.int(100, title="Target Points") stop_loss_points = input.int(50, title="Stop Loss Points") // Calculate RSI rsi = ta.rsi(close, rsi_length) // Strategy logic long_condition = ta.crossover(rsi, oversold_level) short_condition = ta.crossunder(rsi, overbought_level) // Plot RSI plot(rsi, color=color.blue, title="RSI") // Strategy entry if long_condition strategy.entry("Long", strategy.long) if short_condition strategy.entry("Short", strategy.short) // Calculate target and stop loss levels long_target = strategy.position_avg_price + target_points long_stop_loss = strategy.position_avg_price - stop_loss_points short_target = strategy.position_avg_price - target_points short_stop_loss = strategy.position_avg_price + stop_loss_points // Strategy exit strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss) strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)