add conditions //@version=5.1 strategy("SMA and RSI Strategy for FTMUSDT", overlay=true)…
- User
add conditions //@version=5.1 strategy("SMA and RSI Strategy for FTMUSDT", overlay=true)
// Inputs for short-term and long-term SMA periods shortPeriod = input.int(15, minval=1, title="Short-term SMA Period") longPeriod = input.int(50, minval=1, title="Long-term SMA Period")
// Inputs for RSI period and thresholds rsiPeriod = input.int(14, minval=1, title="RSI Period") overbought = input.float(70.0, minval=50.0, maxval=100.0, title="Overbought Level") oversold = input.float(30.0, minval=0.0, maxval=50.0, title="Oversold Level")
// Option to combine SMA and RSI signals combineSignals = input.bool(false, title="Combine SMA and RSI Signals")
// Option to enable Stop Loss and Take Profit enableSLTP = input.bool(false, title="Enable Stop Loss & Take Profit") stopLossPerc = input.float(2.0, minval=0.0, title="Stop Loss (%)") takeProfitPerc = input.float(4.0, minval=0.0, title="Take Profit (%)")
// Calculate the short-term and long-term SMAs shortSMA = ta.sma(close, shortPeriod) longSMA = ta.sma(close, longPeriod)
// Calculate RSI rsi = ta.rsi(close, rsiPeriod)
// Plot the SMAs on the chart plot(shortSMA, color=color.blue, linewidth=2, title="Short-term SMA") plot(longSMA, color=color.red, linewidth=2, title="Long-term SMA")
// Generate buy and sell signals based on SMA crossover buySignal_SMA = ta.crossover(shortSMA, longSMA) sellSignal_SMA = ta.crossunder(shortSMA, longSMA)
// Generate buy and sell signals based on RSI levels buySignal_RSI = ta.crossunder(rsi, oversold) sellSignal_RSI = ta.crossover(rsi, overbought)
// Initialize buySignal and sellSignal variables var bool buySignal = false var bool sellSignal = false
// Combine signals accordingly if combineSignals buySignal := buySignal_SMA and buySignal_RSI sellSignal := sellSignal_SMA and sellSignal_RSI else buySignal := buySignal_SMA or buySignal_RSI sellSignal := sellSignal_SMA or sellSignal_RSI
// Plot individual SMA and RSI signals plotshape(buySignal_SMA, title="Buy Signal SMA", location=location.belowbar, color=color.lime, style=shape.labelup, text="BUY_SMA", size=size.tiny) plotshape(sellSignal_SMA, title="Sell Signal SMA", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL_SMA", size=size.tiny) plotshape(buySignal_RSI, title="Buy Signal RSI", location=location.belowbar, color=color.teal, style=shape.labelup, text="BUY_RSI", size=size.tiny) plotshape(sellSignal_RSI, title="Sell Signal RSI", location=location.abovebar, color=color.orange, style=shape.labeldown, text="SELL_RSI", size=size.tiny)
// Plot combined signals plotshape(buySignal and combineSignals, title="Combined Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, text="BUY", size=size.small) plotshape(sellSignal and combineSignals, title="Combined Sell Signal", location=location.abovebar, color=color.maroon, style=shape.triangledown, text="SELL", size=size.small)
- Assistant