Why not use the ATR indicator in the TTR package?

On Thu, Sep 20, 2012 at 11:39 AM, sean fallon <sf99167@yahoo.com> wrote:

> I am trying to calculate the Absolute value to append in file so I can
> build ATR indicator. I am stuck at the first part wherein I am trying to
> calculate the ABS for High - Close Price. However when I run the
> "head(data)" to see what the results are, the AbsHC shows me the same
> number i.e. 61.2, whether I put the "data$AbsHC=abs(x)" inside the for loop
> or outside. I am only trying it for the first 10 rows of data. Enclosed
> below is the code
>
> #Get data fro Yahoo finance for Infosys (INFY.BO)
> data <- read.csv("
> http://ichart.finance.yahoo.com/table.csv?s=INFY.BO&a=08&b=16&c=2008&d=08&e=20&f=2012&g=d&ignore=.csv",
> stringsAsFactors=F)
>
> #view data
> head(data)
>
> #compute high-close
> h=data[,3]
> c=data[,4]
> hcdif=h-c
> data$HminusC=hcdif
>
> #check data
> data[30:40,]
>
> #compute absolute value
> j=2
> for (i in 1:10)
> {
>    ab1= data[i,5]
>    ab2= data[j,3]
>    x=ab1-ab2
>    #data$AbsHC=abs(x), I have commented this as I have out it outside the
> loop.
>    j = j+1
> }
>
> data$AbsHC=abs(x)
> head(data)
>
> What am I doing wrong here???
>
> regards
>
> Sean
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> 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]]

