8

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.

# loads quatmod & xts
library("quantmod")
# Retrive 'ESSI' TICKER OHLCV data
STOCK = getSymbols("ESSI",auto.assign = FALSE)
# last observation carried formward / facilitates NAs
STOCK <- 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 & merge them
MAX <- 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 <- na.locf(reclass(apply(MAX,1,mean),match.to=MAX))

I would do the same for the Low's but I think I would be better off going about using DonchianChannel() but it is not what I want... The output should return something similar to FinViz's :

FINVIZ

Rime
  • 912
  • 2
  • 11
  • 39
  • 5
    If you don't want a variation of `DonchianChannel`, how do you want to quantitatively define your "support/resistance" levels? What you're asking for can mean any number of things. Presume you don't mean those lines in your chart you posted there, because they are just SMAs, easily added with TTR's `SMA` function? – FXQuantTrader Dec 28 '16 at 11:39
  • @FXQuantTrader I meant the support/resistance level (purple horizontal line). – Rime Mar 08 '17 at 17:07
  • And how do you define these levels concretely? Define the algorithm – FXQuantTrader Mar 09 '17 at 14:17
  • Thats what I don't know because typically people will just draw them onto the chart. But there has to be a mathematical way. I dont think the referenced site has time to draw the lines on every chart. – Rime Mar 09 '17 at 17:05

1 Answers1

1

You could apply a swing filter such as TTR's ZigZag function. Identifying reversals this way seems like a better way to go than Donchian channels and you can define support / resistance as levels where the reversals tend to cluster.

Jay
  • 193
  • 7