مشکل «Syntax error at input 'end of line without line continuation'» معمولاً وقتی رخ میدهد که در یک خط کد، کاما یا پارامترها به درستی جدا نشدهاند یا پارامترها به صورت کلید=مقدار نوشته نشدهاند.
در Pine Script، تابع plotshape باید پارامترها را به صورت کلید=مقدار دریافت کند، نه به صورت موقعیتی.
مشکل اصلی در خطوط plotshape است.
مثلاً این خط اشتباه است:
plotshape(strongBuySignal, location.belowbar, color.lime, shape.labelup, "STRONG BUY", size.normal, textcolor=color.white)
باید به این شکل اصلاح شود:
plotshape(series=strongBuySignal, location=location.belowbar, color=color.lime, style=shape.labelup, text="STRONG BUY", size=size.normal, textcolor=color.white)
نسخه کامل و اصلاح شده کد:
//@version=5
indicator("Advanced Trading Strategy - Fixed Signals", overlay=true)
// ورودیهای کاربر
emaShortLength = input.int(9, title="EMA Short Length")
emaMediumLength = input.int(21, title="EMA Medium Length")
emaLongLength = input.int(50, title="EMA Long Length")
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")
macdFastLength = input.int(12, title="MACD Fast Length")
macdSlowLength = input.int(26, title="MACD Slow Length")
macdSignalSmoothing = input.int(9, title="MACD Signal Smoothing")
// محاسبه اندیکاتورها
emaShort = ta.ema(close, emaShortLength)
emaMedium = ta.ema(close, emaMediumLength)
emaLong = ta.ema(close, emaLongLength)
rsi = ta.rsi(close, rsiLength)
[macdLine, signalLine, macdHistogram] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalSmoothing)
// محاسبه حجم معاملات
avgVolume = ta.sma(volume, 20)
highVolume = volume > avgVolume * 1.2
// محاسبه سطوح حمایت و مقاومت
pivotHigh = ta.pivothigh(high, 5, 5)
pivotLow = ta.pivotlow(low, 5, 5)
var float supportLevel = na
var float resistanceLevel = na
if not na(pivotHigh)
resistanceLevel := pivotHigh
if not na(pivotLow)
supportLevel := pivotLow
// شرایط روند ساده
bullishTrend = emaShort > emaMedium and emaMedium > emaLong
bearishTrend = emaShort < emaMedium and emaMedium < emaLong
// سیگنالهای خرید (سادهتر و دقیقتر)
// سیگنال خرید قوی
strongBuySignal = ta.crossover(emaShort, emaMedium) and
rsi < 70 and
macdLine > signalLine and
close > open
// سیگنال خرید متوسط
mediumBuySignal = ta.crossover(emaShort, emaLong) and
rsi < 65 and
macdHistogram > 0
// سیگنال خرید در اصلاح
dipBuySignal = rsi < rsiOversold and
rsi > rsi[1] and
close > emaShort and
macdHistogram > macdHistogram[1]
// سیگنال خرید MACD
macdBuySignal = ta.crossover(macdLine, signalLine) and
rsi < 60 and
close > emaMedium
// سیگنالهای فروش (سادهتر و دقیقتر)
// سیگنال فروش قوی
strongSellSignal = ta.crossunder(emaShort, emaMedium) and
rsi > 30 and
macdLine < signalLine and
close < open
// سیگنال فروش متوسط
mediumSellSignal = ta.crossunder(emaShort, emaLong) and
rsi > 35 and
macdHistogram < 0
// سیگنال فروش در اشباع خرید
peakSellSignal = rsi > rsiOverbought and
rsi < rsi[1] and
close < emaShort and
macdHistogram < macdHistogram[1]
// سیگنال فروش MACD
macdSellSignal = ta.crossunder(macdLine, signalLine) and
rsi > 40 and
close < emaMedium
// ترکیب سیگنالها
anyBuySignal = strongBuySignal or mediumBuySignal or dipBuySignal or macdBuySignal
anySellSignal = strongSellSignal or mediumSellSignal or peakSellSignal or macdSellSignal
// رسم سیگنالها با اشکال مختلف
plotshape(series=strongBuySignal, location=location.belowbar, color=color.lime, style=shape.labelup, text="STRONG BUY", size=size.normal, textcolor=color.white)
plotshape(series=mediumBuySignal, location=location.belowbar, color=color.green, style=shape.triangleup, text="BUY", size=size.small, textcolor=color.white)
plotshape(series=dipBuySignal, location=location.belowbar, color=color.blue, style=shape.circle, text="DIP", size=size.tiny, textcolor=color.white)
plotshape(series=macdBuySignal, location=location.belowbar, color=color.aqua, style=shape.square, text="MACD", size=size.tiny, textcolor=color.white)
plotshape(series=strongSellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="STRONG SELL", size=size.normal, textcolor=color.white)
plotshape(series=mediumSellSignal, location=location.abovebar, color=color.orange, style=shape.triangledown, text="SELL", size=size.small, textcolor=color.white)
plotshape(series=peakSellSignal, location=location.abovebar, color=color.purple, style=shape.circle, text="PEAK", size=size.tiny, textcolor=color.white)
plotshape(series=macdSellSignal, location=location.abovebar, color=color.maroon, style=shape.square, text="MACD", size=size.tiny, textcolor=color.white)
// رسم EMAها
plot(emaShort, color=color.blue, linewidth=2, title="EMA 9")
plot(emaMedium, color=color.orange, linewidth=2, title="EMA 21")
plot(emaLong, color=color.red, linewidth=2, title="EMA 50")
// رسم سطوح حمایت و مقاومت
plot(supportLevel, color=color.green, linewidth=2, style=plot.style_line, title="Support")
plot(resistanceLevel, color=color.red, linewidth=2, style=plot.style_line, title="Resistance")
// رنگآمیزی پسزمینه بر اساس روند
bgcolor(bullishTrend ? color.new(color.green, 90) : bearishTrend ? color.new(color.red, 90) : na)
// نمایش اطلاعات در گوشه
var table infoTable = table.new(position.top_right, 2, 5, bgcolor=color.white, border_width=1)
if barstate.islast
table.cell(infoTable, 0, 0, "RSI", text_color=color.black, bgcolor=color.gray)
table.cell(infoTable, 1, 0, str.tostring(math.round(rsi, 1)), text_color=color.black)
table.cell(infoTable, 0, 1, "MACD", text_color=color.black, bgcolor=color.gray)
table.cell(infoTable, 1, 1, str.tostring(math.round(macdLine, 4)), text_color=color.black)
table.cell(infoTable, 0, 2, "Trend", text_color=color.black, bgcolor=color.gray)
table.cell(infoTable, 1, 2, bullishTrend ? "Bull" : bearishTrend ? "Bear" : "Side",
text_color=bullishTrend ? color.green : bearishTrend ? color.red : color.orange)
table.cell(infoTable, 0, 3, "Volume", text_color=color.black, bgcolor=color.gray)
table.cell(infoTable, 1, 3, highVolume ? "High" : "Normal",
text_color=highVolume ? color.green : color.gray)
table.cell(infoTable, 0, 4, "Signal", text_color=color.black, bgcolor=color.gray)
table.cell(infoTable, 1, 4, anyBuySignal ? "BUY" : anySellSignal ? "SELL" : "WAIT",
text_color=anyBuySignal ? color.green : anySellSignal ? color.red : color.orange)
// آلارمها
alertcondition(strongBuySignal, title="Strong Buy", message="Strong Buy Signal!")
alertcondition(strongSellSignal, title="Strong Sell", message="Strong Sell Signal!")
alertcondition(anyBuySignal, title="Any Buy", message="Buy Signal Generated!")
alertcondition(anySellSignal, title="Any Sell", message="Sell Signal Generated!")
// نمایش آمار در انتهای نمودار
if barstate.islast
label.new(bar_index, high,
"EMA9: " + str.tostring(math.round(emaShort, 2)) + "\n" +
"EMA21: " + str.tostring(math.round(emaMedium, 2)) + "\n" +
"RSI: " + str.tostring(math.round(rsi, 1)),
style=label.style_label_down,
color=color.blue,
textcolor=color.white,
size=size.small)