Pine 脚本未遍历所有点,仅保留一个入口且没有出口

发布于 2025-01-16 21:57:49 字数 588 浏览 0 评论 0原文

查找以下 10 SMA 到 20 SMA 交叉的代码,该代码无法正常工作

//@version=5
    strategy(' MA Crossover ', overlay=true)
    start = timestamp(2007, 1, 1, 0, 0)
    end = timestamp(2022, 03, 21, 0, 0)
    ema1 = ta.sma(close, 10)
    ema2 = ta.sma(close, 20)
    plot(ema1, title='EMA 11', color=color.new(color.green, 0))
    plot(ema2, title='EMA 20', color=color.new(color.blue, 0))
    LongEntry = ta.crossover(ema1, ema2)
    LongExit = ta.crossover(ema2, ema1)
    
    strategy.entry('Long Entry', strategy.long, when=LongEntry)
    strategy.close('Long Exit', when=LongExit)

Find below code for 10 SMA to 20 SMA crossover which is not working somehow

//@version=5
    strategy(' MA Crossover ', overlay=true)
    start = timestamp(2007, 1, 1, 0, 0)
    end = timestamp(2022, 03, 21, 0, 0)
    ema1 = ta.sma(close, 10)
    ema2 = ta.sma(close, 20)
    plot(ema1, title='EMA 11', color=color.new(color.green, 0))
    plot(ema2, title='EMA 20', color=color.new(color.blue, 0))
    LongEntry = ta.crossover(ema1, ema2)
    LongExit = ta.crossover(ema2, ema1)
    
    strategy.entry('Long Entry', strategy.long, when=LongEntry)
    strategy.close('Long Exit', when=LongExit)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

靑春怀旧 2025-01-23 21:57:49

strategy.close() 的第一个参数是 id

id(系列字符串) 必需参数。订单标识符。这是
可以通过引用标识符来关闭订单。

您需要传递您想要关闭的交易的 ID。在你的情况下应该是:

strategy.close('Long Entry', when=LongExit)

First parameter of strategy.close() is id.

id (series string) A required parameter. The order identifier. It is
possible to close an order by referencing its identifier.

You need to pass the id of the trade you want to close. In your case it should be:

strategy.close('Long Entry', when=LongExit)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文