Skip to content

Instantly share code, notes, and snippets.

@ShivamPsit
Last active July 20, 2020 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShivamPsit/3ff4fa6f04ba2041ad4f639989d9d678 to your computer and use it in GitHub Desktop.
Save ShivamPsit/3ff4fa6f04ba2041ad4f639989d9d678 to your computer and use it in GitHub Desktop.
Stock_Relative_Strength
//@version=4
study("Relative Strength", shorttitle="RS",resolution = "")
comparativeTickerId = input("CNX500", type=input.symbol, title="Comparative Symbol")
comparativeSectorId = input("CNXIT", type=input.symbol, title="Sector Symbol")
lenght = input(50, type=input.integer, minval=1, title="Period")
showMA_1 = input(defval=true, type=input.bool, title="Nifty_RS_MA")
showMA_2 = input(defval=true, type=input.bool, title="Sector_RS_MA")
showres = input(defval=false, type=input.bool, title="Show RS")
showsecres = input(defval=false, type=input.bool, title="Show Sector RS")
lenghtMA_1 = input(5, type=input.integer, minval=1, title="Nifty_RS_MA")
lenghtMA_2 = input(5, type=input.integer, minval=1, title="Sector_RS_MA")
baseSymbol = security(syminfo.tickerid, timeframe.period, close)
comparativeSymbol = security(comparativeTickerId, timeframe.period, close)
comparativeSectorSymbol = security(comparativeSectorId, timeframe.period, close)
hline(0, color=color.black, linestyle=hline.style_solid)
res = ((baseSymbol / baseSymbol[lenght]) /
(comparativeSymbol / comparativeSymbol[lenght])) -1
resSec = ((baseSymbol / baseSymbol[lenght]) /
(comparativeSectorSymbol / comparativeSectorSymbol[lenght])) -1
plot(showres ? res : na, title="RS", color=#1155CC,style=plot.style_line, linewidth=2)
plot(showsecres ? resSec : na, title="Sec_RS", color=#1155CC,style=plot.style_line, linewidth=2)
ema_1 = sma(res, lenghtMA_1)
ema_2 = ema(resSec, lenghtMA_2)
plot(showMA_1 ? ema_1 : na,title="Nifty_MA", color=color.black, linewidth=2)
plot(showMA_2 ? ema_2 : na, title="Sector_MA", color=color.red, linewidth=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment