[R-SIG-Finance] Read some data from TradeStation to display using barChart

Guy Yollin gyollin at r-programming.org
Tue Oct 2 23:28:50 CEST 2012


Mark,

Here's a code snippet that I had that reads a file exported from 
TradeStation, creates an xts object, and then generates a barChart.

See if you can make this work for what you want to do.

G



fn1 <- "GBPUSD.txt"
dat <- read.table(file=fn1,sep=",",header=T,as.is=T)
tm <- strptime(
   paste(dat[,"Date"], sprintf("%04d",dat[,"Time"])),
   format="%m/%d/%Y %H%M")


GBP <- xts(x=dat[,c("Open","High","Low","Close")],order.by=tm)
barChart(GBP,TA='addSMA(n = 7, col = "red");addSMA(n = 44, col = "blue")',
   theme="white",name="GBPUSD")

On 10/2/2012 12:13 PM, Mark Knecht wrote:
> Hi,
>     I haven't done any R programming in maybe 2 years but I got
> interested recently in looking at something and quantmod seems like it
> would be good for a basic start. As a first step I'm trying to get
> some price data saved in a running strategy on TradeStation into a
> barChart using quantmod.
>
>     The following code seems to read my data file successfully and
> produces reasonable looking (to me anyway) data.  I think I need to
> convert the data to xts to get barChart to work but I cannot quite get
> there. Is there a straightforward way to do this? Maybe the date
> format isn't right for use with xts?
>
>     Can someone point out how to do this?
>
> Thanks in advance,
> Mark
>
>
> require(reshape)
> require(TTR)
> require(ggplot2)
> require(chron)
> require(quantmod)
>
> ### Requires MWKFunctions.R be loaded first
> source("C:/Documents and Settings/Mark/My
> Documents/R/MWKFunctions/MWKFunctions.R")
>
> SystemTable = read.table("C:\\Test1.csv",sep=",",header=TRUE)
> SystemTable[,1] = TStoDate(SystemTable[,1])
> typeof(SystemTable)
>
> SystemTable[1:4,1:7]
>
> SystemXTS = as.xts(SystemTable[,1:7])
>
> barChart(SystemTable)
>
>
>
> <SNIP>
>> ### Requires MWKFunctions.R be loaded first
>> source("C:/Documents and Settings/Mark/My Documents/R/MWKFunctions/MWKFunctions.R")
>>
>> SystemTable = read.table("C:\\Test1.csv",sep=",",header=TRUE)
>> SystemTable[,1] = TStoDate(SystemTable[,1])
>> typeof(SystemTable)
> [1] "list"
>> SystemTable[1:4,1:7]
>          Date Time   Open    High     Low   Close Volume
> 1 2011-09-20 2225 1175.5 1176.00 1174.25 1174.50    102
> 2 2011-09-20 2230 1174.5 1175.50 1174.25 1175.25    267
> 3 2011-09-20 2235 1175.5 1175.75 1174.00 1175.00    248
> 4 2011-09-20 2240 1175.0 1175.50 1175.00 1175.25    135
>> SystemXTS = as.xts(SystemTable[,1:7])
> Error in as.POSIXlt.character(x, tz, ...) :
>    character string is not in a standard unambiguous format
>> barChart(SystemTable)
> Error in try.xts(x, error = "chartSeries requires an xtsible object") :
>    chartSeries requires an xtsible object
> _______________________________________________
> R-SIG-Finance at 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.
>
>



More information about the R-SIG-Finance mailing list