Pine script 我有一堆滞后

Pine script 我有一堆滞后,pine-script,algorithmic-trading,trading,Pine Script,Algorithmic Trading,Trading,我想构建一个algo,它可以执行以下操作: 当价格超过20巴时,MA:买入 当价格交叉下跌20条时,MA:空头 你能帮我吗 //@version=3 study("My Script") strategy("MA Crossover", overlay=true) x = sma(close,1) y = sma(close,20) longCondition = crossover(x, y) if (longCondition) strategy.entry("Long", st

我想构建一个algo,它可以执行以下操作:

当价格超过20巴时,MA:买入
当价格交叉下跌20条时,MA:空头

你能帮我吗

//@version=3
study("My Script")
strategy("MA Crossover", overlay=true)

x = sma(close,1)
y = sma(close,20)

longCondition = crossover(x, y)
if (longCondition)
    strategy.entry("Long", strategy.long)

shortCondition = crossunder(x, y)
if (shortCondition)
    strategy.entry("Short", strategy.short)

伙计。。。请更正我的代码。您正在编辑pointsdude的帖子。。。请更正我的代码。你只是在编辑文章的要点
//@version=4
strategy("MA Crossover", overlay=true, process_orders_on_close = true)

x = sma(close,1)
y = sma(close,20)

longCondition = crossover(x, y)
if (longCondition)
    strategy.entry("Long", strategy.long)

shortCondition = crossunder(x, y)
if (shortCondition)
    strategy.entry("Short", strategy.short)