[R-SIG-Finance] setting quantstrat stoplimit threshold to a signal value
bb01100100
kel.graham at gmail.com
Thu Jun 30 10:15:17 CEST 2011
Hello,
I am testing a simple strategy in quantstrat, whereby I would like to set a
'stoplimit' order equal to 75% of the Donchian Channel range.
If the Donchian Channel is as follows:
a. low = 92.20
b. high = 110.50
Then I would like to set my 'stoplimit' to: low + (high - low) * 0.75,
giving a price of 105.925
My question is: How can I correctly access mktdata's signal information,
e.g. mktdata$mySignalValue for use in the threshold parameter of add.rule()?
If my approach is wrong, then a backup question is: In quantstrat, how do I
set a long stop / stoplimit order above the market at a price derived from
the signals added to the strategy via add.signal()?
I have tried to use formulas in the add.rule() function's 'threshold'
parameter as below:
myStrat = add.rule(myStrat, name='ruleSignal',
arguments=list(
sigcol='trade.long',
sigval=TRUE,
orderqty=1,
ordertype='stoplimit',
orderside='long',
threshold=(mktdata$tradeSignal.low + ((mktdata$tradeSignal.high -
mktdata$tradeSignal.low)*0.75) - mktdata$SPY.High),
tmult=FALSE,
TxnFees=-5
),
type='enter',
replace=TRUE
)
but I get an error:
[1] "Setup completed"
Added a position limit for SPY
Error in NextMethod(.Generic) :
dims [product 1] do not match the length of object [504]
In addition: Warning messages:
1: In max(i) : no non-missing arguments to max; returning -Inf
2: In max(getOrders(portfolio = portfolio, symbol = symbol, status = "open",
:
no non-missing arguments, returning NA
3: In if (!is.null(ordertype) & is.na(charmatch(ordertype, c("market", :
the condition has length > 1 and only the first element will be used
4: In if (is.na(charmatch(ordertype, c("market", "limit", "stoplimit", :
the condition has length > 1 and only the first element will be used
Which, I assume, means that I'm passing a big list of values from my
threshold formula instead of a specific value.
I have tried using last() on the above formula, but this uses the last value
of the entire mktdata series.
Also, I have searched quite a lot, but all of the examples I have seen look
for a signal and then buy at market, so I'm bit stuck. Any help, pointers or
guidance to a relevant example would be much appreciated.
Thanks,
Kel.
--
View this message in context: http://r.789695.n4.nabble.com/setting-quantstrat-stoplimit-threshold-to-a-signal-value-tp3635067p3635067.html
Sent from the Rmetrics mailing list archive at Nabble.com.
More information about the R-SIG-Finance
mailing list