[text] Real Relative Sector Strength Arrows

Viewer

copydownloadembedprintName: Real Relative Sector Strength Arrows
  1. // This source code is subject to the terms of the MIT License at https://opensource.org/licenses/MIT
  2. // /u/HurlTeaInTheSea v1.0
  3. //
  4. // Credits:
  5. // - Inspired by /u/lilsgymdan
  6. // - RRS calculation by /u/WorkPiece on 12.28.21
  7. // - Concept by u/HSeldon2020
  8.  
  9. //@version=5
  10.  
  11. indicator(shorttitle='RRS/S', title='Real Relative Sector Strength Arrows', overlay=true)
  12.  
  13. var CURRENT_COLOR = #d1d4dc
  14. var BASELINE_COLOR = #b2b5be
  15.  
  16. colorCurrent = input.color(CURRENT_COLOR, title='Current') 
  17. baseline = input.symbol('SPY', title='Baseline', inline='baseline')
  18. colorBaseline = input.color(BASELINE_COLOR, title='', inline='baseline')
  19. src = input(close, title='Source')
  20. periodPC= input.int(12, minval=1, title='Price Chg. Period')
  21. periodATR = input.int(12, minval=1, title='ATR Period')
  22.  
  23. // ===== Sector Symbol Definitions =====
  24. // Note:
  25. // - As of 2022-08-29
  26. // - A symbol may belong in multiple sectors
  27.  
  28. // Communication Services
  29. var sectorName1 = 'Comms'
  30. var sector1 = 'XLC'
  31. var sectorSymbols1 = 'ATVI, CHTR, CMCSA, DIS, DISH, EA, META, FOX, FOXA, GOOG, GOOGL, IPG, LUMN, LYV, MTCH, NFLX, NWS, NWSA, OMC, PARA, T, TMUS, TTWO, TWTR, VZ, WBD'
  32. var color1 = #ffc000
  33.  
  34. // Consumer Discretionary
  35. var sectorName2 = 'CDisc'
  36. var sector2 = 'XLY'
  37. var sectorSymbols2 = 'AAP, AMZN, APTV, AZO, BBWI, BBY, BKNG, BWA, CCL, CMG, CZR, DG, DHI, DLTR, DPZ, DRI, EBAY, ETSY, EXPE, F, GM, GPC, GRMN, HAS, HD, HLT, KMX, LEN, LKQ, LOW, LVS, MAR, MCD, MGM, MHK, NCLH, NKE, NVR, NWL, ORLY, PENN, PHM, POOL, PVH, RCL, RL, ROST, SBUX, TGT, TJX, TPR, TSCO, TSLA, UAA, ULTA, VFC, WHR, WYNN, YUM'
  38. var color2 = #ff0000
  39.  
  40. // Consumer Staples
  41. var sectorName3 = 'CStap'
  42. var sector3 = 'XLP'
  43. var sectorSymbols3 = 'ADM, BF.B, CAG, CHD, CL, CLX, COST, CPB, EL, GIS, HRL, HSY, K, KDP, KHC, KMB, KO, KR, LW, MDLZ, MKC, MNST, MO, PEP, PG, PM, SJM, STZ, SYY, TAP, TSN, WBA, WMT'
  44. var color3 = #0000ff
  45.  
  46. // Energy
  47. var sectorName4 = 'Energy'
  48. var sector4 = 'XLE'
  49. var sectorSymbols4 = 'APA, BKR, COP, CTRA, CVX, DVN, EOG, FANG, HAL, HES, KMI, MPC, MRO, OKE, OXY, PSX, PXD, SLB, VLO, WMB, XOM'
  50. var color4 = #ffff00
  51.  
  52. // Financials
  53. var sectorName5 = 'Fin'
  54. var sector5 = 'XLF'
  55. var sectorSymbols5 = 'AFL, AIG, AIZ, AJG, ALL, AMP, AON, AXP, BAC, BEN, BK, BLK, BRK.B, BRO, C, CB, CBOE, CFG, CINF, CMA, CME, COF, DFS, FDS, FITB, FRC, GL, GS, HBAN, HIG, ICE, IVZ, JPM, KEY, L, LNC, MCO, MET, MKTX, MMC, MS, MSCI, MTB, NDAQ, NTRS, PFG, PGR, PNC, PRU, RE, RF, RJF, SBNY, SCHW, SIVB, SPGI, STT, SYF, TFC, TROW, TRV, USB, WFC, WRB, WTW, ZION'
  56. var color5 = #009940
  57.  
  58. // Health Care
  59. var sectorName6 = 'Health'
  60. var sector6 = 'XLV'
  61. var sectorSymbols6 = 'A, ABBV, ABC, ABMD, ABT, ALGN, AMGN, BAX, BDX, BIIB, BIO, BMY, BSX, CAH, CI, CNC, COO, CRL, CTLT, CVS, DGX, DHR, DVA, DXCM, ELV, EW, GILD, HCA, HOLX, HSIC, HUM, IDXX, ILMN, INCY, IQV, ISRG, JNJ, LH, LLY, MCK, MDT, MOH, MRK, MRNA, MTD, OGN, PFE, PKI, REGN, RMD, STE, SYK, TECH, TFX, TMO, UHS, UNH, VRTX, VTRS, WAT, WST, XRAY, ZBH, ZTS'
  62. var color6 = #f8bbd0
  63.  
  64. // Industrials
  65. var sectorName7 = 'Indus'
  66. var sector7 = 'XLI'
  67. var sectorSymbols7 = 'AAL, ALK, ALLE, AME, AOS, BA, CARR, CAT, CHRW, CMI, CPRT, CSX, CTAS, DAL, DE, DOV, EFX, EMR, ETN, EXPD, FAST, FBHS, FDX, FTV, GD, GE, GNRC, GWW, HII, HON, HWM, IEX, IR, ITW, J, JBHT, JCI, LDOS, LHX, LMT, LUV, MAS, MMM, NDSN, NLSN, NOC, NSC, ODFL, OTIS, PCAR, PH, PNR, PWR, RHI, ROK, ROL, ROP, RSG, RTX, SNA, SWK, TDG, TDY, TT, TXT, UAL, UNP, UPS, URI, VRSK, WAB, WM, XYL'
  68. var color7 = #ff8000
  69.  
  70. // Materials
  71. var sectorName8 = 'Mats'
  72. var sector8 = 'XLB'
  73. var sectorSymbols8 = 'ALB, AMCR, APD, AVY, BALL, CE, CF, CTVA, DD, DOW, ECL, EMN, FCX, FMC, IFF, IP, LIN, LYB, MLM, MOS, NEM, NUE, PKG, PPG, SEE, SHW, VMC, WRK'
  74. var color8 = #801922
  75.  
  76. // Real Estate
  77. var sectorName9 = 'Real'
  78. var sector9 = 'XLRE'
  79. var sectorSymbols9 = 'AMT, ARE, AVB, BXP, CBRE, CCI, CPT, DLR, DRE, EQIX, EQR, ESS, EXR, FRT, HST, IRM, KIM, MAA, O, PEAK, PLD, PSA, REG, SBAC, SPG, UDR, VICI, VNO, VTR, WELL, WY'
  80. var color9 = #8000ff
  81.  
  82. // Technology
  83. var sectorName10 = 'Tech'
  84. var sector10 = 'XLK'
  85. var sectorSymbols10 = 'AAPL, ACN, ADBE, ADI, ADP, ADSK, AKAM, AMAT, AMD, ANET, ANSS, APH, AVGO, BR, CDAY, CDNS, CDW, CRM, CSCO, CTSH, CTXS, DXC, ENPH, EPAM, FFIV, FIS, FISV, FLT, FTNT, GLW, GPN, HPE, HPQ, IBM, INTC, INTU, IT, JKHY, JNPR, KEYS, KLAC, LRCX, MA, MCHP, MPWR, MSFT, MSI, MU, NLOK, NOW, NTAP, NVDA, NXPI, ON, ORCL, PAYC, PAYX, PTC, PYPL, QCOM, QRVO, SEDG, SNPS, STX, SWKS, TEL, TER, TRMB, TXN, TYL, V, VRSN, WDC, ZBRA'
  86. var color10 = #0080ff
  87.  
  88. // Utilities
  89. var sectorName11 = 'Utils'
  90. var sector11 = 'XLU'
  91. var sectorSymbols11 = 'AEE, AEP, AES, ATO, AWK, CEG, CMS, CNP, D, DTE, DUK, ED, EIX, ES, ETR, EVRG, EXC, FE, LNT, NEE, NI, NRG, PEG, PNW, PPL, SO, SRE, WEC, XEL'
  92. var color11 = #00ffff
  93.  
  94. // Semiconductors
  95. var sectorName12 = 'Semis'
  96. var sector12 = 'SMH'
  97. var sectorSymbols12 = 'ADI, AMAT, AMD, ASML, AVGO, CDNS, INTC, KLAC, LRCX, MCHP, MPWR, MRVL, MU, NVDA, NXPI, OLED, ON, QCOM, QRVO, SNPS, STM, SWKS, TER, TSM, TXN'
  98. var color12 = #00ff00
  99.  
  100. // Add New
  101. var sectorName13 = ''
  102. var sector13 = ''
  103. var sectorSymbols13 = ''
  104. var color13 = #2962FF
  105.  
  106. // Add New
  107. var sectorName14 = ''
  108. var sector14 = ''
  109. var sectorSymbols14 = ''
  110. var color14 = #2962FF
  111.  
  112. // Add New
  113. var sectorName15 = ''
  114. var sector15 = ''
  115. var sectorSymbols15 = ''
  116. var color15 = #2962FF
  117.  
  118. // Add New
  119. var sectorName16 = ''
  120. var sector16 = ''
  121. var sectorSymbols16 = ''
  122. var color16 = #2962FF
  123.  
  124. // Add New
  125. var sectorName17 = ''
  126. var sector17 = ''
  127. var sectorSymbols17 = ''
  128. var color17 = #2962FF
  129.  
  130. // Add New
  131. var sectorName18 = ''
  132. var sector18 = ''
  133. var sectorSymbols18 = ''
  134. var color18 = #2962FF
  135.  
  136. // Add New
  137. var sectorName19 = ''
  138. var sector19 = ''
  139. var sectorSymbols19 = ''
  140. var color19 = #2962FF
  141.  
  142. // Add New
  143. var sectorName20 = ''
  144. var sector20 = ''
  145. var sectorSymbols20 = ''
  146. var color20 = #2962FF
  147.  
  148. // ===== Sector Inputs =====
  149.  
  150. var SECTOR_GROUP_NAME = 'Sectors (Check Each to Always Show)'
  151. var SECTOR_SHOW_NAME = ''
  152.  
  153. showAll = input.bool(false, title='Show All', group=SECTOR_GROUP_NAME)
  154.  
  155. c1 = input.color(color1, title='1', group=SECTOR_GROUP_NAME, inline='S1A')
  156. n1 = input.string(sectorName1, title='', group=SECTOR_GROUP_NAME, inline='S1A')
  157. s1 = input.symbol(sector1 , title='', group=SECTOR_GROUP_NAME, inline='S1B')
  158. symbols1 = input.string(sectorSymbols1, title='', group=SECTOR_GROUP_NAME, inline='S1B')
  159. show1 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S1B')
  160.  
  161. c2 = input.color(color2, title='2', group=SECTOR_GROUP_NAME, inline='S2A')
  162. n2 = input.string(sectorName2, title='', group=SECTOR_GROUP_NAME, inline='S2A')
  163. s2 = input.symbol(sector2 , title='', group=SECTOR_GROUP_NAME, inline='S2B')
  164. symbols2 = input.string(sectorSymbols2, title='', group=SECTOR_GROUP_NAME, inline='S2B')
  165. show2 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S2B')
  166.  
  167. c3 = input.color(color3, title='3', group=SECTOR_GROUP_NAME, inline='S3A')
  168. n3 = input.string(sectorName3, title='', group=SECTOR_GROUP_NAME, inline='S3A')
  169. s3 = input.symbol(sector3 , title='', group=SECTOR_GROUP_NAME, inline='S3B')
  170. symbols3 = input.string(sectorSymbols3, title='', group=SECTOR_GROUP_NAME, inline='S3B')
  171. show3 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S3B')
  172.  
  173. c4 = input.color(color4, title='4', group=SECTOR_GROUP_NAME, inline='S4A')
  174. n4 = input.string(sectorName4, title='', group=SECTOR_GROUP_NAME, inline='S4A')
  175. s4 = input.symbol(sector4 , title='', group=SECTOR_GROUP_NAME, inline='S4B')
  176. symbols4 = input.string(sectorSymbols4, title='', group=SECTOR_GROUP_NAME, inline='S4B')
  177. show4 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S4B')
  178.  
  179. c5 = input.color(color5, title='5', group=SECTOR_GROUP_NAME, inline='S5A')
  180. n5 = input.string(sectorName5, title='', group=SECTOR_GROUP_NAME, inline='S5A')
  181. s5 = input.symbol(sector5 , title='', group=SECTOR_GROUP_NAME, inline='S5B')
  182. symbols5 = input.string(sectorSymbols5, title='', group=SECTOR_GROUP_NAME, inline='S5B')
  183. show5 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S5B')
  184.  
  185. c6 = input.color(color6, title='6', group=SECTOR_GROUP_NAME, inline='S6A')
  186. n6 = input.string(sectorName6, title='', group=SECTOR_GROUP_NAME, inline='S6A')
  187. s6 = input.symbol(sector6 , title='', group=SECTOR_GROUP_NAME, inline='S6B')
  188. symbols6 = input.string(sectorSymbols6, title='', group=SECTOR_GROUP_NAME, inline='S6B')
  189. show6 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S6B')
  190.  
  191. c7 = input.color(color7, title='7', group=SECTOR_GROUP_NAME, inline='S7A')
  192. n7 = input.string(sectorName7, title='', group=SECTOR_GROUP_NAME, inline='S7A')
  193. s7 = input.symbol(sector7 , title='', group=SECTOR_GROUP_NAME, inline='S7B')
  194. symbols7 = input.string(sectorSymbols7, title='', group=SECTOR_GROUP_NAME, inline='S7B')
  195. show7 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S7B')
  196.  
  197. c8 = input.color(color8, title='8', group=SECTOR_GROUP_NAME, inline='S8A')
  198. n8 = input.string(sectorName8, title='', group=SECTOR_GROUP_NAME, inline='S8A')
  199. s8 = input.symbol(sector8 , title='', group=SECTOR_GROUP_NAME, inline='S8B')
  200. symbols8 = input.string(sectorSymbols8, title='', group=SECTOR_GROUP_NAME, inline='S8B')
  201. show8 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S8B')
  202.  
  203. c9 = input.color(color9, title='9', group=SECTOR_GROUP_NAME, inline='S9A')
  204. n9 = input.string(sectorName9, title='', group=SECTOR_GROUP_NAME, inline='S9A')
  205. s9 = input.symbol(sector9 , title='', group=SECTOR_GROUP_NAME, inline='S9B')
  206. symbols9 = input.string(sectorSymbols9, title='', group=SECTOR_GROUP_NAME, inline='S9B')
  207. show9 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S9B')
  208.  
  209. c10 = input.color(color10, title='10', group=SECTOR_GROUP_NAME, inline='S10A')
  210. n10 = input.string(sectorName10, title='', group=SECTOR_GROUP_NAME, inline='S10A')
  211. s10 = input.symbol(sector10, title='', group=SECTOR_GROUP_NAME, inline='S10B')
  212. symbols10 = input.string(sectorSymbols10, title='', group=SECTOR_GROUP_NAME, inline='S10B')
  213. show10 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S10B')
  214.  
  215. c11 = input.color(color11, title='11', group=SECTOR_GROUP_NAME, inline='S11A')
  216. n11 = input.string(sectorName11, title='', group=SECTOR_GROUP_NAME, inline='S11A')
  217. s11 = input.symbol(sector11, title='', group=SECTOR_GROUP_NAME, inline='S11B')
  218. symbols11 = input.string(sectorSymbols11, title='', group=SECTOR_GROUP_NAME, inline='S11B')
  219. show11 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S11B')
  220.  
  221. c12 = input.color(color12, title='12', group=SECTOR_GROUP_NAME, inline='S12A')
  222. n12 = input.string(sectorName12, title='', group=SECTOR_GROUP_NAME, inline='S12A')
  223. s12 = input.symbol(sector12, title='', group=SECTOR_GROUP_NAME, inline='S12B')
  224. symbols12 = input.string(sectorSymbols12, title='', group=SECTOR_GROUP_NAME, inline='S12B')
  225. show12 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S12B')
  226.  
  227. c13 = input.color(color13, title='13', group=SECTOR_GROUP_NAME, inline='S13A')
  228. n13 = input.string(sectorName13, title='', group=SECTOR_GROUP_NAME, inline='S13A')
  229. s13 = input.symbol(sector13, title='', group=SECTOR_GROUP_NAME, inline='S13B')
  230. symbols13 = input.string(sectorSymbols13, title='', group=SECTOR_GROUP_NAME, inline='S13B')
  231. show13 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S13B')
  232.  
  233. c14 = input.color(color14, title='14', group=SECTOR_GROUP_NAME, inline='S14A')
  234. n14 = input.string(sectorName14, title='', group=SECTOR_GROUP_NAME, inline='S14A')
  235. s14 = input.symbol(sector14, title='', group=SECTOR_GROUP_NAME, inline='S14B')
  236. symbols14 = input.string(sectorSymbols14, title='', group=SECTOR_GROUP_NAME, inline='S14B')
  237. show14 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S14B')
  238.  
  239. c15 = input.color(color15, title='15', group=SECTOR_GROUP_NAME, inline='S15A')
  240. n15 = input.string(sectorName15, title='', group=SECTOR_GROUP_NAME, inline='S15A')
  241. s15 = input.symbol(sector15, title='', group=SECTOR_GROUP_NAME, inline='S15B')
  242. symbols15 = input.string(sectorSymbols15, title='', group=SECTOR_GROUP_NAME, inline='S15B')
  243. show15 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S15B')
  244.  
  245. c16 = input.color(color16, title='16', group=SECTOR_GROUP_NAME, inline='S16A')
  246. n16 = input.string(sectorName16, title='', group=SECTOR_GROUP_NAME, inline='S16A')
  247. s16 = input.symbol(sector16, title='', group=SECTOR_GROUP_NAME, inline='S16B')
  248. symbols16 = input.string(sectorSymbols16, title='', group=SECTOR_GROUP_NAME, inline='S16B')
  249. show16 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S16B')
  250.  
  251. c17 = input.color(color17, title='17', group=SECTOR_GROUP_NAME, inline='S17A')
  252. n17 = input.string(sectorName17, title='', group=SECTOR_GROUP_NAME, inline='S17A')
  253. s17 = input.symbol(sector17, title='', group=SECTOR_GROUP_NAME, inline='S17B')
  254. symbols17 = input.string(sectorSymbols17, title='', group=SECTOR_GROUP_NAME, inline='S17B')
  255. show17 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S17B')
  256.  
  257. c18 = input.color(color18, title='18', group=SECTOR_GROUP_NAME, inline='S18A')
  258. n18 = input.string(sectorName18, title='', group=SECTOR_GROUP_NAME, inline='S18A')
  259. s18 = input.symbol(sector18, title='', group=SECTOR_GROUP_NAME, inline='S18B')
  260. symbols18 = input.string(sectorSymbols18, title='', group=SECTOR_GROUP_NAME, inline='S18B')
  261. show18 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S18B')
  262.  
  263. c19 = input.color(color19, title='19', group=SECTOR_GROUP_NAME, inline='S19A')
  264. n19 = input.string(sectorName19, title='', group=SECTOR_GROUP_NAME, inline='S19A')
  265. s19 = input.symbol(sector19, title='', group=SECTOR_GROUP_NAME, inline='S19B')
  266. symbols19 = input.string(sectorSymbols19, title='', group=SECTOR_GROUP_NAME, inline='S19B')
  267. show19 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S19B')
  268.  
  269. c20 = input.color(color20, title='20', group=SECTOR_GROUP_NAME, inline='S20A')
  270. n20 = input.string(sectorName20, title='', group=SECTOR_GROUP_NAME, inline='S20A')
  271. s20 = input.symbol(sector20, title='', group=SECTOR_GROUP_NAME, inline='S20B')
  272. symbols20 = input.string(sectorSymbols20, title='', group=SECTOR_GROUP_NAME, inline='S20B')
  273. show20 = input.bool(false, title=SECTOR_SHOW_NAME, group=SECTOR_GROUP_NAME, inline='S20B')
  274.  
  275. // ===== Utility Functions =====
  276.  
  277. isSymbolInSector(string sectorSymbols) =>
  278.     // replace all commas, pluses and minuses with whitespace then split by whitespace
  279.     symbols = str.split(str.replace_all(str.replace_all(str.replace_all(sectorSymbols, ',', ' '), '+', ' '), '-', ' '), ' ')
  280.     array.indexof(symbols, syminfo.ticker) >= 0
  281.  
  282. // ===== RRS =====
  283. // NOTE:
  284. // - RRS is the powerIndex of the current symbol minus the powerIndex of the baseline/sector
  285. // - A higher (lower) powerIndex to the baseline/sector means relative strength (weakness)
  286. // - Because we're plotting the symbol, baseline and sector together, we show each powerIndex instead of RRS
  287.  
  288. calcPowerIndex(series float src, series float atr) =>
  289.     symbolRollingMove = src - src[periodPC]
  290.     symbolPowerIndex = symbolRollingMove / atr[1]
  291.  
  292. // current + baseline
  293. powerIndex = calcPowerIndex(close, ta.atr(periodATR))
  294. [src0, atr0] = request.security(symbol=baseline,  timeframe="", expression=[src, ta.atr(periodATR)])
  295. powerIndex0 = calcPowerIndex(src0, atr0)
  296.  
  297. // sectors
  298. var plot1  = str.length(s1) > 0 and (showAll or show1  or isSymbolInSector(symbols1))
  299. [src1,  atr1 ] = request.security(symbol=s1,  timeframe="", expression=[src, ta.atr(periodATR)])
  300. powerIndex1  = calcPowerIndex(plot1  ? src1  : na, plot1  ? atr1  : na)
  301.  
  302. var plot2  = str.length(s2) > 0 and (showAll or show2  or isSymbolInSector(symbols2))
  303. [src2,  atr2 ] = request.security(symbol=s2,  timeframe="", expression=[src, ta.atr(periodATR)])
  304. powerIndex2  = calcPowerIndex(plot2  ? src2  : na, plot2  ? atr2  : na)
  305.  
  306. var plot3  = str.length(s3) > 0 and (showAll or show3  or isSymbolInSector(symbols3))
  307. [src3,  atr3 ] = request.security(symbol=s3,  timeframe="", expression=[src, ta.atr(periodATR)])
  308. powerIndex3  = calcPowerIndex(plot3  ? src3  : na, plot3  ? atr3  : na)
  309.  
  310. var plot4  = str.length(s4) > 0 and (showAll or show4  or isSymbolInSector(symbols4))
  311. [src4,  atr4 ] = request.security(symbol=s4,  timeframe="", expression=[src, ta.atr(periodATR)])
  312. powerIndex4  = calcPowerIndex(plot4  ? src4  : na, plot4  ? atr4  : na)
  313.  
  314. var plot5  = str.length(s5) > 0 and (showAll or show5  or isSymbolInSector(symbols5))
  315. [src5,  atr5 ] = request.security(symbol=s5,  timeframe="", expression=[src, ta.atr(periodATR)])
  316. powerIndex5  = calcPowerIndex(plot5  ? src5  : na, plot5  ? atr5  : na)
  317.  
  318. var plot6  = str.length(s6) > 0 and (showAll or show6  or isSymbolInSector(symbols6))
  319. [src6,  atr6 ] = request.security(symbol=s6,  timeframe="", expression=[src, ta.atr(periodATR)])
  320. powerIndex6  = calcPowerIndex(plot6  ? src6  : na, plot6  ? atr6  : na)
  321.  
  322. var plot7  = str.length(s7) > 0 and (showAll or show7  or isSymbolInSector(symbols7))
  323. [src7,  atr7 ] = request.security(symbol=s7,  timeframe="", expression=[src, ta.atr(periodATR)])
  324. powerIndex7  = calcPowerIndex(plot7  ? src7  : na, plot7  ? atr7  : na)
  325.  
  326. var plot8  = str.length(s8) > 0 and (showAll or show8  or isSymbolInSector(symbols8))
  327. [src8,  atr8 ] = request.security(symbol=s8,  timeframe="", expression=[src, ta.atr(periodATR)])
  328. powerIndex8  = calcPowerIndex(plot8  ? src8  : na, plot8  ? atr8  : na)
  329.  
  330. var plot9  = str.length(s9) > 0 and (showAll or show9  or isSymbolInSector(symbols9))
  331. [src9,  atr9 ] = request.security(symbol=s9,  timeframe="", expression=[src, ta.atr(periodATR)])
  332. powerIndex9  = calcPowerIndex(plot9  ? src9  : na, plot9  ? atr9  : na)
  333.  
  334. var plot10 = str.length(s10) > 0 and (showAll or show10 or isSymbolInSector(symbols10))
  335. [src10, atr10] = request.security(symbol=s10, timeframe="", expression=[src, ta.atr(periodATR)])
  336. powerIndex10 = calcPowerIndex(plot10 ? src10 : na, plot10 ? atr10 : na)
  337.  
  338. var plot11 = str.length(s11) > 0 and (showAll or show11 or isSymbolInSector(symbols11))
  339. [src11, atr11] = request.security(symbol=s11, timeframe="", expression=[src, ta.atr(periodATR)])
  340. powerIndex11 = calcPowerIndex(plot11 ? src11 : na, plot11 ? atr11 : na)
  341.  
  342. var plot12 = str.length(s12) > 0 and (showAll or show12 or isSymbolInSector(symbols12))
  343. [src12, atr12] = request.security(symbol=s12, timeframe="", expression=[src, ta.atr(periodATR)])
  344. powerIndex12 = calcPowerIndex(plot12 ? src12 : na, plot12 ? atr12 : na)
  345.  
  346. var plot13 = str.length(s13) > 0 and (showAll or show13 or isSymbolInSector(symbols13))
  347. [src13, atr13] = request.security(symbol=s13, timeframe="", expression=[src, ta.atr(periodATR)])
  348. powerIndex13 = calcPowerIndex(plot13 ? src13 : na, plot13 ? atr13 : na)
  349.  
  350. var plot14 = str.length(s14) > 0 and (showAll or show14 or isSymbolInSector(symbols14))
  351. [src14, atr14] = request.security(symbol=s14, timeframe="", expression=[src, ta.atr(periodATR)])
  352. powerIndex14 = calcPowerIndex(plot14 ? src14 : na, plot14 ? atr14 : na)
  353.  
  354. var plot15 = str.length(s15) > 0 and (showAll or show15 or isSymbolInSector(symbols15))
  355. [src15, atr15] = request.security(symbol=s15, timeframe="", expression=[src, ta.atr(periodATR)])
  356. powerIndex15 = calcPowerIndex(plot15 ? src15 : na, plot15 ? atr15 : na)
  357.  
  358. var plot16 = str.length(s16) > 0 and (showAll or show16 or isSymbolInSector(symbols16))
  359. [src16, atr16] = request.security(symbol=s16, timeframe="", expression=[src, ta.atr(periodATR)])
  360. powerIndex16 = calcPowerIndex(plot16 ? src16 : na, plot16 ? atr16 : na)
  361.  
  362. var plot17 = str.length(s17) > 0 and (showAll or show17 or isSymbolInSector(symbols17))
  363. [src17, atr17] = request.security(symbol=s17, timeframe="", expression=[src, ta.atr(periodATR)])
  364. powerIndex17 = calcPowerIndex(plot17 ? src17 : na, plot17 ? atr17 : na)
  365.  
  366. var plot18 = str.length(s18) > 0 and (showAll or show18 or isSymbolInSector(symbols18))
  367. [src18, atr18] = request.security(symbol=s18, timeframe="", expression=[src, ta.atr(periodATR)])
  368. powerIndex18 = calcPowerIndex(plot18 ? src18 : na, plot18 ? atr18 : na)
  369.  
  370. var plot19 = str.length(s19) > 0 and (showAll or show19 or isSymbolInSector(symbols19))
  371. [src19, atr19] = request.security(symbol=s19, timeframe="", expression=[src, ta.atr(periodATR)])
  372. powerIndex19 = calcPowerIndex(plot19 ? src19 : na, plot19 ? atr19 : na)
  373.  
  374. var plot20 = str.length(s20) > 0 and (showAll or show20 or isSymbolInSector(symbols20))
  375. [src20, atr20] = request.security(symbol=s20, timeframe="", expression=[src, ta.atr(periodATR)])
  376. powerIndex20 = calcPowerIndex(plot20 ? src20 : na, plot20 ? atr20 : na)
  377.  
  378. // ===== Visuals =====
  379.  
  380. // current + baseline
  381.  
  382. // color.new() to disable style color customization because changing colors there won't affect sector tags
  383. //plot(powerIndex, title='Current', color=color.new(colorCurrent, 1), linewidth=2)
  384. //plot(powerIndex0, title='Baseline', color=colorBaseline)
  385. //hline(0, title="Center", color=color.gray, linestyle=hline.style_dotted)
  386.  
  387. // sectors
  388. //plot(powerIndex1,  title='S1',  color=c1)
  389. //plot(powerIndex2,  title='S2',  color=c2)
  390. //plot(powerIndex3,  title='S3',  color=c3)
  391. //plot(powerIndex4,  title='S4',  color=c4)
  392. //plot(powerIndex5,  title='S5',  color=c5)
  393. //plot(powerIndex6,  title='S6',  color=c6)
  394. //plot(powerIndex7,  title='S7',  color=c7)
  395. //plot(powerIndex8,  title='S8',  color=c8)
  396. //plot(powerIndex9,  title='S9',  color=c9)
  397. //plot(powerIndex10, title='S10', color=c10)
  398. //plot(powerIndex11, title='S11', color=c11)
  399. //plot(powerIndex12, title='S12', color=c12)
  400. //plot(powerIndex13, title='S13', color=c13)
  401. //plot(powerIndex14, title='S14', color=c14)
  402. //plot(powerIndex15, title='S15', color=c15)
  403. //plot(powerIndex16, title='S16', color=c16)
  404. //plot(powerIndex17, title='S17', color=c17)
  405. //plot(powerIndex18, title='S18', color=c18)
  406. //plot(powerIndex19, title='S19', color=c19)
  407. //plot(powerIndex20, title='S20', color=c20)
  408.  
  409. // ===== Visuals (Sector Tags) =====
  410.  
  411. // sectors
  412. var string[] activeSectors = array.new_string()
  413. var color[] activeColors = array.new_color()
  414. if barstate.isfirst
  415.     if plot1
  416.         array.push(activeSectors, str.length(n1) > 0 ? n1 : syminfo.ticker(s1))
  417.         array.push(activeColors, c1)
  418.     if plot2
  419.         array.push(activeSectors, str.length(n2) > 0 ? n2 : syminfo.ticker(s2))
  420.         array.push(activeColors, c2)
  421.     if plot3
  422.         array.push(activeSectors, str.length(n3) > 0 ? n3 : syminfo.ticker(s3))
  423.         array.push(activeColors, c3)
  424.     if plot4
  425.         array.push(activeSectors, str.length(n4) > 0 ? n4 : syminfo.ticker(s4))
  426.         array.push(activeColors, c4)
  427.     if plot5
  428.         array.push(activeSectors, str.length(n5) > 0 ? n5 : syminfo.ticker(s5))
  429.         array.push(activeColors, c5)
  430.     if plot6
  431.         array.push(activeSectors, str.length(n6) > 0 ? n6 : syminfo.ticker(s6))
  432.         array.push(activeColors, c6)
  433.     if plot7
  434.         array.push(activeSectors, str.length(n7) > 0 ? n7 : syminfo.ticker(s7))
  435.         array.push(activeColors, c7)
  436.     if plot8
  437.         array.push(activeSectors, str.length(n8) > 0 ? n8 : syminfo.ticker(s8))
  438.         array.push(activeColors, c8)
  439.     if plot9
  440.         array.push(activeSectors, str.length(n9) > 0 ? n9 : syminfo.ticker(s9))
  441.         array.push(activeColors, c9)
  442.     if plot10
  443.         array.push(activeSectors, str.length(n10) > 0 ? n10 : syminfo.ticker(s10))
  444.         array.push(activeColors, c10)
  445.     if plot11
  446.         array.push(activeSectors, str.length(n11) > 0 ? n11 : syminfo.ticker(s11))
  447.         array.push(activeColors, c11)
  448.     if plot12
  449.         array.push(activeSectors, str.length(n12) > 0 ? n12 : syminfo.ticker(s12))
  450.         array.push(activeColors, c12)
  451.     if plot13
  452.         array.push(activeSectors, str.length(n13) > 0 ? n13 : syminfo.ticker(s13))
  453.         array.push(activeColors, c13)
  454.     if plot14
  455.         array.push(activeSectors, str.length(n14) > 0 ? n14 : syminfo.ticker(s14))
  456.         array.push(activeColors, c14)
  457.     if plot15
  458.         array.push(activeSectors, str.length(n15) > 0 ? n15 : syminfo.ticker(s15))
  459.         array.push(activeColors, c15)
  460.     if plot16
  461.         array.push(activeSectors, str.length(n16) > 0 ? n16 : syminfo.ticker(s16))
  462.         array.push(activeColors, c16)
  463.     if plot17
  464.         array.push(activeSectors, str.length(n17) > 0 ? n17 : syminfo.ticker(s17))
  465.         array.push(activeColors, c17)
  466.     if plot18
  467.         array.push(activeSectors, str.length(n18) > 0 ? n18 : syminfo.ticker(s18))
  468.         array.push(activeColors, c18)
  469.     if plot19
  470.         array.push(activeSectors, str.length(n19) > 0 ? n19 : syminfo.ticker(s19))
  471.         array.push(activeColors, c19)
  472.     if plot20
  473.         array.push(activeSectors, str.length(n20) > 0 ? n20 : syminfo.ticker(s20))
  474.         array.push(activeColors, c20)
  475.  
  476. var sectorTag = table.new(position=position.bottom_right, columns=array.size(activeSectors), rows=1, border_width=0)
  477. if barstate.isfirst
  478.     int i = 0
  479.     while i < array.size(activeSectors)
  480.         table.cell(sectorTag, column=i, row=0, text=array.get(activeSectors, i), text_color=array.get(activeColors, i))
  481.         i := i+1
  482.         
  483.  
  484.  
  485. //BarColor Plot: 
  486.  
  487. long1 = powerIndex > powerIndex0 and powerIndex1 > powerIndex0 and powerIndex > powerIndex1 and isSymbolInSector(symbols1)
  488. short1 = powerIndex < powerIndex0 and powerIndex1 < powerIndex0 and powerIndex < powerIndex1 and isSymbolInSector(symbols1)
  489.  
  490. long2 = powerIndex > powerIndex0 and powerIndex2 > powerIndex0 and powerIndex > powerIndex2 and isSymbolInSector(symbols2)
  491. short2 = powerIndex < powerIndex0 and powerIndex2 < powerIndex0 and powerIndex < powerIndex2 and isSymbolInSector(symbols2)
  492.  
  493. long3 = powerIndex > powerIndex0 and powerIndex3 > powerIndex0 and powerIndex > powerIndex3 and isSymbolInSector(symbols3)
  494. short3 = powerIndex < powerIndex0 and powerIndex3 < powerIndex0 and powerIndex < powerIndex3 and isSymbolInSector(symbols3)
  495.  
  496. long4 = powerIndex > powerIndex0 and powerIndex4 > powerIndex0 and powerIndex > powerIndex4 and isSymbolInSector(symbols4)
  497. short4 = powerIndex < powerIndex0 and powerIndex4 < powerIndex0 and powerIndex < powerIndex4 and isSymbolInSector(symbols4)
  498.  
  499. long5 = powerIndex > powerIndex0 and powerIndex5 > powerIndex0 and powerIndex > powerIndex5 and isSymbolInSector(symbols5)
  500. short5 = powerIndex < powerIndex0 and powerIndex5 < powerIndex0 and powerIndex < powerIndex5 and isSymbolInSector(symbols5)
  501.  
  502. long6 = powerIndex > powerIndex0 and powerIndex6 > powerIndex0 and powerIndex > powerIndex6 and isSymbolInSector(symbols6)
  503. short6 = powerIndex < powerIndex0 and powerIndex6 < powerIndex0 and powerIndex < powerIndex6 and isSymbolInSector(symbols6)
  504.  
  505. long7 = powerIndex > powerIndex0 and powerIndex7 > powerIndex0 and powerIndex > powerIndex7 and isSymbolInSector(symbols7)
  506. short7 = powerIndex < powerIndex0 and powerIndex7 < powerIndex0 and powerIndex < powerIndex7 and isSymbolInSector(symbols7)
  507.  
  508. long8 = powerIndex > powerIndex0 and powerIndex8 > powerIndex0 and powerIndex > powerIndex8 and isSymbolInSector(symbols8)
  509. short8 = powerIndex < powerIndex0 and powerIndex8 < powerIndex0 and powerIndex < powerIndex8 and isSymbolInSector(symbols8)
  510.  
  511. long9 = powerIndex > powerIndex0 and powerIndex9 > powerIndex0 and powerIndex > powerIndex9 and isSymbolInSector(symbols9)
  512. short9 = powerIndex < powerIndex0 and powerIndex9 < powerIndex0 and powerIndex < powerIndex9 and isSymbolInSector(symbols9)
  513.  
  514. long10 = powerIndex > powerIndex0 and powerIndex10 > powerIndex0 and powerIndex > powerIndex10 and isSymbolInSector(symbols10)
  515. short10 = powerIndex < powerIndex0 and powerIndex10 < powerIndex0 and powerIndex < powerIndex10 and isSymbolInSector(symbols10)
  516.  
  517. long11 = powerIndex > powerIndex0 and powerIndex11 > powerIndex0 and powerIndex > powerIndex11 and isSymbolInSector(symbols11)
  518. short11 = powerIndex < powerIndex0 and powerIndex11 < powerIndex0 and powerIndex < powerIndex11 and isSymbolInSector(symbols11)
  519.  
  520. long12 = powerIndex > powerIndex0 and powerIndex12 > powerIndex0 and powerIndex > powerIndex12 and isSymbolInSector(symbols12)
  521. short12 = powerIndex < powerIndex0 and powerIndex2 < powerIndex0 and powerIndex < powerIndex2 and isSymbolInSector(symbols2)
  522.  
  523.  
  524.  
  525.  
  526.  
  527. //barcolor(long1 or long2 or long3 or long4 or long5 or long6 or long7 or long8 or long9 or long10 or long11 or long12 ? color.yellow : short1 or short2 or short3 or short4 or short5 or short6 or short7 or short8 or short9 or short10 or short11 or short12 ? color.purple: na)
  528.  
  529. vwap = ta.vwap
  530. vwapup = close > ta.vwap
  531. vwapdown = close < ta.vwap
  532.  
  533.  
  534.  
  535.  
  536. plotshape((long1 or long2 or long3 or long4 or long5 or long6 or long7 or long8 or long9 or long10 or long11 or long12) and vwapup, "Long", shape.arrowup, location.belowbar, color.green)
  537. plotshape((short1 or short2 or short3 or short4 or short5 or short6 or short7 or short8 or short9 or short10 or short11 or short12) and vwapdown, "Short", shape.arrowdown, location.abovebar, color.red)
  538.  
  539.         
  540. //plotshape("Long", shape.arrowup, location.belowbar, color.green)
  541. //plotshape("Short", shape.arrowdown, location.abovebar, color.red)

Editor

You can edit this paste and save as new:


File Description
  • Real Relative Sector Strength Arrows
  • Paste Code
  • 02 Dec-2022
  • 28.65 Kb
You can Share it: