5

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)
Bjorn Mistiaen
  • 6,459
  • 3
  • 18
  • 42
Washy
  • 61
  • 1
  • 1
  • 3

1 Answers1

8

There are new namespaces in v5 pine. So for example ema() is now ta.ema() https://www.tradingview.com/pine-script-reference/v5/#fun_ta{dot}ema

rumpypumpydumpy
  • 3,435
  • 2
  • 5
  • 10
  • Thanks for the reply. I changed the ema to ta.ema. Now I'm getting an errror that says "21: Undeclared identifier 'strategy.close'" Really appreciate the help. – Washy Nov 15 '21 at 03:28
  • `strategy.close()` has different parameters than `strategy.entry()`. It will compile if you change it to `strategy.close("long")`. With `strategy.entry()` the `strategy.long` parameter is to tell the strategy to go long or short. `strategy.close()` doesn't have that parameter. https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}close – rumpypumpydumpy Nov 15 '21 at 04:25