英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论