OPEN-SOURCE SCRIPT

Enhanced SPY Rhythm Formations Detector with Alerts

58
//version=6
indicator("Enhanced SPY Rhythm Formations Detector with Alerts", overlay=true)

// Inputs
maLength1 = input.int(50, title="EMA Length 1", minval=1)
maLength2 = input.int(200, title="EMA Length 2", minval=1)
shortMaLength1 = input.int(5, title="Short EMA Length 1", minval=1)
shortMaLength2 = input.int(10, title="Short EMA Length 2", minval=1)
shortMaLength3 = input.int(20, title="Short EMA Length 3", minval=1)
rsiLength = input.int(14, title="RSI Length", minval=1)
macdShort = input.int(12, title="MACD Short Length", minval=1)
macdLong = input.int(26, title="MACD Long Length", minval=1)
macdSignal = input.int(9, title="MACD Signal Length", minval=1)
atrLength = input.int(14, title="ATR Length", minval=1)
atrMultiplier = input.float(1.5, title="ATR Multiplier for Target Price", minval=0.1)

// Calculations
ma1 = ta.ema(close, maLength1)
ma2 = ta.ema(close, maLength2)
shortMa1 = ta.ema(close, shortMaLength1)
shortMa2 = ta.ema(close, shortMaLength2)
shortMa3 = ta.ema(close, shortMaLength3)
rsi = ta.rsi(close, rsiLength)
[macdLine, signalLine, _] = ta.macd(close, macdShort, macdLong, macdSignal)
macdHist = macdLine - signalLine
atr = ta.atr(atrLength)

// Moving Average Crossovers
goldenCross = ta.crossover(ma1, ma2)
deathCross = ta.crossunder(ma1, ma2)

// Short MAs Crossovers
shortCross1 = ta.crossover(shortMa1, shortMa2)
shortCross2 = ta.crossover(shortMa2, shortMa3)
shortCross3 = ta.crossover(shortMa1, shortMa3)

shortCross1Down = ta.crossunder(shortMa1, shortMa2)
shortCross2Down = ta.crossunder(shortMa2, shortMa3)
shortCross3Down = ta.crossunder(shortMa1, shortMa3)

// RSI Divergence Detection
rsiHigh = ta.highest(rsi, 20)
rsiLow = ta.lowest(rsi, 20)
priceHigh = ta.highest(high, 20)
priceLow = ta.lowest(low, 20)

bearishDivergence = (high == priceHigh and rsi < rsiHigh)
bullishDivergence = (low == priceLow and rsi > rsiLow)

// MACD Histogram Zero Cross
macdZeroCrossUp = ta.crossover(macdHist, 0)
macdZeroCrossDown = ta.crossunder(macdHist, 0)

// Day Trading Signals
dayLongEntry = shortCross1 and rsi < 30
dayShortEntry = shortCross1Down and rsi > 70

// Swing Trading Signals
swingLongEntry = goldenCross and macdHist > 0
swingShortEntry = deathCross and macdHist < 0

// Next Bar Prediction
nextBarUp = close > open and close + (atr * atrMultiplier) > high
nextBarDown = close < open and close - (atr * atrMultiplier) < low

// Shaded Bar Shadow for Next Bar Prediction
bgcolor(nextBarUp ? color.new(color.green, 90) : na, title="Next Bar Up")
bgcolor(nextBarDown ? color.new(color.red, 90) : na, title="Next Bar Down")

// Blinking Alerts
var bool blink = false
blink := not blink

if (dayLongEntry)
label.new(bar_index, low, text="Day Long Entry", color=blink ? color.green : color.white, style=label.style_label_up, textcolor=color.black, size=size.small)
alert("Day Long Entry Signal Detected!", alert.freq_once_per_bar_close)

if (dayShortEntry)
label.new(bar_index, high, text="Day Short Entry", color=blink ? color.red : color.white, style=label.style_label_down, textcolor=color.black, size=size.small)
alert("Day Short Entry Signal Detected!", alert.freq_once_per_bar_close)

if (swingLongEntry)
label.new(bar_index, low, text="Swing Long Entry", color=blink ? color.blue : color.white, style=label.style_label_up, textcolor=color.black, size=size.small)
alert("Swing Long Entry Signal Detected!", alert.freq_once_per_bar_close)

if (swingShortEntry)
label.new(bar_index, high, text="Swing Short Entry", color=blink ? color.orange : color.white, style=label.style_label_down, textcolor=color.black, size=size.small)
alert("Swing Short Entry Signal Detected!", alert.freq_once_per_bar_close)

// Plotting
plot(ma1, color=color.blue, title="EMA Length 1 (50)")
plot(ma2, color=color.red, title="EMA Length 2 (200)")
plot(shortMa1, color=color.green, title="Short EMA Length 1 (5)")
plot(shortMa2, color=color.orange, title="Short EMA Length 2 (10)")
plot(shortMa3, color=color.purple, title="Short EMA Length 3 (20)")

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.