[R-SIG-Finance] addATR() and addTA(ATR()) generate different plots
Joshua Ulrich
josh.m.ulrich at gmail.com
Thu Nov 28 17:08:31 CET 2013
On Thu, Nov 28, 2013 at 10:00 AM, <manojit_roy at comcast.net> wrote:
> Thanks for the prompt response. Adding HLC() to ATR() function brings the
> plot closer to the addATR() plot, but there are still differences - addATR()
> values are somewhat higher than addTA(ATR) values, and the two plots differ
> in shape too.
>
The default arguments are different:
> args(addATR)
function (n = 14, maType = "EMA", ...)
NULL
> args(ATR)
function (HLC, n = 14, maType, ...)
NULL
So try:
addTA(ATR(HLC(ticker),n=20,maType="EMA")$atr,col='blue',lwd=2)
Please keep replies on-list, so everyone can benefit from the discussion.
Best,
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
> ________________________________
> From: "Joshua Ulrich" <josh.m.ulrich at gmail.com>
> To: "manojit roy" <manojit_roy at comcast.net>
> Cc: "r-sig-finance" <r-sig-finance at r-project.org>
> Sent: Thursday, November 28, 2013 10:38:00 AM
> Subject: Re: [R-SIG-Finance] addATR() and addTA(ATR()) generate different
> plots
>
>
> On Thu, Nov 28, 2013 at 9:33 AM, <manojit_roy at comcast.net> wrote:
>> I get different plots for ATR() when adding this indicator to my chart in
>> two different ways (see last 2 lines of the code below):
>>
>>> require(quantmod)
>>> getSymbols('GTAT')
>>> ticker <- last(GTAT,'5 years')
>>>
>>> barChart(ticker,TA=NULL,theme='white',major.ticks='months',minor.ticks=FALSE,show.grid=FALSE)
>>> plot(addATR(n=20))
>>> plot(addTA(ATR(ticker,n=20)$atr,col='blue',lwd=2))
>>
>> Can someone help me understand what I am doing wrong, and which ATR values
>> I should use?
>>
> ATR requires a HLC object. You're passing an OHLCV object to it. Try:
> plot(addTA(ATR(HLC(ticker),n=20)$atr,col='blue',lwd=2))
>
> TTR can't use the HLC function because HLC is in quantmod and quantmod
> depends on TTR. So, for the time being, you have to be thoughtful
> about the columns in the object you pass to TTR functions.
>
> Best,
> --
> Joshua Ulrich | about.me/joshuaulrich
> FOSS Trading | www.fosstrading.com
More information about the R-SIG-Finance
mailing list