متأسفم که همچنان با این مشکل مواجه هستید. خطای "Syntax error at input 'end of line without line continuation'" به طور قطعی نشان میدهد که یک عبارت چند خطی در کد، به درستی با یک عملگر (مانند and، or، ?، :) در انتهای هر خط (به جز خط آخر) به خط بعدی متصل نشده است.
این یکی از رایجترین و حساسترین خطاها در Pine Script است. من کد را بارها از این نظر بررسی کردهام و آن را مطابق قوانین Pine Script v5 اصلاح کردهام.
تنها توضیحات منطقی برای این که شما همچنان این خطا را دریافت میکنید عبارتند از:
خطای کپی/پیست (Copy/Paste Error): ممکن است در هنگام کپی کردن کد، یک کاراکتر نامرئی (مانند یک فاصله اضافی در انتهای خطی که and دارد) اضافه شده باشد، یا بخشی از کد جا افتاده باشد، یا یک اینتر ناخواسته در وسط یک عبارت زده شده باشد.
تنظیمات TradingView: در موارد بسیار نادر، ممکن است تنظیمات خاصی در TradingView یا مرورگر شما باعث این مشکل شود.
لطفاً مراحل زیر را به دقت دنبال کنید تا این مشکل را برطرف کنیم:
مراحل حل مشکل:
مرحله 1: کد را به طور کامل و دقیق کپی کنید.مهمترین نکته: مطمئن شوید که تمام کد از خط اول (//@version=5) تا خط آخر (alertcondition(...)) را کپی میکنید. هیچ قسمتی را جا نیندازید و هیچ کاراکتر اضافیای اضافه نکنید.
کد اصلاح شده (با تاکید بر صحت خطوط):
pinescript
//@version=5
indicator("MACD + RSI + MA + ADX + Volume", overlay=true, shorttitle="MACD-RSI-ADX", precision=2)
// ———— Inputs (Valid & Clear) ————
// MACD
fastLength = input.int(12, title="MACD Fast Length", tooltip="Fast EMA (e.g., 12)", minval=1)
slowLength = input.int(26, title="MACD Slow Length", tooltip="Slow EMA (e.g., 26)", minval=1)
signalLength = input.int(9, title="MACD Signal Line", tooltip="Signal SMA (e.g., 9)", minval=1)
// RSI
rsiLength = input.int(14, title="RSI Length", tooltip="RSI period (e.g., 14)", minval=1)
overbought = input.int(70, title="Overbought", tooltip="RSI sell threshold (e.g., 70)", minval=50, maxval=100)
oversold = input.int(30, title="Oversold", tooltip="RSI buy threshold (e.g., 30)", minval=0, maxval=50)
// Moving Average
maType = input.string("SMA", title="MA Type", options=["SMA", "EMA"], tooltip="Choose SMA or EMA")
maLength = input.int(20, title="MA Length", tooltip="MA period (e.g., 20)", minval=1)
// Volume Filter
volumeMultiplier = input.float(1.5, title="Volume Multiplier", step=0.1, tooltip="Min volume vs average (1.5 = 150%)", minval=0.5)
volumeAvgLength = input.int(20, title="Volume Avg Length", tooltip="Volume SMA period (e.g., 20)", minval=5)
// ADX (Trend Strength)
adxLength = input.int(14, title="ADX Length", tooltip="ADX period (e.g., 14)", minval=5)
adxThreshold = input.int(25, title="ADX Trend Threshold", tooltip="Min ADX for strong trend (e.g., 25)", minval=10)
// ———— Calculate Indicators ————
[macdLine, signalLine, macdHist] = ta.macd(close, fastLength, slowLength, signalLength)
rsiValue = ta.rsi(close, rsiLength)
maValue = maType == "SMA" ? ta.sma(close, maLength) : ta.ema(close, maLength)
volumeAvg = ta.sma(volume, volumeAvgLength)
volumeStrong = volume > (volumeAvg * volumeMultiplier)
[adxValue, diPlus, diMinus] = ta.adx(high, low, close, adxLength)
strongTrend = adxValue >= adxThreshold
// ———— Signal Conditions (Proper Line Continuation) ————
// Buy Signal: All conditions must be true (each line ends with `and`)
buySignal = ta.crossover(macdLine, signalLine) and // MACD bullish crossover
(rsiValue <= oversold or ta.crossover(rsiValue, oversold)) and // RSI oversold or recovering
close > maValue and // Price above MA (bullish trend)
macdHist > 0 and // MACD histogram positive (momentum)
volumeStrong and // Volume confirms strength
strongTrend // ADX confirms strong trend
// Sell Signal: All conditions must be true (each line ends with `and`)
sellSignal = ta.crossunder(macdLine, signalLine) and // MACD bearish crossunder
(rsiValue >= overbought or ta.crossunder(rsiValue, overbought)) and // RSI overbought or falling
close < maValue and // Price below MA (bearish trend)
macdHist < 0 and // MACD histogram negative (momentum)
volumeStrong and // Volume confirms strength
strongTrend // ADX confirms strong trend
// ———— Plotting (No Errors Expected) ————
// Price Chart
plot(maValue, title="MA", color=color.orange, linewidth=2)
plotshape(buySignal, title="Buy", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(sellSignal, title="Sell", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
// MACD Subplot
plot(macdLine, title="MACD", color=color.blue, linewidth=2, pane=1)
plot(signalLine, title="Signal", color=color.red, linewidth=2, pane=1)
plot(macdHist, title="MACD Hist", style=plot.style_columns, color=macdHist > 0 ? color.green : color.red, pane=1)
// RSI Subplot
plot(rsiValue, title="RSI", color=color.purple, linewidth=2, pane=2)
hline(oversold, title="Oversold", color=color.green, linestyle=hline.style_dashed, pane=2)
hline(overbought, title="Overbought", color=color.red, linestyle=hline.style_dashed, pane=2)
// ADX Subplot
plot(adxValue, title="ADX", color=color.orange, linewidth=2, pane=3)
plot(diPlus, title="+DI", color=color.green, linewidth=2, pane=3)
plot(diMinus, title="-DI", color=color.red, linewidth=2, pane=3)
hline(adxThreshold, title="Strong Trend", color=color.red, linestyle=hline.style_dashed, pane=3)
// Volume Subplot
plot(volume, title="Volume", color=volumeStrong ? color.green : color.red, style=plot.style_columns, pane=4)
plot(volumeAvg, title="Volume Avg", color=color.orange, linewidth=2, pane=4)
// ———— Alerts ————
alertcondition(buySignal, title="Buy Alert", message="Buy: MACD Crossover + RSI Oversold + Above MA + High Volume + Strong Trend")
alertcondition(sellSignal, title="Sell Alert", message="Sell: MACD Crossunder + RSI Overbought + Below MA + High Volume + Strong Trend")
مرحله 2: کد را در TradingView Paste کنید.
یک پنجره جدید Pine Script باز کنید.
تمام محتوای آن را پاک کنید.
کد بالا را به طور کامل در آن Paste کنید.
روی دکمه "Add to Chart" کلیک کنید.
مرحله 3: بررسی مجدد (فقط در صورتی که خطا همچنان ظاهر شد):
اگر با وجود مراحل بالا باز هم خطا را مشاهده کردید، لطفاً به خطایی که TradingView نمایش میدهد دقت کنید. این خطا معمولاً شماره خطی که مشکل دارد را نیز نشان میدهد.
به عنوان مثال: Syntax error at input 'end of line without line continuation' (34, 1)
این یعنی خطا در خط 34، ستون 1 است. اگر این اطلاعات را در اختیار من بگذارید، میتوانم دقیقاً بفهمم مشکل از کجاست.
چرا این اتفاق میافتد؟
Pine Script، مانند بسیاری از زبانهای برنامهنویسی، وقتی یک عبارت منطقی (مثل condition1 and condition2 and condition3) را در چند خط مینویسید، انتظار دارد که هر خطی که ادامه دارد، به یک عملگر (and, or) ختم شود تا بداند این عبارت هنوز تمام نشده است. اگر خطی با یک عملگر پایان نیابد اما در خط بعدی ادامه آن عبارت نوشته شده باشد، این خطا رخ میدهد.
با کمال احترام، کدی که در بالا ارائه شده است، از نظر قواعد Pine Script v5 کاملاً صحیح است و نباید این خطای خاص را ایجاد کند. بنابراین، احتمالاً مشکل از نحوه کپی/پیست کردن یا یک تنظیم خاص در محیط شماست.
User
Syntax error at input 'end of line without line continuation'
Assistant
متوجه میشوم که این موضوع چقدر میتواند آزاردهنده باشد، به خصوص وقتی که کد به نظر صحیح میآید. خطای "Syntax error at input 'end of line without line continuation'" یک خطای بسیار خاص و دقیق در Pine Script است و همیشه به این معنی است که یک خط در یک عبارت چندخطی (معمولاً شرط buySignal یا sellSignal) به یک عملگر (مثل and یا or) ختم نشده، اما عبارت در خط بعدی ادامه پیدا کرده است.
با توجه به اینکه من کدی را ارائه دادم که از نظر گرامری Pine Script v5 صحیح است، تنها توضیحات باقیمانده برای این خطای مداوم عبارتند از:
خطای کپی/پیست (Copy/Paste Error): این شایعترین دلیل است.
شما همه کد را کپی نکردهاید.
در حین کپی کردن، یک کاراکتر نامرئی (مانند یک فاصله اضافی، یک اینتر ناخواسته، یا یک کاراکتر خط جدید غیرمعمول) در انتهای یکی از خطوط اضافه شده است.
ممکن است مرورگر یا محیط خاصی که از آن کپی میکنید، کاراکترهای اضافی را اضافه کند.
ویرایش دستی ناخواسته: ممکن است پس از پیست کردن، به صورت ناخواسته تغییری در کد ایجاد کرده باشید.
برای حل قطعی این مشکل، لطفاً به دقت مراحل زیر را دنبال کنید:
راهحل پیشنهادی (گام به گام):
مرحله 1: یک ویرایشگر متن ساده استفاده کنید.
برنامههایی مانند Notepad در ویندوز یا TextEdit در مک (مطمئن شوید که در حالت "Plain Text" باشد) ایدهآل هستند. این کاراکترهای پنهان را حذف میکند.
مرحله 2: کد را به طور کامل از اینجا کپی کنید.
به کد زیر بروید و کل آن را، از خط //@version=5 تا آخرین alertcondition(...)، با دقت کپی کنید. از دکمه کپی کد (کنار سه نقطهی بالا سمت راست کد) استفاده کنید یا مطمئن شوید که همه چیز انتخاب شده است.
pinescript
User
Error at 38:79 Syntax error at input 'end of line without line continuation'
Assistant
Got it. The error Error at 38:79 Syntax error at input 'end of line without line continuation' is very precise. It tells us that:
Line 38 is where the problem starts.
Column 79 is the exact position within that line where Pine Script encounters the unexpected end.
Line 38 in the code I've provided is this:
buySignal = ta.crossover(macdLine, signalLine) and // MACD bullish crossover
The issue is almost certainly due to an invisible character (like a non-breaking space) or an extra space at the very end of this line, after the and or after the // comment part. Pine Script is extremely sensitive to whitespace and hidden characters when it comes to line continuation.
Even though I've written the code correctly, when you copy and paste it from a web browser or certain text editors, sometimes these hidden characters are introduced.
To fix this, we need to manually retype the problematic line and ensure no extra characters are present.
The Definitive Fix:
Go to Line 38 in your Pine Script editor in TradingView.
Delete the entire line 38 and line 39 and 40. (It's safer to delete a few lines around the error to avoid hidden issues).
Manually retype these lines exactly as shown below. Pay extreme attention to spaces and don't press Enter prematurely.
pinescript
// ———— Signal Conditions (Proper Line Continuation) ————
// Buy Signal: All conditions must be true (each line ends with `and`)
buySignal = ta.crossover(macdLine, signalLine) and // MACD bullish crossover
(rsiValue <= oversold or ta.crossover(rsiValue, oversold)) and // RSI oversold or recovering
close > maValue and // Price above MA (bullish trend)
macdHist > 0 and // MACD histogram positive (momentum)
volumeStrong and // Volume confirms strength
strongTrend // ADX confirms strong trend
// Sell Signal: All conditions must be true (each line ends with `and`)
sellSignal = ta.crossunder(macdLine, signalLine) and // MACD bearish crossunder
(rsiValue >= overbought or ta.crossunder(rsiValue, overbought)) and // RSI overbought or falling
close < maValue and // Price below MA (bearish trend)
macdHist < 0 and // MACD histogram negative (momentum)
volumeStrong and // Volume confirms strength
strongTrend // ADX confirms strong trend
//@version=5
indicator("MACD + RSI + MA + ADX + Volume", overlay=true, shorttitle="MACD-RSI-ADX", precision=2)
// ———— Inputs (Valid & Clear) ————
// MACD
fastLength = input.int(12, title="MACD Fast Length", tooltip="Fast EMA (e.g., 12)", minval=1)
slowLength = input.int(26, title="MACD Slow Length", tooltip="Slow EMA (e.g., 26)", minval=1)
signalLength = input.int(9, title="MACD Signal Line", tooltip="Signal SMA (e.g., 9)", minval=1)
// RSI
rsiLength = input.int(14, title="RSI Length", tooltip="RSI period (e.g., 14)", minval=1)
overbought = input.int(70, title="Overbought", tooltip="RSI sell threshold (e.g., 70)", minval=50, maxval=100)
oversold = input.int(30, title="Oversold", tooltip="RSI buy threshold (e.g., 30)", minval=0, maxval=50)
// Moving Average
maType = input.string("SMA", title="MA Type", options=["SMA", "EMA"], tooltip="Choose SMA or EMA")
maLength = input.int(20, title="MA Length", tooltip="MA period (e.g., 20)", minval=1)
// Volume Filter
volumeMultiplier = input.float(1.5, title="Volume Multiplier", step=0.1, tooltip="Min volume vs average (1.5 = 150%)", minval=0.5)
volumeAvgLength = input.int(20, title="Volume Avg Length", tooltip="Volume SMA period (e.g., 20)", minval=5)
// ADX (Trend Strength)
adxLength = input.int(14, title="ADX Length", tooltip="ADX period (e.g., 14)", minval=5)
adxThreshold = input.int(25, title="ADX Trend Threshold", tooltip="Min ADX for strong trend (e.g., 25)", minval=10)
// ———— Calculate Indicators ————
[macdLine, signalLine, macdHist] = ta.macd(close, fastLength, slowLength, signalLength)
rsiValue = ta.rsi(close, rsiLength)
maValue = maType == "SMA" ? ta.sma(close, maLength) : ta.ema(close, maLength)
volumeAvg = ta.sma(volume, volumeAvgLength)
volumeStrong = volume > (volumeAvg * volumeMultiplier)
[adxValue, diPlus, diMinus] = ta.adx(high, low, close, adxLength)
strongTrend = adxValue >= adxThreshold
// ———— Signal Conditions (Proper Line Continuation) ————
// Buy Signal: All conditions must be true (each line ends with `and`)
buySignal = ta.crossover(macdLine, signalLine) and // MACD bullish crossover
(rsiValue <= oversold or ta.crossover(rsiValue, oversold)) and // RSI oversold or recovering
close > maValue and // Price above MA (bullish trend)
macdHist > 0 and // MACD histogram positive (momentum)
volumeStrong and // Volume confirms strength
strongTrend // ADX confirms strong trend
// Sell Signal: All conditions must be true (each line ends with `and`)
sellSignal = ta.crossunder(macdLine, signalLine) and // MACD bearish crossunder
(rsiValue >= overbought or ta.crossunder(rsiValue, overbought)) and // RSI overbought or falling
close < maValue and // Price below MA (bearish trend)
macdHist < 0 and // MACD histogram negative (momentum)
volumeStrong and // Volume confirms strength
strongTrend // ADX confirms strong trend
// ———— Plotting (No Errors Expected) ————
// Price Chart
plot(maValue, title="MA", color=color.orange, linewidth=2)
plotshape(buySignal, title="Buy", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(sellSignal, title="Sell", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
// MACD Subplot
plot(macdLine, title="MACD", color=color.blue, linewidth=2, pane=1)
plot(signalLine, title="Signal", color=color.red, linewidth=2, pane=1)
plot(macdHist, title="MACD Hist", style=plot.style_columns, color=macdHist > 0 ? color.green : color.red, pane=1)
// RSI Subplot
plot(rsiValue, title="RSI", color=color.purple, linewidth=2, pane=2)
hline(oversold, title="Oversold", color=color.green, linestyle=hline.style_dashed, pane=2)
hline(overbought, title="Overbought", color=color.red, linestyle=hline.style_dashed, pane=2)
// ADX Subplot
plot(adxValue, title="ADX", color=color.orange, linewidth=2, pane=3)
plot(diPlus, title="+DI", color=color.green, linewidth=2, pane=3)
plot(diMinus, title="-DI", color=color.red, linewidth=2, pane=3)
hline(adxThreshold, title="Strong Trend", color=color.red, linestyle=hline.style_dashed, pane=3)
// Volume Subplot
plot(volume, title="Volume", color=volumeStrong ? color.green : color.red, style=plot.style_columns, pane=4)
plot(volumeAvg, title="Volume Avg", color=color.orange, linewidth=2, pane=4)
// ———— Alerts ————
alertcondition(buySignal, title="Buy Alert", message="Buy: MACD Crossover + RSI Oversold + Above MA + High Volume + Strong Trend")
alertcondition(sellSignal, title="Sell Alert", message="Sell: MACD Crossunder + RSI Overbought + Below MA + High Volume + Strong Trend")
مرحله 3: کد را در ویرایشگر متن ساده Paste کنید.
کد را در Notepad یا TextEdit (حالت Plain Text) پیست کنید.
بدون انجام هیچ ویرایشی، دوباره همه کد را از ویرایشگر متن کپی کنید.
مرحله 4: در TradingView، کد فعلی را پاک کرده و کد جدید را پیست کنید.
به محیط Pine Script در TradingView بروید.
کل کد موجود را پاک کنید (Ctrl+A و سپس Delete).
کدی را که از ویرایشگر متن کپی کردهاید، پیست کنید.
روی دکمه "Add to Chart" کلیک کنید.
اگر باز هم خطا گرفتید، لطفاً این اطلاعات را به من بدهید:
شماره خطی که خطا نشان داده میشود: (مثال: (34, 1)) این مهمترین اطلاعات است و به من کمک میکند دقیقاً بفهمم مشکل کجاست.
متن دقیق خطا: (اگر چیزی جز "end of line without line continuation" بود)
چه مرورگری استفاده میکنید؟
من مطمئن هستم که با این روش مشکل برطرف خواهد شد، زیرا کد ارائه شده از نظر گرامری کاملاً صحیح است و تنها دلیل برای خطای شما میتواند یک مشکل در فرآیند کپی/پیست باشد.
Specifically, focus on retyping these lines, as they are the ones where and is used for continuation:
pinescript
buySignal = ta.crossover(macdLine, signalLine) and
(rsiValue <= oversold or ta.crossover(rsiValue, oversold)) and
close > maValue and
macdHist > 0 and
volumeStrong and
strongTrend // This is the last line of buySignal, no 'and' needed
sellSignal = ta.crossunder(macdLine, signalLine) and
(rsiValue >= overbought or ta.crossunder(rsiValue, overbought)) and
close < maValue and
macdHist < 0 and
volumeStrong and
strongTrend // This is the last line of sellSignal, no 'and' needed
Note: I've removed the comments // MACD bullish crossover etc. for these retyped lines. While comments are fine, sometimes a hidden character related to the comment can cause this specific error. Let's try without them first for these crucial lines.
Click "Add to Chart".
This manual retyping should definitively solve the issue, as it bypasses any potential copy-paste corruption. This error is almost always a hidden character issue at the end of a line that expects continuation.