OPEN-SOURCE SCRIPT

Gold Trading Signals + Trendlines + Patterns

//version=5
indicator("Gold Trading Signals + Trendlines + Patterns", overlay=true)

// === تنظیمات ورودی ===
emaShortLength = input.int(50, title="EMA Short Length", minval=1)
emaLongLength = input.int(200, title="EMA Long Length", minval=1)
rsiLength = input.int(14, title="RSI Length", minval=1)
atrMultiplierSL = input.float(1.5, title="ATR Multiplier for Stop Loss", minval=0.1)
tpMultiplier = input.float(2.0, title="Take Profit Multiplier", minval=1.0)
pivotLookback = input.int(5, title="Pivot Lookback Period", minval=2)

// === اندیکاتورها ===
emaShort = ta.ema(close, emaShortLength)
emaLong = ta.ema(close, emaLongLength)
rsi = ta.rsi(close, rsiLength)
atr = ta.atr(14)

// === قوانین ورود ===
longCondition = close > emaShort and emaShort > emaLong and rsi > 40
shortCondition = close < emaShort and emaShort < emaLong and rsi < 60

// === مدیریت ریسک ===
stopLossLong = close - atr * atrMultiplierSL
takeProfitLong = close + atr * atrMultiplierSL * tpMultiplier

stopLossShort = close + atr * atrMultiplierSL
takeProfitShort = close - atr * atrMultiplierSL * tpMultiplier

// === سیگنال‌های بصری ===
plotshape(series=longCondition, style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", size=size.small)
plotshape(series=shortCondition, style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", size=size.small)

if longCondition
line.new(x1=bar_index, y1=stopLossLong, x2=bar_index + 10, y2=stopLossLong, color=color.red, width=1, style=line.style_dotted)
line.new(x1=bar_index, y1=takeProfitLong, x2=bar_index + 10, y2=takeProfitLong, color=color.green, width=1, style=line.style_dotted)

if shortCondition
line.new(x1=bar_index, y1=stopLossShort, x2=bar_index + 10, y2=stopLossShort, color=color.red, width=1, style=line.style_dotted)
line.new(x1=bar_index, y1=takeProfitShort, x2=bar_index + 10, y2=takeProfitShort, color=color.green, width=1, style=line.style_dotted)

// === خطوط روند ===
// محاسبه سقف‌ها و کف‌ها (Pivot Points)
pivotHigh = ta.pivothigh(high, pivotLookback, pivotLookback)
pivotLow = ta.pivotlow(low, pivotLookback, pivotLookback)

// رسم خطوط روند بر اساس سقف‌ها و کف‌ها
var line upTrendline = na
var line downTrendline = na

if (not na(pivotLow))
if (na(upTrendline))
upTrendline := line.new(x1=bar_index[pivotLookback], y1=pivotLow, x2=bar_index, y2=low, color=color.green, width=1, style=line.style_solid)
else
line.set_xy2(upTrendline, bar_index, low)

if (not na(pivotHigh))
if (na(downTrendline))
downTrendline := line.new(x1=bar_index[pivotLookback], y1=pivotHigh, x2=bar_index, y2=high, color=color.red, width=1, style=line.style_solid)
else
line.set_xy2(downTrendline, bar_index, high)

// === الگوهای قیمتی ===
// شناسایی مثلث (Triangle)
isTriangle = ta.crossover(emaShort, emaLong) or ta.crossunder(emaShort, emaLong)

if isTriangle
label.new(bar_index, high, "Triangle", style=label.style_circle, color=color.orange, textcolor=color.white)

// === نمایش EMA‌ها ===
plot(emaShort, color=color.blue, title="EMA 50", linewidth=2)
plot(emaLong, color=color.red, title="EMA 200", linewidth=2)

// === نمایش RSI ===
hline(70, "Overbought (70)", color=color.gray, linestyle=hline.style_dotted)
hline(30, "Oversold (30)", color=color.gray, linestyle=hline.style_dotted)
Candlestick analysisChart patternsMoving Averages

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer