Hi

I have a function myTTR ( which calculates the 5D SMA) given a price series.
I am trying to use add.indicator, add.signal and add.rule to this function.
The argument of myTTR is a price series, say ,'IBM'. So I have myTTR(IBM)
which returns a set of 1s,0s and -1s based on when the 5D SMA crossover has
happened etc. I have been trying to use this as follows but I keep getting
an error after applyStrategy. Can someone help please?

Here is the code:

require(quantstrat)
try(rm("order_book.SMA5D",pos=.strategy),silent=TRUE)
try(rm("account.SMA5D","portfolio.SMA5D",pos=.blotter),silent=TRUE)
try(rm("account.st","portfolio.st
","stock.str","s","initDate","initEq",'start_t','end_t'),silent=TRUE)

stock.str='IBM' # what are we trying it on
currency('USD')
stock(stock.str,currency='USD',multiplier=1)

initDate='2006-12-31'
initEq=1000000
portfolio.st='SMA5D'
account.st='SMA5D'

initPortf(portfolio.st,symbols=stock.str, initDate=initDate)
initAcct(account.st,portfolios=portfolio.st, initDate=initDate)
initOrders(portfolio=portfolio.st,initDate=initDate)


stratSMA5D <- strategy(portfolio.st)

stratSMA5D <- add.indicator(strategy = stratSMA5D, name = "myTTR", arguments
= list(x=quote(mktdata)))

stratSMA5D <- add.signal(strategy = stratSMA5D,name="sigThreshold",arguments
=
list(data=quote(mktdata),column="signal",relationship="gt",threshold=0,cross=TRUE),label="signal.gt.zero")
stratSMA5D <- add.signal(strategy = stratSMA5D,name="sigThreshold",arguments
=
list(data=quote(mktdata),column="signal",relationship="lt",threshold=0,cross=TRUE),label="signal.lt.zero")

stratSMA5D <- add.rule(strategy = stratSMA5D,name='ruleSignal', arguments =
list(data=quote(mktdata),sigcol="signal.gt.zero",sigval=TRUE, orderqty=100,
ordertype='market', orderside='long', threshold=NULL),type='enter')
stratSMA5D <- add.rule(strategy = stratSMA5D,name='ruleSignal', arguments =
list(data=quote(mktdata),sigcol="signal.gt.zero",sigval=TRUE, orderqty=-100,
ordertype='stoplimit', orderside='long',
threshold=1.1,tmult=TRUE),type='risk')

getSymbols(stock.str,from=initDate)
start_t<-Sys.time()
*out<-try(applyStrategy(strategy=stratSMA5D , portfolios=portfolio.st))*
end_t<-Sys.time()
end_t-start_t
updatePortf(Portfolio='SMA5D',Dates=paste('::',as.Date(Sys.time()),sep=''))
chart.Posn(Portfolio='SMA5D',Symbol=stock.str)

out<-try(applyStrategy(strategy=stratSMA5D , portfolios=portfolio.st))
Error in is.array(x) : 'x' is missing


Many thanks for  your kind assistance.
-- 
'Raghu'

	[[alternative HTML version deleted]]

