【发布时间】:2020-10-18 00:30:23
【问题描述】:
这是一个简单的代码来向您展示我的意思,多头和空头头寸都有止损,但问题是我希望能够在不关闭已经开立的多头头寸的情况下开设空头头寸。正如您可能已经猜到的那样,我想在市场紧张并且您可以从中获利时测试此策略,无论哪种方式,它只需要两个帐户。
strategy("bothways", overlay=true)
leverage=input(5,"leverage",step=.25)
partoftrade=input(1,"partoftrade",step=.01)
StoplosssS=input(0.025,"StopLOSS SHORT",step=0.001)
StoplosssL=input(0.025,"StopLOSS LONG",step=0.001)
pertpS = input(0.02,"TP Short",step=0.01)
pertpL = input(0.02,"TP Long",step=0.01)
narrow=bbw(open,20,2)<0.005
red=open>close
green=open<close
longCondition = narrow and green
if (longCondition and strategy.opentrades<2)
strategy.entry("L", strategy.long,qty=(strategy.equity/1)*partoftrade*leverage/open,oca_name="ocg",oca_type=strategy.oca.cancel)
strategy.exit("LE",from_entry="L",profit=close*pertpL/syminfo.mintick,loss=open*StoplosssL/syminfo.mintick,oca_name="ocg")
shortCondition = narrow and red
if (shortCondition and strategy.opentrades<2)
strategy.entry("S", strategy.short,qty=(strategy.equity/1)*partoftrade*leverage/open,oca_name="ocg",oca_type=strategy.oca.reduce)
strategy.exit("SE",from_entry="S",profit=close*pertpS/syminfo.mintick,loss=open*StoplosssS/syminfo.mintick,oca_name="ocg")
感谢帮助
【问题讨论】:
-
不幸的是,我相信这是不可能的
-
我不太确定,但我认为这就是您使用 oca_name 的地方,并且必须使用不同的组。
标签: pine-script