can anyone help with this? I want a strategy that executes when a candle closes above the 10EMA. I have the code but the issue I keep getting is:
Compilation error. Line 8: no viable alternative at character '{'
Here is the code:
//@version=5
strategy("My Strategy", overlay=true)
// Declare variables
var ema = ema(close, 10)
// Check if the current candle closes above the EMA
if (close[1] < ema[1] and close > ema) {
strategy.entry("Short", strategy.short, leverage=10, size=strategy.calculate_position_size(percent=1, currency=currency.BTC), comment="Short")
}
// Plot the EMA
plot(ema, color=pink)
Any suggestions much appreciated!
From what I can see the curly braces are correctly referenced and no issue with syntax, so I'm at a wall
What if you remove the curly braces? Directly from the reference guide:
//@version=5
strategy("if")
if (ta.crossover(high, low))
strategy.entry("BBandLE", strategy.long, stop=low, oca_name="BollingerBands", oca_type=strategy.oca.cancel, comment="BBandLE")
else
strategy.cancel(id="BBandLE")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.