متوجه شدم مشکلتون هنوز پابرجاست. خطای:
Syntax error at input 'end of line without line continuation'
در Pine Script معمولاً به معنی این هست که توی یک خط کد، PineScript انتظار یک مقدار دیگه رو داشته، ولی خط تموم شده یا خط درست ادامه پیدا نکرده.
✅ مشکل دقیقاً از اینه که برخی از آرگومانهای توابع plotshape نادرست وارد شدهاند:
کد اشتباه بود از این خط:
plotshape(
series=buyCondition,
...
text="BUY",
textcolor=color.white
)
در Pine Script نسخه ۵، توابع plotshape() و plotchar() پارامترهایی مثل text یا textcolor ندارند ❌ و همین باعث خطا شده.
✅ نسخه صحیح و بدون خطا (اصلاح شده کامل):
//@version=5
indicator("Advanced Buy/Sell Signals", overlay=true)
// --- تنظیمات ---
rsiLength = input.int(14, "RSI Length", minval=1)
macdFast = input.int(12, "MACD Fast Length", minval=1)
macdSlow = input.int(26, "MACD Slow Length", minval=1)
macdSignal = input.int(9, "MACD Signal Length", minval=1)
ma50Length = input.int(50, "MA 50 Length", minval=1)
ma200Length = input.int(200, "MA 200 Length", minval=1)
atrLength = input.int(14, "ATR Length", minval=1)
// --- محاسبه اندیکاتورها ---
rsi = ta.rsi(close, rsiLength)
[macdLine, signalLine, _] = ta.macd(close, macdFast, macdSlow, macdSignal)
ma50 = ta.sma(close, ma50Length)
ma200 = ta.sma(close, ma200Length)
atr = ta.atr(atrLength)
// --- تشخیص روند ---
bullishTrend = close > ma50 and close > ma200
bearishTrend = close < ma50 and close < ma200
// --- شرایط سیگنال خرید ---
buyCondition = bullishTrend and rsi < 30 and macdLine > signalLine and close > ma50
// --- شرایط سیگنال فروش ---
sellCondition = bearishTrend and rsi > 70 and macdLine < signalLine and close < ma50
// --- نمایش سیگنالها ---
plotshape(buyCondition, title="Buy Signal", location=location.belowbar,
style=shape.triangleup, size=size.small, color=color.green)
plotshape(sellCondition, title="Sell Signal", location=location.abovebar,
style=shape.triangledown, size=size.small, color=color.red)
// --- نمایش میانگین متحرکها ---
plot(ma50, color=color.blue, title="MA 50")
plot(ma200, color=color.orange, title="MA 200")
// --- رنگ پسزمینه بر اساس روند ---
bgcolor(
bullishTrend ? color.new(color.green, 85) :
bearishTrend ? color.new(color.red, 85) : na
)
// --- هشدارها ---
alertcondition(buyCondition, title="Buy Alert", message="سیگنال خرید فعال شد!")
alertcondition(sellCondition, title="Sell Alert", message="سیگنال فروش فعال شد!")
📌 نکات مهم:
- بقیه کد صحیح بود فقط
text= و textcolor= استفاده شده بود که غیر مجاز هستن.
- اگر میخوای متن “BUY” یا “SELL” نشون بدی، فقط با استفاده از
label.new() میتونی، نه با plotshape():
✳️ اگه متن بخوای بزاری کنار سیگنالها:
همون کد بالا رو استفاده کن، فقط این دو خط رو هم اضافه کن:
// نمایش متن BUY
if (buyCondition)
label.new(bar_index, low, text="BUY", style=label.style_labelup, color=color.green, textcolor=color.white)
// نمایش متن SELL
if (sellCondition)
label.new(bar_index, high, text="SELL", style=label.style_labeldown, color=color.red, textcolor=color.white)
✅ نتیجه:
- اندیکاتور بدون خطا اجرا میشود.
- سیگنالهای خرید و فروش نمایش داده میشوند.
- روند بازار با رنگ بکگراند مشخص شده.
- در صورت تمایل متن "BUY" و "SELL" هم میتونی به صورت برچسب بزاری.
اگه خواستی نسخه بکتست یا نسخه بدون repaint بنویسم، خوشحال میشم کمک کنم.