Ahh, yes, I see.  I didn't think to run the HLC on mktdata to see what it
was returning.  Thank you Brian for looking at this so quickly and for
giving me insight into how you found the problem.

On Tuesday, December 4, 2012, Brian G. Peterson wrote:

> On 12/04/2012 04:31 AM, Justin Lilly wrote:
>
>> My problem as stated in the subject, is that when I add two ATR indicators
>> to a strategy, the second one has invalid output regardless of the
>> arguments.  As an example, I have added two lines to the 0.7.7 maCross
>> demo.  Directly after the second SMA indicator is added, I add these two
>> lines at line 26:
>>
>> stratMACROSS <- add.indicator(strategy = stratMACROSS, name = "ATR",
>> arguments = list(HLC=quote(HLC(mktdata)), n=20),label= "atr1" )
>> stratMACROSS <- add.indicator(strategy = stratMACROSS, name = "ATR",
>> arguments = list(HLC=quote(HLC(mktdata)), n=20),label= "atr2")
>>
>> note that the period (n) is identical.  This is to illustrate the problem.
>>   Once ran my output is as follows:
>>
>>  <...snip different example...>
>
>>
>> I expect the output here to be identical and clearly its not.  Can someone
>> please take a look?
>>
>>
> The problem here is with the use of HLC() from quantmod.
>
> It calls Hi(0, then Lo(), then Cl(), and can return multiple columns for
> each.  In the case here, it does exactly that, and returns trueHigh and
> trueLow when called for the second indicator.  You can see the problem by
> calling
>
> head(HLC(mktdata))
>
> after the script runs.
>
> On current svn code, this small modification to you indicators produces
> the results that you are looking for:
>
> add.indicator(strat.st, name = "ATR", arguments =
> list(HLC=quote(HLC(mktdata)[,**1:3]), n=20),label= "atr1" )
> add.indicator(strat.st, name = "ATR", arguments =
> list(HLC=quote(HLC(mktdata)[,**c(1,3,5)]), n=20),label= "atr2")
>
> note that I take columns 1,3,5 from the output of HLC to construct atr2,
> which will skip over the trueHigh and trueLow that you got from the first
> ATR indicator.
>
> Regards,
>
>    - Brian
>
> --
> Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
>
> ______________________________**_________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-sig-finance<https://stat.ethz.ch/mailman/listinfo/r-sig-finance>
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

	[[alternative HTML version deleted]]

