//version=5
indicator("Scalping Trend Indicator", overlay=true)

// Input Parameters
emaFastLength = input.int(9, title="Fast EMA Length", minval=1)
emaSlowLength = input.int(21, title="Slow EMA Length", minval=1)
atrLength = input.int(14, title="ATR Length", minval=1)
atrMultiplier = input.float(1.5, title="ATR Multiplier", minval=0.1)

// EMA Calculations
emaFast = ta.ema(close, emaFastLength)
emaSlow = ta.ema(close, emaSlowLength)

// ATR Calculation for Stop Loss and Take Profit
atr = ta.atr(atrLength)

// Define Trend
trendBullish = emaFast > emaSlow
trendBearish = emaFast < emaSlow

// Signal Conditions
buySignal = trendBullish and close > emaFast
sellSignal = trendBearish and close < emaSlow

// Stop Loss and Take Profit Levels
longStopLoss = close - atr * atrMultiplier
longTakeProfit = close + atr * atrMultiplier * 2
shortStopLoss = close + atr * atrMultiplier
shortTakeProfit = close - atr * atrMultiplier * 2

// Plot EMA Lines
plot(emaFast, color=color.green, title="Fast EMA")
plot(emaSlow, color=color.red, title="Slow EMA")

// Plot Buy and Sell Signals
plotshape(buySignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(sellSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")

// Plot Stop Loss and Take Profit Levels
plot(buySignal ? longStopLoss : na, color=color.new(color.red, 80), title="Buy Stop Loss", linewidth=1, style=plot.style_dotted)
plot(buySignal ? longTakeProfit : na, color=color.new(color.green, 80), title="Buy Take Profit", linewidth=1, style=plot.style_dotted)
plot(sellSignal ? shortStopLoss : na, color=color.new(color.red, 80), title="Sell Stop Loss", linewidth=1, style=plot.style_dotted)
plot(sellSignal ? shortTakeProfit : na, color=color.new(color.green, 80), title="Sell Take Profit", linewidth=1, style=plot.style_dotted)

// Alerts for Easy Monitoring
alertcondition(buySignal, title="Buy Alert", message="Buy Signal Detected! Place Stop Loss and Take Profit.")
alertcondition(sellSignal, title="Sell Alert", message="Sell Signal Detected! Place Stop Loss and Take Profit.")

// Add Labels for Signals
if (buySignal)
label.new(bar_index, low, "BUY", style=label.style_label_up, color=color.green, textcolor=color.white)
if (sellSignal)
label.new(bar_index, high, "SELL", style=label.style_label_down, color=color.red, textcolor=color.white)
Technical IndicatorsTrend Analysis

免責事項