//@version=5 indicator("Long-Term Trading Strategy", overlay=true)
// Inputs for strategy parameters lengthMA = input.int(50, title="Moving Average Length", minval=1) rsiLength = input.int(14, title="RSI Length", minval=1) macdFastLength = input.int(12, title="MACD Fast Length", minval=1) macdSlowLength = input.int(26, title="MACD Slow Length", minval=1) macdSignalLength = input.int(9, title="MACD Signal Length", minval=1)
// Calculations: Moving Average, RSI, MACD ma = ta.sma(close, lengthMA) // Declarative statement for moving average rsi = ta.rsi(close, rsiLength) [macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength)
// Buy condition: price crosses above MA, RSI is below 50, and MACD is bullish buyCondition = ta.crossover(close, ma) and rsi < 50 and macdLine > signalLine
// Exit condition: price crosses below MA, RSI is above 70, or MACD is bearish exitCondition = ta.crossunder(close, ma) or rsi > 70 or macdLine < signalLine
// Plot Buy Signal - Green Box Below Candle if (buyCondition) label.new(bar_index, low, text="Buy", style=label.style_labelup, color=color.green, textcolor=color.white, size=size.normal, tooltip="Buy Signal")
// Plot Exit Signal - Red Box Above Candle if (exitCondition) label.new(bar_index, high, text="Exit", style=label.style_labeldown, color=color.red, textcolor=color.white, size=size.normal, tooltip="Exit Signal")
// Plot the Moving Average line for reference plot(ma, title="Moving Average", color=color.blue)