[R-SIG-Finance] questions about order price and timestamp in quantstrat
domodo
1111938 at qq.com
Wed Sep 3 09:21:40 CEST 2014
hi,guys,I'm learning quantstrat and get some questions as below:
1. transaction's order occurs and price
#add an indicator: monthly 5-sma
add.indicator(strategy = mystrategy, name = "SMA", arguments = list(x =
quote(Cl(mktdata)), n = 5), label = "SMA5")
add.indicator(strategy = mystrategy, name = "SMA", arguments = list(x =
quote(Cl(mktdata)[,1]), n = 10), label = "SMA10")
#add signal: SMA5 cross over / under sma10
add.signal(mystrategy, name = "sigCrossover", arguments = list(columns =
c("SMA5",
"SMA10"), relationship = "gt"), label = "SMA5.gt.SMA10")
add.signal(mystrategy, name = "sigCrossover", arguments = list(columns =
c("SMA5",
"SMA10"), relationship = "lt"), label = "SMA5.lt.SMA10")
#add rules
#open long position
add.rule(mystrategy, name = "ruleSignal", arguments = list(sigcol =
"SMA5.gt.SMA10",
sigval = TRUE, orderqty = 900, ordertype = "market", orderside = "long",
pricemethod = "market"), type = "enter", path.dep = TRUE) #buy 900 shares
#exit position
add.rule(mystrategy, name = "ruleSignal", arguments = list(sigcol =
"SMA5.lt.SMA10",
sigval = TRUE, orderqty = "all", ordertype = "market", orderside = "long",
pricemethod = "market"), type = "exit", path.dep = TRUE)
according to the codes above, when sma5 cross above sma10, a trading signal
occurs,and the order price is current bar's close price. it could be coded
in tradestation's easylanguage as below:
if average(close, 5) cross above average(close, 10) then
buy this bar at close;
if average(close, 5) cross under average(close, 10) then
sell this bar at close;
how if I want to set the next bar's open price as order price ? it means the
codes in easylanguage as below
if average(close, 5) cross above average(close, 10) then
buy next bar at open;
if average(close, 5) cross under average(close, 10) then
sell next bar at open;
my initial modification is:
1) make sma5 and sma10 delay a bar,that's,if sma5 of 2 bars ago is less than
sma10 of 2 bars ago,and previous bar's sma5 is greater than previous bar's
sma10,
2) then a signal occurs and an order with current bar's open price could be
sent out.
the codes below deal with point 1):
#add signal: SMA5 cross over / under sma10
add.signal(mystrategy, name = "sigCrossover", arguments = list(columns =
c("SMA5"[1],
"SMA10"[1]), relationship = "gt"), label = "SMA5.gt.SMA10")
add.signal(mystrategy, name = "sigCrossover", arguments = list(columns =
c("SMA5"[1],
"SMA10"[1]), relationship = "lt"), label = "SMA5.lt.SMA10")
but how to specify the order price as current bar's open price.
2. how to transfer timestamp from add.rule to ruleSignal
timestamp is a argment of ruleSignal,but ruleSignal's documents doesn't give
a detailed description,just says:
timestamp
timestamp coercible to POSIXct that will be the time the order will be
inserted on.
I don't quite catch on to what it is saying. further more,it seems that
seldom examles in demo folder of quantstrat specifies this argument ?
3. how to code 'pyramiding' in quantstrat ?
I have no idea about how to code 'pyramiding', it means the rule below,in
quantstrat:
1) when RSI is less than 30, enter long with 300 shares of stock A,
2) when RSI is less than 10, and previous position is profitable, enter long
with 100 more shares of stock A
3) when RSI is greater than 50, 200 shares of stock A exit
4) when RSI is greater than 70, rest 200 shares of stock A exit
much appreciated if any guys give me some help about the question.
regards.
--
View this message in context: http://r.789695.n4.nabble.com/questions-about-order-price-and-timestamp-in-quantstrat-tp4696424.html
Sent from the Rmetrics mailing list archive at Nabble.com.
More information about the R-SIG-Finance
mailing list