【问题标题】:Pine script - How to program multiple take profit targetsPine 脚本 - 如何编程多个止盈目标
【发布时间】:2019-06-24 12:08:03
【问题描述】:

我正在尝试在 pine 策略中设置 3 个获利目标。

在下面的代码中,当触发做多条件时,打开一个数量为 100 的条目。这很好。 valueTakeProfit1、2 和 3 的值也是正确的。但是一旦我将它们放入一个 strategy.exit() 中,它们就会被触发或未被触发,或者利润处于错误的水平。 变量 ATR1/2/3percent 的值不是百分比,它只是从通过 strategy.entry() 打开的 100 中取出的数量。

if(longCondition or re_entryCondition)
    alertLine := 1
    strategy.entry(id="Long Entry", long=true, when=alertLine==1, qty=100)
    valueTakeProfit1 := close+ATR1*ma_function(tr(true), lengthATR)
    valueTakeProfit2 := close+ATR2*ma_function(tr(true), lengthATR)
    valueTakeProfit3 := close+ATR3*ma_function(tr(true), lengthATR)
    strategy.exit("Take Profit 1 Long", from_entry="Long Entry", limit=valueTakeProfit1, qty=ATR1percent)
    strategy.exit("Take Profit 2 Long", from_entry="Long Entry", limit=valueTakeProfit2, qty=ATR2percent)
    strategy.exit("Take Profit 3 Long", from_entry="Long Entry", limit=valueTakeProfit3, qty=ATR3percent)


//End long positions
if(longCloseCondition)
    strategy.close(id="Long Entry")

有人可以帮我看看我应该如何定义多个止盈水平吗?

【问题讨论】:

  • 使用 strategy.close_all(when=longCloseCondition) 似乎做得更好,但止盈水平是在下一根蜡烛而不是价格达到目标的当前蜡烛上获得的。如何从当前蜡烛中获利?

标签: pine-script


【解决方案1】:

好的,所以我发现了错误。 在脚本的开头,我确实声明了变量:

valueTakeProfit1 = 0.0
valueTakeProfit2 = 0.0
valueTakeProfit3 = 0.0

在 if 语句之前,我确实将变量重置为零:

valueTakeProfit1Short := 0.0
valueTakeProfit2Short := 0.0
valueTakeProfit3Short := 0.0

通过在 if 语句之前用正确的值声明变量,它确实解决了问题:

valueTakeProfit1 = close +  (ATR1*ma_function(tr(true), lengthATR))
valueTakeProfit2 = close +  (ATR2*ma_function(tr(true), lengthATR))
valueTakeProfit3 = close + (ATR3*ma_function(tr(true), lengthATR))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-21
    • 1970-01-01
    • 2021-12-14
    • 1970-01-01
    • 2020-02-10
    • 2021-12-13
    • 1970-01-01
    • 2021-04-07
    相关资源
    最近更新 更多