TradingView Pine Script plotshape函数编译错误求助
Let's break down what's causing this compilation error and how to fix it quickly.
The Root Cause
Your error message points to a syntax issue in your plotshape calls: the compiler can't parse the parameters because you're mixing named arguments (like title="SuperTrend Long") with unlabeled positional arguments incorrectly.
In Pine Script, once you use a named argument for any parameter, all subsequent parameters must also use their explicit parameter names. Your code skips labels for critical parameters like shape, location, and color after using title=, which confuses the parser.
Fixed Code Snippets
Here's the corrected version of your plotshape blocks, with all parameters properly labeled:
// Plot entries plotshape(cross(close,Tsl) and close>Tsl ? True : na, title="SuperTrend Long", shape=shape.triangleup, text="Buy", location=location.belowbar, color=color.green, transp=0) // Super Trend Long plotshape(cross(Tsl,close) and close<Tsl ? True : na, title="SuperTrend Short", shape=shape.triangledown, text="Sell", location=location.abovebar, color=color.red, transp=0) // Super Trend Short plotshape(longToggle ? (k <= kMin and Trend == 1 ? Trend : na) : na, title="Long Entry", shape=shape.labelup, location=location.belowbar, color=color.navy, transp=0, textcolor=color.black) // Stochastic Long Entry plotshape(longAltToggle ? (rising(k,1) and cross(k, 50) and Trend == 1 ? Trend : na) : na, title="Long Alt Entry", shape=shape.cross, location=location.belowbar, color=color.olive, transp=0, textcolor=color.black) // Stochastic Long Entry plotshape(longExitToggle ? (k >= kMax and Trend == 1 ? Trend : na) : na, title="Long Exit", shape=shape.xcross, location=location.abovebar, color=color.red, transp=0, textcolor=color.black) // Stochastic Long Exit plotshape(shortToggle ? (k >= kMax and Trend == -1 ? Trend : na) : na, title="Short Entry", shape=shape.labeldown, location=location.abovebar, color=color.navy, transp=0, textcolor=color.black) // Stochastic Short Entry plotshape(shortAltToggle ? (falling(k,1) and cross(k, 50) and Trend == -1 ? Trend : na) : na, title="Short Alt Entry", shape=shape.cross, location=location.abovebar, color=color.olive, transp=0, textcolor=color.black) // Stochastic Short Entry plotshape(shortExitToggle ? (k <= kMin and Trend == -1 ? Trend : na) : na, title="Short Exit", shape=shape.xcross, location=location.belowbar, color=color.red, transp=0, textcolor=color.black) // Stochastic Short Exit
Key Changes Made
- Added explicit parameter labels (
shape=,location=,color=) for all arguments aftertitle=to resolve parsing confusion - Replaced the unlabeled
blackparameter withtextcolor=color.black(this was the missing label for text color) - Removed the empty string
""parameter which was unnecessary and causing additional parsing issues
Why This Works
Pine Script's parser relies on consistent argument labeling to map values to the correct function parameters. By explicitly naming each parameter, you eliminate ambiguity and ensure the compiler can translate your code correctly.
Just replace your original plotshape blocks with these corrected versions, and your script should compile without errors.
内容的提问来源于stack exchange,提问作者FTX




