OPEN-SOURCE SCRIPT

RSI, MACD and MA Strategy

//version=5
indicator("RSI, MACD and MA Strategy", overlay=true)

// RSI Input
rsiLength = input(14, title="RSI Length")
rsiSource = input(close, title="RSI Source")
rsiOverbought = input(70, title="Overbought Level")
rsiOversold = input(30, title="Oversold Level")

// MACD Input
macdShortLength = input(12, title="MACD Short Length")
macdLongLength = input(26, title="MACD Long Length")
macdSignalLength = input(9, title="MACD Signal Length")

// MA Input
maLength = input(50, title="MA Length")

// RSI Calculation
rsiValue = ta.rsi(rsiSource, rsiLength)

// MACD Calculation
[macdLine, signalLine, _] = ta.macd(close, macdShortLength, macdLongLength, macdSignalLength)

// Moving Average Calculation
maLine = ta.sma(close, maLength)

// Buy and Sell Conditions
buySignal = ta.crossover(rsiValue, rsiOversold) and ta.crossover(macdLine, signalLine) and close > maLine
sellSignal = ta.crossunder(rsiValue, rsiOverbought) and ta.crossunder(macdLine, signalLine) and close < maLine

// Plotting Signals
plotshape(series=buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
Breadth Indicators

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