繁体   English   中英

Pine Script - 无法用我的逻辑编写 Strategy.exit

[英]Pine Script - Unable to write a Strategy.exit with my logic

我尝试在 Pine 编辑器中编写策略脚本。

  • strategy.entry() 正在按我的预期工作。
  • 但是 strategy.exit() 没有按照我的逻辑工作。
  • 我的退出计算是前一根蜡烛的高点减去低点。

我是 Pine 的新手。 下面是我的代码。 有人可以指出什么是错的吗?

    Short = ( ( close[1] > open[1] ) and ( high < high[1] ) and ( close < low[1] ) )
    if ( Short )
        Target = high[1] - low[1]
        Loss = high[1] - low[1]
        strategy.entry("Enter Short", strategy.short, 1, when = window() )
        strategy.exit("Enter Short", "Enter Short", stop=Loss, limit=Target, when = window())

根据 pine 脚本手册: when (bool) 一个可选参数。 订单条件。 如果条件为“真”,则下单。 如果条件为'false',则什么都不会发生(之前下的相同ID的订单不会被取消)。 默认值为“真”。 所以我认为你没有满足条件window()。 请改用 strategy.close()。

回答

Target = valuewhen(( ( close[1] > open[1] ) and ( high < high[1] ) and ( close < low[1] ) ), high[1] - low[1], 0 ) strategy.exit("Enter Short", "Enter Short", stop=strategy.position_avg_price+Target, limit=strategy.position_avg_price-Target, when = window())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM