策略。
我对此非常陌生,我想知道如何添加策略。此外,X bars之后的功能。
因此,当信号朝相反的方向(我目前实施)或x bar之后,我想退出长/短交易。
事先感谢您的任何帮助。非常感谢。
目前,我的进入和退出条件如下:
strategy.entry("Long", strategy.long, when=buy_1 or buy_2,
alert_message="{{strategy.order.action}} for {{ticker}} at {{strategy.order.price}}")
strategy.close("Long", when=sell_1 or sell_2, comment="Text for Exit here")
// strategy.exit("Exit Long", from_entry="Long", limit=tpLevel_long, stop=slLevel_long, comment="")
// Entry and exit logic for short
if sell_1 or sell_2
alert(message="Add Short text here")
strategy.entry("Short", strategy.short, when=sell_1 or sell_2,
alert_message="{{strategy.order.action}} for {{ticker}} at {{strategy.order.price}}")
strategy.close("Short", when=buy_1 or buy_2, comment="Text for Exit here")
// strategy.exit("Exit Short", from_entry="Short", limit=tpLevel_short, stop=slLevel_short, comment="")```
I'm quite new to this and I was wondering how it's possible to add a strategy.close function additionally after x bars.
So, I'd like to exit the long/short trades either when there comes a signal in the opposite direction (as I have implemented it currently) or after x bars.
Thanks in advance for any help. Much appreciated.
Right now I have the entry and exit conditions as following:
strategy.entry("Long", strategy.long, when=buy_1 or buy_2,
alert_message="{{strategy.order.action}} for {{ticker}} at {{strategy.order.price}}")
strategy.close("Long", when=sell_1 or sell_2, comment="Text for Exit here")
// strategy.exit("Exit Long", from_entry="Long", limit=tpLevel_long, stop=slLevel_long, comment="")
// Entry and exit logic for short
if sell_1 or sell_2
alert(message="Add Short text here")
strategy.entry("Short", strategy.short, when=sell_1 or sell_2,
alert_message="{{strategy.order.action}} for {{ticker}} at {{strategy.order.price}}")
strategy.close("Short", when=buy_1 or buy_2, comment="Text for Exit here")
// strategy.exit("Exit Short", from_entry="Short", limit=tpLevel_short, stop=slLevel_short, comment="")```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其添加到您的策略中:
Add this to your strategy:
您可以使用
stragity.opentrades.entry_bar_index
内置变量以获取条目的条索引。然后根据当前条索引添加支票。You can use the
strategy.opentrades.entry_bar_index
built-in variable to get the bar index of the entry. Then add a check based on current bar index.