Ok, I didn't see the part in add.indicator.
Even better then: instead of adding new test for duplicates, let's remove
the buggy (and redundant) condition! :)

In the new light, the below condition is.null(names(tmp_val))prevents from
setting the label and thus keeps the duplicated column name in mktdata: e.g.
"yourticker.Close" from momentum function, after cbinded, becomes
"yourticker.Close.1".

Original:
if(is.null(names(tmp_val)) & ncol(tmp_val)==1)
names(tmp_val)<-indicator$label

Suggestion 2.0.0 :)
if(                          ncol(tmp_val)==1)
names(tmp_val)<-indicator$label

Bottom line: indicator$label is never NULL, so let's just use it as passed
by user. If not provided by user, then current template
"yourIndicatorFunctionName.ind", as implemented in add.indicator.

DK

On Mon, Aug 1, 2011 at 4:14 PM, Brian G. Peterson <brian@braverock.com>wrote:

> On Sun, 2011-07-31 at 15:32 +0200, Daniel Krizian wrote:
> > Hello,
> >
> > assigning labels via add.indicator function (in quantstrat) does not work
> > for TTR function "momentum" or "ROC" and generally other functions having
> > output with non-null column names. Labelling works properly only for
> > indicator functions that have empty column names, e.g. RSI, SMA used in
> > demos.
> > getSymbols('AAPL')
> > head(RSI(Cl(AAPL)))
> > head(SMA(Cl(AAPL)))
> > head(momentum(Cl(AAPL)))
> > head(ROC(Cl(AAPL)))
> >
> > For example, I have line, in which assignment label="momentum" will be
> > totally ignored later by applyIndicators:
> >
> > mystrat <- add.indicator(strategy = mystrat, name = "momentum", arguments
> =
> > list(x=quote(Cl(mktdata))), label = "mom" )
> >
> > This piece of code in applyIndicators causes the behavior:
> > if (is.null(names(tmp_val)) & ncol(tmp_val) == 1)
> >    names(tmp_val) <- indicator$label
> >
> > My suggestion is to replace it with more intuitive behavior:
> > if (!is.null(indicator$label) & ncol(tmp_val) == 1)
> >    names(tmp_val) <- indicator$label
> >
> > Thank you.
>
> Daniel,
>
> I like the spirit of your suggestion, but I'm not sure about the exact
> implementation.  In the current code, label is never NULL, because of
> this line in add.indicator
>
>    if(is.null(label)) label = paste(name,"ind",sep='.')
>
> Your suggested patch would ignore any names set by an indicator
> function, which seems to be counterproductive where indicator functions
> add meaningful names.
>
> Perhaps, instead, we need to test to see if the returned tmp_val column
> name is duplicated in the mktdata, and overwrite with label in that
> case.
>
> --
> Brian
>
>

	[[alternative HTML version deleted]]

