title: addSMA not drawn on graph when called from function
body: <p>I am a newbie for R and have got stuck here.  I am trying to draw a graph with price, sma and ema.</p>
  
  <p>When I call the graph from the command line it draws fine including price, sma and ema:</p>
  
  <pre><code>tickers = c("BIIB","ISRG","AIG","FITB","GE","JNY","VIAB","WFM","WMB")
  
  x= 1
  
  print(paste("Preparing ADX graph for :",paste(tickers[x])))
  tmp &lt;- read.csv(paste(tickers[x],".csv", sep=""),as.is=TRUE, header=TRUE, row.names=NULL) 
  tmp$Date&lt;-as.Date(tmp$Date)
  ydat = xts(tmp[,-1],tmp$Date) 
  names(ydat) &lt;- c("Open","High","Low","Close","Volume","Adjusted")
  
  # convert it into montly price
  ydat.monthly &lt;- to.monthly(ydat)
  
  jpegname &lt;- paste(tickers[x], "MonthlyMovingAverage.jpeg", sep="") 
  jpeg( filename=jpegname,height=600, width=1600) 
  
  lineChart(ydat.monthly["1998/"], TA=NULL, name=paste(tickers[x],"Monthly &amp; 10 Month Moving Average"))
  addSMA(10)
  addEMA(10)
  
  dev.off()
  </code></pre>
  
  <p>But put into function as:</p>
  
  <pre><code>MovingMonthlyAverageGraph &lt;- function(tickers)
  {
  
      source("code.r")
      load.packages('quantmod')   
  
      for (x in 1:(length(tickers)) ) 
      { 
         print(paste("Preparing ADX graph for :",paste(tickers[x])))
         tmp &lt;- read.csv(paste(tickers[x],".csv", sep=""),as.is=TRUE, header=TRUE, row.names=NULL) 
         tmp$Date&lt;-as.Date(tmp$Date)
         ydat = xts(tmp[,-1],tmp$Date) 
         names(ydat) &lt;- c("Open","High","Low","Close","Volume","Adjusted")
  
         # convert it into montly price
         ydat.monthly &lt;- to.monthly(ydat)
  
         jpegname &lt;- paste(tickers[x], "MonthlyMovingAverage.jpeg", sep="") 
         jpeg( filename=jpegname,height=600, width=1600) 
  
         lineChart(ydat.monthly["1998/"], TA=NULL, name=paste(tickers[x],"Monthly &amp; 10 Month Moving Average"))
         addSMA(10)
         addEMA(10)
  
         dev.off()
      }
  }
  </code></pre>
  
  <p>and called as:</p>
  
  <pre><code>tickers = c("BIIB","ISRG","AIG","FITB","GE","JNY","VIAB","WFM","WMB")
  MovingMonthlyAverageGraph(tickers)
  </code></pre>
  
  <p>only draws the price, but ignores the sma and ema lines.</p>
  
  <p>What am I doing wrong here?  </p>