OPEN-SOURCE SCRIPT

Best Buy/Sell Predictor with Labels

//version=5
indicator("Best Buy/Sell Predictor with Labels", overlay=true)

// Inputs
atrLength = input.int(10, title="ATR Length")
atrMultiplier = input.float(3.0, title="ATR Multiplier")
rsiPeriod = input.int(14, title="RSI Period")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")

// Supertrend Calculation
atr = ta.atr(atrLength)
upTrend = close[1] - (atrMultiplier * atr)
downTrend = close[1] + (atrMultiplier * atr)

trendUp = ta.valuewhen(ta.crossover(close, upTrend), upTrend, 0)
trendDown = ta.valuewhen(ta.crossunder(close, downTrend), downTrend, 0)

supertrend = close > trendUp ? trendUp : close < trendDown ? trendDown : na
supertrendDirection = close > supertrend ? 1 : close < supertrend ? -1 : na

// RSI Calculation
rsi = ta.rsi(close, rsiPeriod)

// Buy/Sell Conditions
buySignal = supertrendDirection == 1 and rsi < rsiOversold
sellSignal = supertrendDirection == -1 and rsi > rsiOverbought

// Plot Supertrend
plot(supertrendDirection == 1 ? trendUp : na, title="Supertrend Up", color=color.green, linewidth=2)
plot(supertrendDirection == -1 ? trendDown : na, title="Supertrend Down", color=color.red, linewidth=2)

// Plot Buy/Sell Shapes with Labels
plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY", title="Buy Signal")
plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL", title="Sell Signal")

// Alert Conditions
alertcondition(buySignal, title="Buy Alert", message="BUY Signal: Supertrend is bullish and RSI is oversold")
alertcondition(sellSignal, title="Sell Alert", message="SELL Signal: Supertrend is bearish and RSI is overbought")

免責聲明