很抱歉造成任何不便:我正在r-sig-finance发帖,因为我在下面的问题上没有收到任何意见。
++++
大家好,
我正在测试一个简单的Bollinger-Breakout:
如果关闭> UpperBand然后长
如果关闭< LowerbandBand然后短
如果Close Crosses MidBand然后退出
以下是发生的事情:
我希望:
a)在我的卖空入场价之上创建的止损 b)在亏本而非制作时被触发。我在这里做错了什么?
我不确定我的代码的哪些部分会有所帮助,并且在您充斥着订单,交易等之前。我将从我的信号和规则(下面)开始。 非常感谢您的意见。谢谢!
add.indicator(strat.st, name = "BBands",
arguments = list(HLC = quote(HLC(mktdata)), maType='SMA'), label='BBands')
add.signal(strat.st, name="sigCrossover",
arguments=list(columns=c("Close","up"),relationship="gt"),
label="Cl.gt.UpperBand")
add.signal(strat.st, name="sigCrossover",
arguments=list(columns=c("Close","dn"),relationship="lt"),
label="Cl.lt.LowerBand")
add.signal(strat.st, name="sigCrossover",
arguments=list(columns=c("Close","mavg"),relationship="gt"),
label="Cross.Mid.GT")
add.signal(strat.st, name="sigCrossover",
arguments=list(columns=c("Close","mavg"),relationship="lt"),
label="Cross.Mid.LT")
add.rule(strat.st, name='ruleSignal',
arguments=list(sigcol="Cl.gt.UpperBand",sigval=TRUE, orderqty=1,
ordertype='market', orderside=NULL, threshold=NULL, osFUN=osFixedDollar,
orderset='ocolong'),
type='enter',label="LE")
add.rule(strat.st, name='ruleSignal',
arguments=list(sigcol="Cl.lt.LowerBand",sigval=TRUE, orderqty= -1,
ordertype='market', orderside=NULL, threshold=NULL, osFUN=osFixedDollar,
orderset='ocoshort'),
type='enter',label="SE")
add.rule(strat.st, name='ruleSignal',
arguments=list(sigcol="Cross.Mid.GT",sigval=TRUE, orderqty= 'all',
ordertype='market', orderside=NULL, threshold=NULL),
type='exit', label="midCrossGT")
add.rule(strat.st, name='ruleSignal',
arguments=list(sigcol="Cross.Mid.LT",sigval=TRUE, orderqty= 'all',
ordertype='market', orderside=NULL, threshold=NULL),
type='exit', label="midCrossLT")
add.rule(strat.st, name = 'ruleSignal',
arguments=list(sigcol='Cl.gt.UpperBand' , sigval=TRUE,
replace=FALSE,
orderside=NULL,
ordertype='limit',
tmult=TRUE,
threshold=quote(.stoploss),
orderqty='all',
orderset='ocolong'
),
type='chain', parent='LE',
label='StopLossLONG',
enabled=FALSE
)
add.rule(strat.st, name = 'ruleSignal',
arguments=list(sigcol='Cl.lt.LowerBand' , sigval=TRUE,
replace=FALSE,
orderside=NULL,
ordertype='limit',
tmult=TRUE,
threshold=quote(.stoploss),
orderqty='all',
orderset='ocoshort'
),
type='chain', parent='SE',
label='StopLossSHORT',
enabled=FALSE
)