[R-SIG-Finance] quantstrat: executing stoplimit orders on the same bar as entry
scott gmail
scott.schmidt1001 at gmail.com
Thu Mar 14 23:57:43 CET 2013
Hi,
I am trying to test a strategy where a stoplimit order can be executed, if hit, on the same bar as trade entry. I am using intraday data, although I don't think that has any bearing on this case. The following is a situation I have run into:
bar 0: signal generated for entry, entry order entered in order book
bar 1: entry order executed with prefer='open'
bar 1: stoplimit order entered in order book (purpose is initial stop loss)
bar 1: signal generated for exit, exit order entered in order book
[bar 1: stoplimit hit, but no stoplimit order executed]
bar 2: exit order executed with prefer='open'
bar 2: stoplimit order on bar 1 canceled
I cannot seem to come up with a configuration that allows the stoplimit order entered on bar 1 to execute, if hit. After bar 1, the stoplimit seems to be executed as expected. I have tried changing the stoplimit orders from type 'chain' to type 'order', but that resulted in no transactions being placed. I also tried moving 'chain' up the rule.order hierarchy above 'exit' and 'entry', but that did not change the result.
Any suggestions are most welcome.
Thank you,
scott
Below are my rules:
### rules ----
# enter long
add.rule(strategy, name='ruleSignal',
arguments = list(sigcol="Cl.gt.SMA",
sigval=TRUE,
replace=FALSE,
orderqty=2,
ordertype='market',
orderside='long',
pricemethod='market',
prefer='open',
TxnFees=-5,
orderset='ocolong'),
type='enter',
label='EnterLong',
path.dep=TRUE)
# enter short
add.rule(strategy, name='ruleSignal',
arguments = list(sigcol="Cl.lt.SMA",
sigval=TRUE,
replace=FALSE,
orderqty= -2,
ordertype='market',
orderside='short',
pricemethod='market',
prefer='open',
TxnFees=-5,
orderset='ocoshort'),
type='enter',
label='EnterShort',
path.dep=TRUE)
# exit long
add.rule(strategy, name='ruleSignal',
arguments = list(sigcol="Cl.lt.SMA",
sigval=TRUE,
replace=TRUE,
orderqty='all',
ordertype='market',
orderside='long',
pricemethod='market',
prefer='open',
TxnFees=-5,
orderset='ocolong'),
type='exit',
label='ExitLong',
path.dep=TRUE)
# exit short
add.rule(strategy, name='ruleSignal',
arguments = list(sigcol="Cl.gt.SMA",
sigval=TRUE,
replace=TRUE,
orderqty='all',
ordertype='market',
orderside='short',
pricemethod='market',
prefer='open',
TxnFees=-5,
orderset='ocoshort'),
type='exit',
label='ExitShort',
path.dep=TRUE)
# stop-loss longs
add.rule(strategy, name='ruleSignal',
arguments = list(sigcol="Cl.gt.SMA",
sigval=TRUE,
replace=FALSE,
orderqty='all',
ordertype='stoplimit',
threshold= 5.25,
orderside='long',
TxnFees=-5,
prefer='open',
orderset='ocolong'),
type='chain',
parent='EnterLong',
label='StopLossLong',
storefun=FALSE,
path.dep=TRUE)
# stop-loss shorts
add.rule(strategy, name='ruleSignal',
arguments = list(sigcol="Cl.lt.SMA",
sigval=TRUE,
replace=FALSE,
orderqty='all',
ordertype='stoplimit',
threshold= 5.25,
orderside='short',
prefer='open',
TxnFees=-5,
orderset='ocoshort'),
type='chain',
parent='EnterShort',
label='StopLossShort',
storefun=FALSE,
path.dep=TRUE)
### end rules
More information about the R-SIG-Finance
mailing list