← Back to Reports

Perfect Timing Indicator For TradingView

Start by opening TradingView and creating a free account if you don’t have one already.

Once you have super charts up, click on “Pine Editor” on the bottom and paste the following code in the popup:

//@version=6
strategy(‘MACD & RSI Strategy with Filters (Long Only)’, overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)

// — Inputs —
macdFastLength = input.int(24, title = ‘MACD Fast Length’)
macdSlowLength = input.int(52, title = ‘MACD Slow Length’)
macdSignalLength = input.int(9, title = ‘MACD Signal Length’)
[macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength)

rsiLength = input.int(14, title = ‘RSI Length’)
rsiOverboughtLongExit = input.float(75, title = ‘RSI Overbought (Long Exit)’)
rsiMidLow = input.float(40, title = ‘RSI Mid Level Low (Filter)’)
rsiMidHigh = input.float(60, title = ‘RSI Mid Level High (Filter)’)

filterRSILongEnabled = input.bool(true, title = ‘Enable RSI Filter for Long Entries’)

// — Calculations —
rsiValue = ta.rsi(close, rsiLength)

macdLongEntry = ta.crossover(macdLine, signalLine)
rsiLongFilter = not filterRSILongEnabled or (rsiValue > rsiMidLow and rsiValue < rsiMidHigh)
longSignal = macdLongEntry and rsiLongFilter

// — Long Exit —
longExit = rsiValue >= rsiOverboughtLongExit

// — Strategy Execution —
if (longSignal)
    strategy.entry(“Long”, strategy.long)

if (longExit)
    strategy.close(“Long”)

// — Plotting —
plotshape(series = longSignal, title = ‘Long Entry’, location = location.belowbar, color = color.green, style = shape.triangleup, size = size.small)
plotshape(series = longExit, title = ‘Long Exit’, location = location.abovebar, color = color.red, style = shape.triangledown, size = size.small)

// — Alerts —
alertcondition(longSignal, title = ‘Long Entry Alert’, message = ‘MACD & RSI Long Entry Signal’)
alertcondition(longExit, title = ‘Long Exit Alert’, message = ‘MACD & RSI Long Exit Signal’)