title: How to find Support/Resistance Levels using R
body: <p>I have not found any good answers on how to go about finding Support/Resistance levels in R. Essentially I would like clusters/areas or pivots where the stock is consolidating, but have found it difficult to do so. </p>
  
  <pre><code># loads quatmod &amp; xts
  library("quantmod")
  # Retrive 'ESSI' TICKER OHLCV data
  STOCK = getSymbols("ESSI",auto.assign = FALSE)
  # last observation carried formward / facilitates NAs
  STOCK &lt;- reclass(apply(STOCK,2,na.locf),match.to=STOCK)
  
  # To be used as a rolling window
  K=20
  # Find MAX for Each Open, High, Low, Close Column &amp; merge them
  MAX &lt;- merge.xts(rollmax(Op(STOCK), k=K, na.pad=TRUE),rollmax(Hi(STOCK), k=K, na.pad=TRUE),rollmax(Lo(STOCK), k=K, na.pad=TRUE),rollmax(Cl(STOCK), k=K, na.pad=TRUE))
  # Find the mean of each MAX row
  MAX &lt;- na.locf(reclass(apply(MAX,1,mean),match.to=MAX))
  </code></pre>
  
  <p>I would do the same for the Low's but I think I would be better off going about using <code>DonchianChannel()</code> but it is not what I want... The output should return something similar to FinViz's :</p>
  
  <p><a href="https://i.stack.imgur.com/RVOWB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/RVOWB.png" alt="FINVIZ"></a></p>