title: Error invalid time series parameters specified - in backtesting R script
body: <p>I have created this backtesting script and its executing but has a minor problem.</p>
  
  <pre><code>library(quantmod) 
  library(PerformanceAnalytics)
  tickers = 'AMZN'
  symbol = getSymbols(tickers,from="2014-01-01",auto.assign=F)
  head(symbol)
  prices=Cl(symbol)
  sma.fast=SMA(prices, 10)
  sma.slow=SMA(prices, 20)
  buy.signal = ifelse((sma.fast&gt; sma.slow), 1, NA)
  sell.signal=ifelse((sma.fast&lt; sma.slow), -1, NA)
  position=rowSums(cbind(buy.signal,sell.signal),na.rm=TRUE)
  myReturn &lt;- lag(position) * dailyReturn(symbol)
  
  charts.PerformanceSummary(cbind(dailyReturn(symbol),myReturn))
  
  Performance &lt;- function(x) {
  
    cumRetx = Return.cumulative(x)
    annRetx = Return.annualized(x, scale=252)
    sharpex = SharpeRatio.annualized(x, scale=252) 
    winpctx = length(x[x &gt; 0])/length(x[x != 0])
    annSDx = sd.annualized(x, scale=252)
    DDs &lt;- findDrawdowns(x)
    maxDDx = min(DDs$return)
    maxLx = max(DDs$length)
  
    Perf = c(cumRetx, annRetx, sharpex, winpctx, annSDx, maxDDx, maxLx)
    names(Perf) = c("Cumulative Return", "Annual Return","Annualized Sharpe Ratio",
                    "Win %","Annualized Volatility", "Maximum Drawdown", "Max Length Drawdown")
    return(Perf)
  }
  cbind(STRAT=Performance(myReturn),BMK=Performance(dailyReturn(symbol)))
  </code></pre>
  
  <p>when executed this script is showing this error</p>
  
  <pre><code>Error in `[.xts`(x, x &gt; 0) : invalid time series parameters specified
  </code></pre>
  
  <p>I am able to zero in the problem line and its is while calculating <code>winpctx = length(x[x &gt; 0])/length(x[x != 0])</code> this problem occurs.</p>
  
  <p>How to solve this error.</p>
  
  <p>P.S. <strong>Performance()</strong> is taken from a website</p>