You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pine Script报错:'entryShort'输入不匹配,期待无续行行尾

错误原因及修复方案

核心问题分析

报错Mismatched input 'entryShort' expecting 'end of line without line continuation'的直接原因是:
entryLong = if belowEMA[1] and aboveEMA这一行的if语句没有明确返回值,Pine Script语法要求if用于变量赋值时,必须指定条件满足时的结果,否则编译器会认为该行代码未结束,进而无法解析下一行的entryShort定义。

同时代码中还存在一个拼写错误:elowEMA应为belowEMA,这个错误会导致后续条件判断逻辑失效。

修复后的完整代码

//@version=5
indicator("EMA Bounce Entry", overlay=true)

// Define EMA length
emaLen = 100

// Calculate the 100 EMA
ema = ema(close, emaLen)

// Identify closing price above/below EMA for potential entry
aboveEMA = close > ema
belowEMA = close < ema // 修复拼写错误:elowEMA → belowEMA

// Entry condition: Price bounces off EMA (closes above after being below or vice versa)
entryLong = belowEMA[1] and aboveEMA // 直接赋值布尔条件,无需冗余if关键字
entryShort = aboveEMA[1] and belowEMA

// Plot the EMA
plot(ema, color=color.blue, linewidth=2, title="100 EMA")

// Mark potential entry points with triangles (optional)
if entryLong
    triangle(up=true, color=color.green, size=size.tiny, location=close)
if entryShort
    triangle(down=true, color=color.red, size=size.tiny, location=close)

// Generate entry orders (modify as needed)
// This example uses alerts for illustration, replace with your order logic
if entryLong
    alert("Long Entry", alert.freq_once_per_bar_close, alert.success)
if entryShort
    alert("Short Entry", alert.freq_once_per_bar_close, alert.failure)

修复说明

  1. 移除了变量赋值中的冗余if关键字:布尔条件判断可以直接赋值给变量,不需要if包裹,简化代码同时符合语法规范。
  2. 修正了elowEMA的拼写错误,确保后续条件判断的正确性。

内容的提问来源于stack exchange,提问作者ade

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 11:35:54