我正在进入交易…
if (enterLong and strategy.position_size == 0)
strategy.entry("Long", true)
按预期工作,并在我想要的时候进入。但是从这里开始,我想要有几个不同的出口:
- 如果碰到INITIAL STOP ->退出贸易100%
- 如果击中第一个TAKE ->获得50%的交易,移动止损以达到收支平衡,并将第二步采取移动到新的条件
目前,我有一个之类的工作版本…
if (strategy.position_size > 0 and strategy.position_size == initial_size)
strategy.exit("LT1", limit=longTakePrice, qty_percent=50)
strategy.close("Long", when=low<longStopPrice)
else
if (strategy.position_size > 0 and strategy.position_size < initial_size)
strategy.exit("LS2", stop=entryPrice)
strategy.close("Long", when = takeCondition)
这个大多数工作,除了close()
函数直到下一个蜡烛才触发(而不是当条件满足时),并且通常有显著的(不切实际的)滑动。
我试过以下方法…
if (strategy.position_size > 0 and strategy.position_size == initial_size)
strategy.exit("LT1", limit=longTakePrice, qty_percent=50)
strategy.exit("LS1", stop=longStopPrice)
但这不起作用。相反,当LS1
被击中时,它只卖出50%的头寸。交换语句的顺序也不能工作。
编辑1:
在停止出口添加qty_percent=100
没有影响。
试试这个:
if (strategy.position_size > 0 and strategy.position_size == initial_size)
strategy.exit("LT1", limit=longTakePrice, stop=longStopPrice, qty_percent=50)
strategy.exit("LS1", stop=longStopPrice)