简体   繁体   English

策略中的止损和反转仓位

[英]Stop Loss and revers positions in the strategy

I would like my Stop loss reverse my position.我希望我的止损反转我的 position。 Is it possible to do?有可能吗? When SL Long go to Short and when SL Short go to Long.当 SL 长 go 短时,当 SL 短 go 时长。 I was looking for a solution, but unfortunately I did not find it.我一直在寻找解决方案,但不幸的是我没有找到它。 Thank You!谢谢你!

strategy.entry('Long', strategy.long, when=long, comment='Long',alert_message = message_long_entry)
strategy.exit( "SL","Long", loss=8700, comment = "SL Long",alert_message = message_long_exit)
strategy.entry('Short', strategy.short, when=short, comment='Short',alert_message = message_short_entry)
strategy.exit( "SL","Short", loss=14700, comment = "SL Short",alert_message = message_short_exit)

Keep your stop-loss conditions (in case you have or do as follows) but use only strategy.entry() .保留您的止损条件(如果您有或执行以下操作),但仅使用strategy.entry()
strategy.entry in the counter direction (short->long | long->short) automatically closes your positions (disregarding position size) and additionally opens the positions you want. strategy.entry在反向方向(空头-> 多头 | 多头-> 空头)自动关闭您的头寸(不考虑 position 大小)并另外打开您想要的头寸。

isLong = strategy.opentrades.size > 0
isShort = strategy.opentrades.size < 0
if isLong and strategy.opentrades.entry_price * 0.95 >= close // 5% stop-loss
    strategy.entry('Reverse short', strategy.short, ...)

if isShort and strategy.opentrades.entry_price * 1.05 <= close // 5% stop-loss
    strategy.entry('Reverse long', strategy.long, ...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM