Rsi

//version=5
strategy("RSI Strategy", overlay=true)

// Define input variables
rsi_length = input(14, title="RSI Length")
rsi_buy = input(30, title="RSI Buy Threshold")
rsi_sell = input(70, title="RSI Sell Threshold")

// Calculate RSI
rsi_value = rsi(close, rsi_length)

// Define buy and sell signals
buy_signal = rsi_value < rsi_buy
sell_signal = rsi_value > rsi_sell

// Enter long position on buy signal
if (buy_signal)
strategy.entry("Buy", strategy.long)

// Exit long position on sell signal
if (sell_signal)
strategy.close("Buy")

// Plot RSI
plot(rsi_value, title="RSI", color=color.blue)

// Plot buy and sell signals
plotshape(buy_signal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(sell_signal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
Technical Indicators

免責事項