OPEN-SOURCE SCRIPT

RSI & Impulse MACD Buy/Sell Signal

//version=5
indicator("RSI & Impulse MACD Buy/Sell Signal", overlay=true)

// Define RSI settings
rsiPeriod = 14
rsiSource = close
rsi = ta.rsi(rsiSource, rsiPeriod)

// Define MACD settings
macdFastLength = 12
macdSlowLength = 26
macdSignalSmoothing = 9
[macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalSmoothing)

// Detect MACD crossing above and below zero
macdAboveZero = ta.crossover(macdLine, 0)
macdBelowZero = ta.crossunder(macdLine, 0)

// Function to check for RSI bullish divergence
isBullishDivergence(rsiSource, rsi) =>
// Find the lowest low of the last 5 bars
low1 = ta.valuewhen(low == ta.lowest(low, 5), low, 0)
low2 = ta.valuewhen(low == ta.lowest(low, 5), low, 1)

// Find corresponding RSI values at those lows
rsi1 = ta.valuewhen(low == ta.lowest(low, 5), rsi, 0)
rsi2 = ta.valuewhen(low == ta.lowest(low, 5), rsi, 1)

// Check if we have a bullish divergence: price makes a lower low, and RSI makes a higher low
priceDivergence = (low1 < low2) and (rsi1 > rsi2)
priceDivergence

// Function to check for RSI bearish divergence
isBearishDivergence(rsiSource, rsi) =>
// Find the highest high of the last 5 bars
high1 = ta.valuewhen(high == ta.highest(high, 5), high, 0)
high2 = ta.valuewhen(high == ta.highest(high, 5), high, 1)

// Find corresponding RSI values at those highs
rsi1 = ta.valuewhen(high == ta.highest(high, 5), rsi, 0)
rsi2 = ta.valuewhen(high == ta.highest(high, 5), rsi, 1)

// Check if we have a bearish divergence: price makes a higher high, and RSI makes a lower high
priceDivergence = (high1 > high2) and (rsi1 < rsi2)
priceDivergence

// Check for bullish and bearish divergences in RSI
bullishDivergence = isBullishDivergence(rsiSource, rsi)
bearishDivergence = isBearishDivergence(rsiSource, rsi)

// Condition for Buy Signal: MACD crossing above zero + RSI bullish divergence
buySignal = macdAboveZero and bullishDivergence

// Condition for Sell Signal: MACD crossing below zero + RSI bearish divergence
sellSignal = macdBelowZero and bearishDivergence

// Plot buy and sell signals on the chart
plotshape(buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Plot RSI and MACD on the chart for reference
plot(rsi, title="RSI", color=color.blue, linewidth=1)
hline(70, "Overbought", color=color.red)
hline(30, "Oversold", color=color.green)
plot(macdLine, title="MACD Line", color=color.blue)
plot(signalLine, title="Signal Line", color=color.orange)
hline(0, "MACD Zero Line", color=color.gray)
Fundamental AnalysisMoving Average Convergence / Divergence (MACD)Relative Strength Index (RSI)rsi_divergence

Скрипт с открытым кодом

В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения. Вы можете добавить этот скрипт в избранное и использовать его на графике.

Хотите использовать этот скрипт на графике?

Отказ от ответственности