Reputation: 1
I am getting the following error:
Mismatched input 'entryShort' expecting 'end of line without line continuation'
I can't figure out why this error is occurring:
Screenshot showing the error in the compiler
//@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
elowEMA = close < ema
// Entry condition: Price bounces off EMA (closes above after being below or vice versa)
entryLong = if belowEMA[1] and aboveEMA
entryShort = if aboveEMA[1] and belowEMA // Fix: Remove extra indentation
// 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)
The code should compile.
Upvotes: 0
Views: 69
Reputation: 355
The issue here is that you are using an unnecessary if statement in the code:
Just this should suffice:
entryLong = belowEMA[1] and aboveEMA
entryShort = aboveEMA[1] and belowEMA
For this exact code, the following will also do:
entryLong = ta.crossover(close, ema)
entryShort = ta.crossunder(close, ema)
Also, is triangle()
a function that you have created using plotshape()
? I am asking because it is not visible in your code. Otherwise, that line of code will also give an error. Below is the proper syntax for a triangle up:
plotshape(entryLong, "Up", shape.triangleup, location.belowbar, color.green, size = size.tiny)
Upvotes: 0