【问题标题】:Could not find function or function reference 'ema'找不到函数或函数引用“ema”
【发布时间】:2021-11-14 22:24:49
【问题描述】:

我收到错误第 13 行:找不到函数或函数引用“ema”。当我知道 ema 是一个函数时。

我正在尝试做一个简单的策略,如果价格高于 200 DEMA,并且来自 SuperTrend 指标的“买入”信号,它将进入多头交易。如果 SuperTrend 指标给出“卖出”信号,我想卖出。我的代码是否朝着正确的方向发展?非常感谢您的帮助!

//@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)

【问题讨论】:

    标签: pine-script algorithmic-trading trading indicator


    【解决方案1】:

    在 v5 pine 中有新的命名空间。例如ema() 现在是ta.ema() https://www.tradingview.com/pine-script-reference/v5/#fun_ta{dot}ema

    【讨论】:

    • 感谢您的回复。我将 ema 更改为 ta.ema。现在我收到一个错误,上面写着“21:未声明的标识符'strategy.close'”非常感谢您的帮助。
    • strategy.close() 的参数与strategy.entry() 不同。如果您将其更改为strategy.close("long"),它将编译。使用strategy.entry()strategy.long 参数用于告诉策略是做多还是做空。 strategy.close() 没有那个参数。 tradingview.com/pine-script-reference/v5/#fun_strategy{dot}close
    猜你喜欢
    • 1970-01-01
    • 2014-12-19
    • 2018-06-22
    • 1970-01-01
    • 2023-02-25
    • 1970-01-01
    • 2012-07-25
    • 2022-10-05
    • 1970-01-01
    相关资源
    最近更新 更多