[英]Pine Script. strategy.exit for Trailing Stop and Partial Take Profit
[英]Pine Script Strategy - How to set a simultaneous STOP exit for 100% and TAKE exit for only 50%?
我要进入交易...
if (enterLong and strategy.position_size == 0)
strategy.entry("Long", true)
这可以按预期工作,并在我想要的时候进入。 但从这里我想有几个不同的出口:
目前,我有一个这样的工作版本......
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
被击中时,它只卖掉了position的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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.