如何在获利后触发移动止损?

huangapple go评论60阅读模式
英文:

How to trigger trailing stop loss once some profit has been made?

问题

在Pine中,我下了一个长期的入场订单,以及一笔出场订单(带有利润和止损条件)

strategy.entry("我的长期入场", strategy.long)
strategy.exit("我的出口1", profit=15000, loss=15000, qty_percent=50, from_entry="我的长期入场", comment_profit="获利")

我还想激活一个跟踪止损订单(使用剩余50%的投资),一旦"我的出口1"已关闭,我尝试过这样做:

if strategy.closedtrades.exit_comment(strategy.opentrades - 1) == "获利"
    strategy.exit("我的出口2", from_entry="我的长期入场", trail_offset=15000, trail_points=0)

我从未在图表上看到这个触发,所以我认为"if"语句有问题。

有什么想法?

英文:

In Pine, I made a long entry order, along with an exit order (with a profit and stop loss condition)

strategy.entry("My Long Entry ", strategy.long)
strategy.exit("My Exit 1", profit=15000, loss=15000, qty_percent = 50 ,from_entry = "My Long Entry ", comment_profit="madeProfit")

I also want to activate a trailing stop loss order (with the rest of the 50% investment) once the "My exit 1" has been closed, I have tried this:

if strategy.closedtrades.exit_comment(strategy.opentrades - 1) == "madeProfit"
    strategy.exit("My Exit 2", from_entry = "My Long Entry ", trail_offset=15000, trail_points=0)

I never see this triggered on the chart, so I think there is something wrong with the "if" statement.

Any idea?

答案1

得分: 0

对于strategy.exit,不需要if

strategy.exit("My Exit 2", from_entry = "My Long Entry ", trail_offset=15000, trail_points=0)
英文:

for strategy.exit an if is not needed

strategy.exit("My Exit 2", from_entry = "My Long Entry ", trail_offset=15000, trail_points=0)

huangapple
  • 本文由 发表于 2023年4月11日 15:14:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75983309.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定