Ma Crossover有一小段滞后

问题描述 投票:0回答:1

我想建立一个执行以下操作的算法:

[当价格突破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)
pine-script algorithmic-trading trading
1个回答
1
投票
//@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)
© www.soinside.com 2019 - 2024. All rights reserved.