OPEN-SOURCE SCRIPT

lets work - RSI Band Strategy

//version=5
strategy("Demo GPT - RSI Band Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3)

// Inputs
length = input.int(14, title="RSI Length")
overSold = input.float(30, title="Lower Band (Buy)")
overBought = input.float(70, title="Upper Band (Sell)")

// Date filters
startDate = input.time(timestamp("2018-01-01 00:00"), title="Start Date", group="Date Filters")
endDate = input.time(timestamp("2069-12-31 23:59"), title="End Date", group="Date Filters")

// RSI Calculation
price = close
vrsi = ta.rsi(price, length)

// Timeframe filter
inDateRange = (time >= startDate and time <= endDate)

// Conditions
buyCondition = ta.crossover(vrsi, overSold) and inDateRange
sellCondition = ta.crossunder(vrsi, overBought) and inDateRange

// Entry and exit logic
if buyCondition
strategy.entry("Buy", strategy.long)

if sellCondition
strategy.close("Buy")

// Plot RSI for visual reference
plot(vrsi, title="RSI", color=color.blue)
hline(overSold, "Lower Band (Buy)", color=color.green)
hline(overBought, "Upper Band (Sell)", color=color.red)
bgcolor(inDateRange ? na : color.new(color.gray, 90), title="Out of Date Range")
Bands and ChannelsChart patterns

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer