Skip to content
Prev 8465 / 15274 Next

Parameters setting for multiple indicators with the same argument names

On Fri, 2011-09-09 at 09:35 +0200, igor_vilcek_external at tatrabanka.sk
wrote:

        
I wrote:
The answer won't change because you ask the question again.

I understand your question exactly, two variables named 'n'. got it.

The answer below is still exactly correct.  I'll add a bit more detail:
Original:
stratMACROSS <- add.indicator(strategy = stratMACROSS, name = "SMA",
arguments = list(x=quote(Cl(mktdata)), n=50),label= "ma50" )
stratMACROSS <- add.indicator(strategy = stratMACROSS, name = "SMA",
arguments = list(x=quote(Cl(mktdata)), n=200),label= "ma200")

New:
stratMACROSS <- add.indicator(strategy = stratMACROSS, name = "SMA",
arguments = list(x=quote(Cl(mktdata)), n=quote(shortMA)),label= "ma50" )
stratMACROSS <- add.indicator(strategy = stratMACROSS, name = "SMA",
arguments = list(x=quote(Cl(mktdata)), n=quote(longMA)),label= "ma200")

I'll leave as an exercise for the reader how to use expand.grid and loop
over applyStrategy with two different values for shortMA and longMA.
The second option remains the more flexible and harder (for you) to code
method.