【问题标题】:Pine Script - Unable to write a Strategy.exit with my logicPine Script - 无法用我的逻辑编写 Strategy.exit
【发布时间】:2020-06-06 11:29:19
【问题描述】:

我尝试在 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())

【问题讨论】:

  • 你确定你有一个正确的格式,即 if 语句内的块有 4 个空格吗?
  • 嗨,帕洛,是的。我在想变量(目标,损失)值没有传递到 strategy.exit() 中。我是否缺少将价格值传递给 strategy.exit() 以进行止损和限价的东西?
  • 您好 Palo,使用以下代码实现 =========================== ==================== '目标 = valuewhen(( ( close[1] > open[1] ) and ( high
  • 你可以把它写成答案,然后接受它。

标签: pine-script


【解决方案1】:

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

【讨论】:

  • 您好丹泽尔,感谢您的回复。 使用以下代码实现 '''Target = valuewhen(( ( close[1] > open[1] ) and ( high
【解决方案2】:

回答

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())

【讨论】:

    猜你喜欢
    • 2021-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    • 2020-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多