I'm getting the error line 13: Could not find function or function reference 'ema'. When I know for a fact ema is a function.
I'm trying to do a simple strategy, where it enters a long trade if the price is above the 200 DEMA, and there is a "buy" signal from the SuperTrend indicator. I want to sell if the SuperTrend indicator gives a "sell" signal. Is my code going in the right direction? Would really appreciate some help!
//@version=5
strategy("DEMA and SuperTrend", overlay=true)
// SuperTrend
atrPeriod = input(12, "ATR Length")
factor = input.float(3.0, "Factor", step = 0.01)
[_, direction] = ta.supertrend(factor, atrPeriod)
// DEMA
demaLength = input(200)
src = input(close, title="Source")
e1 = ema(src, demaLength)
e2 = ema(e1, demaLength)
dema = 2 * e1 - e2
if ta.change(direction) < 0 and close > dema
strategy.entry("long", strategy.long)
if ta.change(direction) > 0
strategy.close("long", strategy.close)