Advertisement
--SubZer0--

QuickCheck For TradingView - v1.5

Nov 21st, 2022 (edited)
1,373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 33.65 KB | Source Code | 0 0
  1. //@version=5
  2. //###########################################################################
  3. //#QuickCheck - Automatically Validate Basic Criteria For Stock Selection
  4. //#Creator: u/--SubZer0--
  5. //#Version: 1.5
  6. //#Last Updated: 11.20.22
  7.  
  8. //#Attributtion:
  9. //#RealRelativeStrength: u/WorkPiece
  10. //#RelativeVolume: u/HurlTeaInTheSea
  11. //#############################################################################
  12.  
  13.  
  14. indicator(title="QuickCheck", overlay=true)
  15.  
  16. //----------------------------------------------
  17. //User Configuration
  18. var string G1 = "Display"
  19. string  tableYposInput = input.string("bottom", "Indicator position...........", inline = "1", options = ["top", "middle", "bottom"], group = G1)
  20. string  tableXposInput = input.string("left", "", inline = "1", options = ["left", "center", "right"], group = G1)
  21.  
  22. string symbolUpString = input.string("▲", title="Symbol Prefix.............    ↑", inline = "2", group=G1)
  23. var symbolDownString = input.string("▼", title=" ↓", inline = "2", group=G1)
  24.  
  25. StockUpColor = input.color(#00ff00, title="Ticker Color............... ↑", inline = "3", group=G1)
  26. StockDownColor = input.color(color.red, title=" ↓", inline = "3", group=G1)
  27.  
  28. meetCriteriaStateColor  = input.color(#00feff, title="Meets Criteria?........... Y", inline = "4", group=G1)
  29. doesNotMeetCriteriaStateColor = input.color(#e6e6e6, title="N", inline = "4", group=G1)
  30. warningStateColor = input.color(#ffeb3b, title="Warn", inline = "4", group=G1)
  31.  
  32. TableBorderColor = input.color(#d1d4dc, title="Table Border Color.........", inline="6", group=G1)
  33. SeparatorRowColor = input.color(color.white, title="Separator Row Color.......", inline="5", group=G1)
  34.  
  35. string G2 = "Indicator Inputs"
  36. comparedWithSecurity = input.symbol(title="Compare With", defval="SPY", group=G2)
  37. var minPriceThreshold = input.int(12, title="Min Price", group=G2)
  38. var desiredMinATR = input.float(2, title="Desired Min ATR", group=G2)
  39. var rrsLength = input.int(12, title="RRS Length", group=G2)
  40. var atrLength = input.int(14, title="ATR Length", group=G2)
  41. var nDayAverageForRVOL = input.int(20, title="N Day Average (For RVOL)", group=G2)
  42. var minVolumeForToday = input.int(1500000, title="Min Required Vol Today", group=G2)
  43. var nDayAverageForDailyVol = input.int(50, title="N Day Average (For Daily Volume)", group=G2)
  44. var desiredAvgVolume = input.int(2000000, title="Desired Min Daily Avg Vol", group=G2)
  45.  
  46.  
  47. //----------------------------------------------
  48. // defaults
  49. tableRows = 22
  50. tableColumns = 2
  51. tableCellWidth1 = 4
  52. tableCellWidth2 = 3
  53. nCurrentRow = 0
  54. symbolMark = ""
  55. cellBG = color.black
  56. textSize =  size.normal
  57.  
  58. //----------------------------------------------
  59. //Get relevant metrics for the ticker representing the Market
  60. tM = ticker.new(syminfo.prefix(symbol=comparedWithSecurity), syminfo.ticker(symbol=comparedWithSecurity))
  61. YCloseM = request.security(tM, 'D', close[1], lookahead = barmerge.lookahead_on)
  62. TCurrentPriceM = request.security(tM, 'D', close, lookahead = barmerge.lookahead_on)
  63.  
  64. DAvgVolM = request.security(tM, 'D', ta.sma(volume, nDayAverageForDailyVol))
  65. TVolumeM = request.security(tM, 'D', volume, lookahead = barmerge.lookahead_on)
  66. TVolFillM = TVolumeM / DAvgVolM
  67.  
  68. dMarketDayChange = TCurrentPriceM - YCloseM
  69. isMarketUp = dMarketDayChange > 0
  70.  
  71.  
  72. //----------------------------------------------
  73. //Get relevant metrics for current stock
  74. tS = ticker.new(syminfo.prefix, syminfo.ticker)
  75. TCurrentPriceS = request.security(tS, 'D', close, lookahead = barmerge.lookahead_on)
  76. YCloseS = request.security(tS, 'D', close[1], lookahead = barmerge.lookahead_on)
  77. YHighS = request.security(tS, 'D', high[1], lookahead = barmerge.lookahead_on)
  78. YLowS = request.security(tS, 'D', low[1], lookahead = barmerge.lookahead_on)
  79. TwentyDayHighS = request.security(tS, timeframe='D', expression=ta.highest(source=high, length=20))
  80. TwentyDayLowS = request.security(tS, timeframe='D', expression=ta.lowest(source=low, length=20))
  81. TOpenS = request.security(tS, 'D', open, lookahead = barmerge.lookahead_on)
  82. TVWAPS = request.security(tS, timeframe="", expression=ta.vwap(hlc3))
  83. DAvgVolS = request.security(tS, 'D', ta.sma(volume, nDayAverageForDailyVol))
  84. TVolumeS = request.security(tS, 'D', volume, lookahead = barmerge.lookahead_on)
  85. TVolFillS = TVolumeS / DAvgVolS
  86. D50SMA = request.security(tS, 'D', ta.sma(close, 50))
  87. D100SMA = request.security(tS, 'D', ta.sma(close, 100))
  88. D200SMA = request.security(tS, 'D', ta.sma(close, 200))
  89. DCurrentATR = request.security(tS, 'D', ta.atr(atrLength))
  90.  
  91. dStockDayChange = TCurrentPriceS - YCloseS
  92. isStockUp = dStockDayChange > 0
  93.  
  94.  
  95. //----------------------------------------------
  96. // Calculate Relative Strength
  97. // © WorkPiece 12.28.21
  98.  
  99. //##########Rolling Price Change##########
  100. comparedClose = request.security(tM, timeframe="", expression=close)
  101. comparedRollingMove = comparedClose - comparedClose[rrsLength]
  102. sClose = request.security(tS, timeframe="", expression=close)
  103. symbolRollingMove = sClose - sClose[rrsLength]
  104.  
  105.  
  106. //##########Rolling ATR Change##########
  107. symbolRollingATR = request.security(tS, timeframe="", expression=ta.atr(rrsLength)[1])
  108. comparedRollingATR = request.security(tM, timeframe="", expression=ta.atr(rrsLength)[1])
  109.  
  110. //##########Calculations##########
  111. powerIndex = comparedRollingMove / comparedRollingATR
  112. TRRS = (symbolRollingMove - powerIndex * symbolRollingATR) / symbolRollingATR
  113.  
  114.  
  115.  
  116.  
  117. //----------------------------------------------
  118. // Calculate RVOL
  119. // /u/HurlTeaInTheSea v1.0
  120. // Intraday Relative Volume (RVol) indicator:
  121.  
  122. // still works on higher timeframe but it's not a "day" average anymore, so throw error to avoid confusion
  123. if not (timeframe.isintraday or timeframe.isdaily)
  124.    runtime.error("RVol is only valid for daily timeframe or lower")
  125.  
  126. var cVolS = 0.0
  127. var cVolM = 0.0
  128.  
  129. var newDayBars = array.new_int()
  130.  
  131. // detect new session of day
  132. isNewDay() =>
  133.    t = time('D') // by default, time() follows symbol's session
  134.     na(t[1]) and not na(t) or t[1] < t
  135.  
  136. if isNewDay()
  137.     // reset cumulative volume
  138.     cVolS := 0
  139.     cVolM := 0
  140.    
  141.     // save new bars in circular array of length nDayAverageForRVOL + 1
  142.     array.push(newDayBars, bar_index)
  143.     if (array.size(newDayBars) > nDayAverageForRVOL + 1)
  144.         array.shift(newDayBars)
  145.    
  146. // cumulative volume
  147. cVolS := cVolS + volume
  148. cVolM := cVolM + request.security(tM, timeframe.period, volume, lookahead = barmerge.lookahead_on)
  149.  
  150. // calculate relative volume
  151. aVolS = 0.0
  152. aVolM = 0.0
  153. // check enough nDayAverageForRVOL saved in history to run (current day also saved)
  154. len = array.size(newDayBars)
  155. if len >= nDayAverageForRVOL + 1
  156.     // SMA of historical cumulative volume up to but not including current time of day
  157.     for i = 0 to len - 2
  158.         b1 = array.get(newDayBars, i)
  159.         b2 = array.get(newDayBars, i + 1)
  160.        
  161.         // use historical date but carry over current hour, minutes, seconds (this method is exact and avoids DST bugs)
  162.         t1 = time[bar_index - b1]
  163.         tLookup = timestamp(year(t1), month(t1), dayofmonth(t1), hour(time), minute(time), second(time))
  164.        
  165.         // get latest bar clamped in range [b1, b2) that is equal to or precedes given time (binary search for speed)
  166.         int lo = math.max(0, b1) - 1
  167.         int hi = math.max(0, b2)
  168.         while 1 + lo < hi
  169.             int mi = lo + math.floor((hi - lo) / 2)
  170.             if (tLookup < time[bar_index - mi])
  171.                 hi := mi
  172.             else
  173.                 lo := mi
  174.         lo := lo < b1 ? hi : lo
  175.         bClosest = b1 < b2 ? lo : -1
  176.        
  177.         // add cumulative volume to SMA calculation
  178.         tClosest = time[bar_index - bClosest]
  179.         aVolS := aVolS + (tLookup >= tClosest ? cVolS[bar_index - bClosest] / nDayAverageForRVOL : 0)
  180.        
  181.         aVolM := aVolM + (tLookup >= tClosest ? cVolM[bar_index - bClosest] / nDayAverageForRVOL : 0)
  182.        
  183. rVolS = aVolS > 0 ? cVolS / aVolS : 0
  184. rVolM = aVolM > 0 ? cVolM / aVolM : 0
  185.  
  186.  
  187. //----------------------------------------------
  188. var dataTable = table.new(tableYposInput + "_" + tableXposInput, tableColumns, tableRows, bgcolor=color.white, frame_width=1, frame_color=TableBorderColor)
  189.  
  190.  
  191. //----------------------------------------------
  192. //Show Market Status
  193. symbolMark := isMarketUp ? symbolUpString : symbolDownString
  194. cellBG := isMarketUp ? StockUpColor : StockDownColor
  195.  
  196. table.cell(dataTable, 0, nCurrentRow, symbolMark + " " + syminfo.ticker(symbol=comparedWithSecurity), text_halign=text.align_left, bgcolor = cellBG, text_color = isMarketUp ? color.black : color.white)
  197. table.cell(dataTable, 1, nCurrentRow, str.tostring(TCurrentPriceM, "#.##") + " (" + str.tostring(dMarketDayChange, "#.##") + ")", text_halign=text.align_left, bgcolor = cellBG, text_color = isMarketUp ? color.black : color.white)
  198. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  199. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  200.  
  201.  
  202. //----------------------------------------------
  203. //Show Stock Status
  204. symbolMark := isStockUp ? symbolUpString : symbolDownString
  205. cellBG := isStockUp ? StockUpColor : StockDownColor
  206.  
  207. nCurrentRow := nCurrentRow + 1
  208. table.cell( dataTable, 0, nCurrentRow, (syminfo.ticker(symbol=comparedWithSecurity) != syminfo.ticker) ? (symbolMark + " " + syminfo.ticker) : "", text_halign=text.align_left, bgcolor = (syminfo.ticker(symbol=comparedWithSecurity) != syminfo.ticker) ? cellBG : SeparatorRowColor, text_color = isStockUp ? color.black : color.white)
  209.            
  210. table.cell(dataTable, 1, nCurrentRow, (syminfo.ticker(symbol=comparedWithSecurity) != syminfo.ticker) ? (str.tostring(TCurrentPriceS, "#.##") + " (" + str.tostring(dStockDayChange, "#.##") + ")") : "", text_halign=text.align_left, bgcolor = (syminfo.ticker(symbol=comparedWithSecurity) != syminfo.ticker) ? cellBG : SeparatorRowColor, text_color = isStockUp ? color.black : color.white)
  211. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  212. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  213.  
  214.  
  215. //----------------------------------------------
  216. //Show Net Change %
  217. deltaYCloseMPercentage = (dMarketDayChange / YCloseM) * 100
  218. deltaYCloseSPercentage = (dStockDayChange / YCloseS) * 100
  219.  
  220. symbolMark := deltaYCloseSPercentage > deltaYCloseSPercentage ? symbolUpString : symbolDownString
  221. if isMarketUp
  222.     if isStockUp
  223.         if TCurrentPriceS > minPriceThreshold
  224.             cellBG := meetCriteriaStateColor
  225.         else
  226.             cellBG := doesNotMeetCriteriaStateColor
  227.     else
  228.         if TCurrentPriceS > minPriceThreshold
  229.             cellBG := warningStateColor
  230.         else
  231.             cellBG := doesNotMeetCriteriaStateColor
  232. else
  233.     if isStockUp
  234.         if TCurrentPriceS > minPriceThreshold
  235.             cellBG := warningStateColor
  236.         else
  237.             cellBG := doesNotMeetCriteriaStateColor
  238.     else
  239.         if TCurrentPriceS > minPriceThreshold
  240.             cellBG := meetCriteriaStateColor
  241.         else
  242.             cellBG := doesNotMeetCriteriaStateColor
  243.  
  244. nCurrentRow := nCurrentRow + 1
  245. table.cell(dataTable, 0, nCurrentRow, symbolMark + " NET CHG %", text_halign=text.align_left, bgcolor=cellBG)
  246. table.cell(dataTable, 1, nCurrentRow, str.tostring(deltaYCloseSPercentage, "#.##") + "%" + ((syminfo.ticker(symbol=comparedWithSecurity) != syminfo.ticker) ? ( " / " + str.tostring(deltaYCloseMPercentage, "#.##") + "%") : ""), text_halign=text.align_left, bgcolor=cellBG)
  247. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  248. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  249.  
  250.  
  251. //----------------------------------------------
  252. //Show Daily ATR Status
  253.  
  254. symbolMark := DCurrentATR > desiredMinATR ? symbolUpString : symbolDownString
  255.  
  256. if isMarketUp
  257.     if isStockUp
  258.         if DCurrentATR > desiredMinATR
  259.             cellBG := meetCriteriaStateColor
  260.         else
  261.             cellBG := doesNotMeetCriteriaStateColor
  262.     else
  263.         if DCurrentATR > desiredMinATR
  264.             cellBG := warningStateColor
  265.         else
  266.             cellBG := doesNotMeetCriteriaStateColor
  267. else
  268.     if isStockUp
  269.         if DCurrentATR > desiredMinATR
  270.             cellBG := warningStateColor
  271.         else
  272.             cellBG := doesNotMeetCriteriaStateColor
  273.     else
  274.         if DCurrentATR > desiredMinATR
  275.             cellBG := meetCriteriaStateColor
  276.         else
  277.             cellBG := doesNotMeetCriteriaStateColor
  278.            
  279. nCurrentRow := nCurrentRow + 1
  280. table.cell(dataTable, 0, nCurrentRow, symbolMark + " ATR(" + str.tostring(atrLength) + "D)", text_halign=text.align_left, bgcolor=cellBG)
  281. table.cell(dataTable, 1, nCurrentRow, str.tostring(DCurrentATR, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  282. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  283. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  284.  
  285.  
  286. //----------------------------------------------
  287. //Show Day Type
  288. //symbolMark := TCurrentPriceS > minPriceThreshold ? symbolUpString : symbolDownString
  289. if isMarketUp
  290.     if isStockUp
  291.         if TCurrentPriceS > YHighS
  292.             cellBG := meetCriteriaStateColor
  293.         else
  294.             cellBG := doesNotMeetCriteriaStateColor
  295.     else
  296.         if TCurrentPriceS < YLowS
  297.             cellBG := warningStateColor
  298.         else
  299.             cellBG := doesNotMeetCriteriaStateColor
  300. else
  301.     if isStockUp
  302.         if TCurrentPriceS > YHighS
  303.             cellBG := warningStateColor
  304.         else
  305.             cellBG := doesNotMeetCriteriaStateColor
  306.     else
  307.         if TCurrentPriceS < YLowS
  308.             cellBG := meetCriteriaStateColor
  309.         else
  310.             cellBG := doesNotMeetCriteriaStateColor
  311.  
  312. strDayType = (TCurrentPriceS > YHighS) ? "UP" : (TCurrentPriceS >= YLowS) ? "INSIDE" : "DOWN"
  313.  
  314. nCurrentRow := nCurrentRow + 1
  315. table.cell(dataTable, 0, nCurrentRow, "    DAY TYPPE", text_halign=text.align_left, bgcolor=cellBG)
  316. table.cell(dataTable, 1, nCurrentRow, strDayType, text_halign=text.align_left, bgcolor=cellBG)
  317. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  318. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  319.  
  320.  
  321. //----------------------------------------------
  322. //Add empty row as separator
  323. nCurrentRow := nCurrentRow + 1
  324. table.cell(dataTable, 0, nCurrentRow, "                           ", text_halign=text.align_left, bgcolor=SeparatorRowColor)
  325. table.cell(dataTable, 1, nCurrentRow, "     ", text_halign=text.align_left, bgcolor=SeparatorRowColor)
  326. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  327. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  328.  
  329.  
  330. //----------------------------------------------
  331. //Show RRS Status
  332. symbolMark := TRRS > 0 ? symbolUpString : symbolDownString
  333.  
  334. if isMarketUp
  335.     if isStockUp
  336.         if TRRS > 0
  337.             cellBG := meetCriteriaStateColor
  338.         else
  339.             cellBG := doesNotMeetCriteriaStateColor
  340.     else
  341.         if TRRS > 0
  342.             cellBG := doesNotMeetCriteriaStateColor
  343.         else
  344.             cellBG := warningStateColor
  345. else
  346.     if isStockUp
  347.         if TRRS > 0
  348.             cellBG := warningStateColor
  349.         else
  350.             cellBG := doesNotMeetCriteriaStateColor
  351.     else
  352.         if TRRS > 0
  353.             cellBG := doesNotMeetCriteriaStateColor
  354.         else
  355.             cellBG := meetCriteriaStateColor
  356.  
  357. nCurrentRow := nCurrentRow + 1
  358. table.cell(dataTable, 0, nCurrentRow, (syminfo.ticker(symbol=comparedWithSecurity) != syminfo.ticker) ? symbolMark + " RRS" : "     RRS", text_halign=text.align_left, bgcolor=cellBG)
  359. table.cell(dataTable, 1, nCurrentRow, (syminfo.ticker(symbol=comparedWithSecurity) != syminfo.ticker) ? (str.tostring(TRRS, "#.##")) : "NA", text_halign=text.align_left, bgcolor=cellBG)
  360. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  361. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)    
  362.  
  363.  
  364. //----------------------------------------------
  365. //Show RVOL Status
  366.  
  367. symbolMark := (rVolS > rVolM and rVolS > 1.25) ? symbolUpString : symbolDownString
  368.  
  369. if isMarketUp
  370.     if isStockUp
  371.         if (rVolS > rVolM and rVolS > 1.25)
  372.             cellBG := meetCriteriaStateColor
  373.         else
  374.             cellBG := doesNotMeetCriteriaStateColor
  375.     else
  376.         if (rVolS > rVolM and rVolS > 1.25)
  377.             cellBG := warningStateColor
  378.         else
  379.             cellBG := doesNotMeetCriteriaStateColor
  380. else
  381.     if isStockUp
  382.         if (rVolS > rVolM and rVolS > 1.25)
  383.             cellBG := warningStateColor
  384.         else
  385.             cellBG := doesNotMeetCriteriaStateColor
  386.     else
  387.         if (rVolS > rVolM and rVolS > 1.25)
  388.             cellBG := meetCriteriaStateColor
  389.         else
  390.             cellBG := doesNotMeetCriteriaStateColor
  391.            
  392. nCurrentRow := nCurrentRow + 1
  393. table.cell(dataTable, 0, nCurrentRow, symbolMark + " RVOL(" + str.tostring(nDayAverageForRVOL) + "D)", text_halign=text.align_left, bgcolor=cellBG)
  394. table.cell(dataTable, 1, nCurrentRow, str.tostring(rVolS*100, "#") + "%" + ((syminfo.ticker(symbol=comparedWithSecurity) != syminfo.ticker) ? ( " / " + str.tostring(rVolM*100, "#") + "%") : ""), text_halign=text.align_left, bgcolor=cellBG)
  395. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  396. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  397.  
  398.  
  399.  
  400. //#################################################
  401. //Show Daily Average Volume
  402.  
  403. symbolMark := DAvgVolS > desiredAvgVolume? symbolUpString : symbolDownString
  404.  
  405. if isMarketUp
  406.     if isStockUp
  407.         if DAvgVolS > desiredAvgVolume
  408.             cellBG := meetCriteriaStateColor
  409.         else
  410.             cellBG := doesNotMeetCriteriaStateColor
  411.     else
  412.         if DAvgVolS > desiredAvgVolume
  413.             cellBG := warningStateColor
  414.         else
  415.             cellBG := doesNotMeetCriteriaStateColor
  416. else
  417.     if isStockUp
  418.         if DAvgVolS > desiredAvgVolume
  419.             cellBG := warningStateColor
  420.         else
  421.             cellBG := doesNotMeetCriteriaStateColor
  422.     else
  423.         if DAvgVolS > desiredAvgVolume
  424.             cellBG := meetCriteriaStateColor
  425.         else
  426.             cellBG := doesNotMeetCriteriaStateColor
  427.            
  428.            
  429. nCurrentRow := nCurrentRow + 1
  430. table.cell(dataTable, 0, nCurrentRow, symbolMark + " AvVOL(" + str.tostring(nDayAverageForDailyVol) + "D)", text_halign=text.align_left, bgcolor=cellBG)
  431. table.cell(dataTable, 1, nCurrentRow, str.tostring(DAvgVolS/1000000, "#.#") + "M", text_halign=text.align_left, bgcolor=cellBG)
  432. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  433. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  434.  
  435.  
  436. //----------------------------------------------
  437. //Show Current Volume
  438.  
  439. symbolMark := TVolumeS > minVolumeForToday? symbolUpString : symbolDownString
  440.  
  441. if isMarketUp
  442.     if isStockUp
  443.         if TVolumeS > minVolumeForToday
  444.             cellBG := meetCriteriaStateColor
  445.         else
  446.             cellBG := doesNotMeetCriteriaStateColor
  447.     else
  448.         if TVolumeS > minVolumeForToday
  449.             cellBG := warningStateColor
  450.         else
  451.             cellBG := doesNotMeetCriteriaStateColor
  452. else
  453.     if isStockUp
  454.         if TVolumeS > minVolumeForToday
  455.             cellBG := warningStateColor
  456.         else
  457.             cellBG := doesNotMeetCriteriaStateColor
  458.     else
  459.         if TVolumeS > minVolumeForToday
  460.             cellBG := meetCriteriaStateColor
  461.         else
  462.             cellBG := doesNotMeetCriteriaStateColor
  463.            
  464. nCurrentRow := nCurrentRow + 1
  465. table.cell(dataTable, 0, nCurrentRow, symbolMark + " VOLUME", text_halign=text.align_left, bgcolor=cellBG)
  466. table.cell(dataTable, 1, nCurrentRow, str.tostring(TVolumeS/1000000, "#.#") + "M", text_halign=text.align_left, bgcolor=cellBG)
  467. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  468. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  469.  
  470.  
  471. //----------------------------------------------
  472. //Show Volume Fill
  473. symbolMark := (TVolFillS > 1 and TVolFillS > TVolFillM) ? symbolUpString : symbolDownString
  474.  
  475. if isMarketUp
  476.     if isStockUp
  477.         if TVolFillS > TVolFillM
  478.             cellBG := meetCriteriaStateColor
  479.         else
  480.             cellBG := doesNotMeetCriteriaStateColor
  481.     else
  482.         if TVolFillS > TVolFillM
  483.             cellBG := warningStateColor
  484.         else
  485.             cellBG := doesNotMeetCriteriaStateColor
  486. else
  487.     if isStockUp
  488.         if TVolFillS > TVolFillM
  489.             cellBG := warningStateColor
  490.         else
  491.             cellBG := doesNotMeetCriteriaStateColor
  492.     else
  493.         if TVolFillS > TVolFillM
  494.             cellBG := meetCriteriaStateColor
  495.         else
  496.             cellBG := doesNotMeetCriteriaStateColor
  497.            
  498. nCurrentRow := nCurrentRow + 1
  499. table.cell(dataTable, 0, nCurrentRow, symbolMark + " VOL FILL", text_halign=text.align_left, bgcolor=cellBG)
  500. table.cell(dataTable, 1, nCurrentRow, str.tostring(TVolFillS*100, "#") + "%" + ((syminfo.ticker(symbol=comparedWithSecurity) != syminfo.ticker) ? (" / " + str.tostring(TVolFillM*100, "#") + "%" ) : ""), text_halign=text.align_left, bgcolor=cellBG)
  501. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  502. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  503.  
  504. //----------------------------------------------
  505. //Add empty row to separate from volume metrics
  506. nCurrentRow := nCurrentRow + 1
  507. table.cell(dataTable, 0, nCurrentRow, "                           ", text_halign=text.align_left, bgcolor=SeparatorRowColor)
  508. table.cell(dataTable, 1, nCurrentRow, "     ", text_halign=text.align_left, bgcolor=SeparatorRowColor)
  509. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  510. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  511.  
  512.  
  513.  
  514. //----------------------------------------------
  515. //Show YClose Status
  516. symbolMark := TCurrentPriceS > YCloseS ? symbolUpString : symbolDownString
  517.  
  518. if isMarketUp
  519.     if isStockUp
  520.         if TCurrentPriceS > YCloseS
  521.             cellBG := meetCriteriaStateColor
  522.         else
  523.             cellBG := doesNotMeetCriteriaStateColor
  524.     else
  525.         if TCurrentPriceS > YCloseS
  526.             cellBG := doesNotMeetCriteriaStateColor
  527.         else
  528.             cellBG := warningStateColor
  529. else
  530.     if isStockUp
  531.         if TCurrentPriceS > YCloseS
  532.             cellBG := warningStateColor
  533.         else
  534.             cellBG := doesNotMeetCriteriaStateColor
  535.     else
  536.         if TCurrentPriceS > YCloseS
  537.             cellBG := doesNotMeetCriteriaStateColor
  538.         else
  539.             cellBG := meetCriteriaStateColor
  540.  
  541. nCurrentRow := nCurrentRow + 1
  542. table.cell(dataTable, 0, nCurrentRow, symbolMark + " YCLOSE", text_halign=text.align_left, bgcolor=cellBG)
  543. table.cell(dataTable, 1, nCurrentRow, str.tostring(dStockDayChange, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  544. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  545. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  546.  
  547.  
  548. //----------------------------------------------
  549. //Show VWAP Status
  550. deltaVWAPS = TCurrentPriceS - TVWAPS
  551. symbolMark := TCurrentPriceS > TVWAPS ? symbolUpString : symbolDownString
  552.  
  553. if isMarketUp
  554.     if isStockUp
  555.         if TCurrentPriceS > TVWAPS
  556.             cellBG := meetCriteriaStateColor
  557.         else
  558.             cellBG := doesNotMeetCriteriaStateColor
  559.     else
  560.         if TCurrentPriceS > TVWAPS
  561.             cellBG := doesNotMeetCriteriaStateColor
  562.         else
  563.             cellBG := warningStateColor
  564. else
  565.     if isStockUp
  566.         if TCurrentPriceS > TVWAPS
  567.             cellBG := warningStateColor
  568.         else
  569.             cellBG := doesNotMeetCriteriaStateColor
  570.     else
  571.         if TCurrentPriceS > TVWAPS
  572.             cellBG := doesNotMeetCriteriaStateColor
  573.         else
  574.             cellBG := meetCriteriaStateColor
  575.  
  576. nCurrentRow := nCurrentRow + 1
  577. table.cell(dataTable, 0, nCurrentRow, symbolMark + " VWAP", text_halign=text.align_left, bgcolor=cellBG)
  578. table.cell(dataTable, 1, nCurrentRow, str.tostring(deltaVWAPS, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  579. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  580. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  581.  
  582.  
  583. //----------------------------------------------
  584. //Show Open Status
  585. deltaOpenS = TCurrentPriceS - TOpenS
  586. symbolMark := TCurrentPriceS > TOpenS ? symbolUpString : symbolDownString
  587.  
  588. if isMarketUp
  589.     if isStockUp
  590.         if TCurrentPriceS > TOpenS
  591.             cellBG := meetCriteriaStateColor
  592.         else
  593.             cellBG := doesNotMeetCriteriaStateColor
  594.     else
  595.         if TCurrentPriceS > TOpenS
  596.             cellBG := doesNotMeetCriteriaStateColor
  597.         else
  598.             cellBG := warningStateColor
  599. else
  600.     if isStockUp
  601.         if TCurrentPriceS > TOpenS
  602.             cellBG := warningStateColor
  603.         else
  604.             cellBG := doesNotMeetCriteriaStateColor
  605.     else
  606.         if TCurrentPriceS > TOpenS
  607.             cellBG := doesNotMeetCriteriaStateColor
  608.         else
  609.             cellBG := meetCriteriaStateColor
  610.  
  611. nCurrentRow := nCurrentRow + 1
  612. table.cell(dataTable, 0, nCurrentRow, symbolMark + " OPEN", text_halign=text.align_left, bgcolor=cellBG)
  613. table.cell(dataTable, 1, nCurrentRow, str.tostring(deltaOpenS, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  614. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  615. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  616.  
  617.  
  618. //----------------------------------------------
  619. //Show YHigh Status
  620. deltaYHighS = TCurrentPriceS - YHighS
  621. symbolMark := TCurrentPriceS > YHighS ? symbolUpString : symbolDownString
  622.  
  623. if isMarketUp
  624.     if isStockUp
  625.         if TCurrentPriceS > YHighS
  626.             cellBG := meetCriteriaStateColor
  627.         else
  628.             cellBG := doesNotMeetCriteriaStateColor
  629.     else
  630.         if TCurrentPriceS > YHighS
  631.             cellBG := doesNotMeetCriteriaStateColor
  632.         else
  633.             cellBG := warningStateColor
  634. else
  635.     if isStockUp
  636.         if TCurrentPriceS > YHighS
  637.             cellBG := warningStateColor
  638.         else
  639.             cellBG := doesNotMeetCriteriaStateColor
  640.     else
  641.         if TCurrentPriceS > YHighS
  642.             cellBG := doesNotMeetCriteriaStateColor
  643.         else
  644.             cellBG := meetCriteriaStateColor
  645.  
  646. nCurrentRow := nCurrentRow + 1
  647. table.cell(dataTable, 0, nCurrentRow, symbolMark + " YHIGH", text_halign=text.align_left, bgcolor=cellBG)
  648. table.cell(dataTable, 1, nCurrentRow, str.tostring(deltaYHighS, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  649. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  650. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  651.  
  652.  
  653. //----------------------------------------------
  654. //Show YLow Status
  655. deltaYLowS = TCurrentPriceS - YLowS
  656. symbolMark := TCurrentPriceS > YLowS ? symbolUpString : symbolDownString
  657.  
  658. if isMarketUp
  659.     if isStockUp
  660.         if TCurrentPriceS > YLowS
  661.             cellBG := meetCriteriaStateColor
  662.         else
  663.             cellBG := doesNotMeetCriteriaStateColor
  664.     else
  665.         if TCurrentPriceS > YLowS
  666.             cellBG := doesNotMeetCriteriaStateColor
  667.         else
  668.             cellBG := warningStateColor
  669. else
  670.     if isStockUp
  671.         if TCurrentPriceS > YLowS
  672.             cellBG := warningStateColor
  673.         else
  674.             cellBG := doesNotMeetCriteriaStateColor
  675.     else
  676.         if TCurrentPriceS > YLowS
  677.             cellBG := doesNotMeetCriteriaStateColor
  678.         else
  679.             cellBG := meetCriteriaStateColor
  680.  
  681. nCurrentRow := nCurrentRow + 1
  682. table.cell(dataTable, 0, nCurrentRow, symbolMark + " YLOW", text_halign=text.align_left, bgcolor=cellBG)
  683. table.cell(dataTable, 1, nCurrentRow, str.tostring(deltaYLowS, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  684. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  685. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  686.  
  687.  
  688.  
  689. //----------------------------------------------
  690. //Show 20 Day High Status
  691. delta20HighS = TCurrentPriceS - TwentyDayHighS
  692. symbolMark := TCurrentPriceS > TwentyDayHighS ? symbolUpString : symbolDownString
  693.  
  694. if isMarketUp
  695.     if isStockUp
  696.         if TCurrentPriceS > TwentyDayHighS
  697.             cellBG := meetCriteriaStateColor
  698.         else
  699.             cellBG := doesNotMeetCriteriaStateColor
  700.     else
  701.         if TCurrentPriceS > TwentyDayHighS
  702.             cellBG := doesNotMeetCriteriaStateColor
  703.         else
  704.             cellBG := warningStateColor
  705. else
  706.     if isStockUp
  707.         if TCurrentPriceS > TwentyDayHighS
  708.             cellBG := warningStateColor
  709.         else
  710.             cellBG := doesNotMeetCriteriaStateColor
  711.     else
  712.         if TCurrentPriceS > TwentyDayHighS
  713.             cellBG := doesNotMeetCriteriaStateColor
  714.         else
  715.             cellBG := meetCriteriaStateColor
  716.  
  717. nCurrentRow := nCurrentRow + 1
  718. table.cell(dataTable, 0, nCurrentRow, symbolMark + " D20 HIGH", text_halign=text.align_left, bgcolor=cellBG)
  719. table.cell(dataTable, 1, nCurrentRow, str.tostring(delta20HighS, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  720. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  721. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  722.  
  723.  
  724. //----------------------------------------------
  725. //Show 20 Day Low Status
  726. delta20LowS = TCurrentPriceS - TwentyDayLowS
  727. symbolMark := TCurrentPriceS > TwentyDayLowS ? symbolUpString : symbolDownString
  728.  
  729. if isMarketUp
  730.     if isStockUp
  731.         if TCurrentPriceS > TwentyDayLowS
  732.             cellBG := meetCriteriaStateColor
  733.         else
  734.             cellBG := doesNotMeetCriteriaStateColor
  735.     else
  736.         if TCurrentPriceS > TwentyDayLowS
  737.             cellBG := doesNotMeetCriteriaStateColor
  738.         else
  739.             cellBG := warningStateColor
  740. else
  741.     if isStockUp
  742.         if TCurrentPriceS > TwentyDayLowS
  743.             cellBG := warningStateColor
  744.         else
  745.             cellBG := doesNotMeetCriteriaStateColor
  746.     else
  747.         if TCurrentPriceS > TwentyDayLowS
  748.             cellBG := doesNotMeetCriteriaStateColor
  749.         else
  750.             cellBG := meetCriteriaStateColor
  751.  
  752. nCurrentRow := nCurrentRow + 1
  753. table.cell(dataTable, 0, nCurrentRow, symbolMark + " D20 LOW", text_halign=text.align_left, bgcolor=cellBG)
  754. table.cell(dataTable, 1, nCurrentRow, str.tostring(delta20LowS, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  755. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  756. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  757.  
  758.  
  759. //----------------------------------------------
  760. //Show 50SMA(D) Status
  761. //https://www.tradingview.com/script/NxVJbviK-Daily-Moving-Averages-on-Intraday-Chart/
  762.  
  763. deltaSMA50S = TCurrentPriceS - D50SMA
  764. symbolMark := TCurrentPriceS > D50SMA ? symbolUpString : symbolDownString
  765.  
  766. if isMarketUp
  767.     if isStockUp
  768.         if TCurrentPriceS > D50SMA
  769.             cellBG := meetCriteriaStateColor
  770.         else
  771.             cellBG := doesNotMeetCriteriaStateColor
  772.     else
  773.         if TCurrentPriceS > D50SMA
  774.             cellBG := doesNotMeetCriteriaStateColor
  775.         else
  776.             cellBG := warningStateColor
  777. else
  778.     if isStockUp
  779.         if TCurrentPriceS > D50SMA
  780.             cellBG := warningStateColor
  781.         else
  782.             cellBG := doesNotMeetCriteriaStateColor
  783.     else
  784.         if TCurrentPriceS > D50SMA
  785.             cellBG := doesNotMeetCriteriaStateColor
  786.         else
  787.             cellBG := meetCriteriaStateColor
  788.            
  789. nCurrentRow := nCurrentRow + 1
  790. table.cell(dataTable, 0, nCurrentRow, symbolMark + " 50SMA(D)", text_halign=text.align_left, bgcolor=cellBG)
  791. table.cell(dataTable, 1, nCurrentRow, str.tostring(deltaSMA50S, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  792. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  793. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  794.  
  795.  
  796. //----------------------------------------------
  797. //Show 100SMA(D) Status
  798.  
  799. deltaSMA100S = TCurrentPriceS - D100SMA
  800. symbolMark := TCurrentPriceS > D100SMA ? symbolUpString : symbolDownString
  801.  
  802. if isMarketUp
  803.     if isStockUp
  804.         if TCurrentPriceS > D100SMA
  805.             cellBG := meetCriteriaStateColor
  806.         else
  807.             cellBG := doesNotMeetCriteriaStateColor
  808.     else
  809.         if TCurrentPriceS > D100SMA
  810.             cellBG := doesNotMeetCriteriaStateColor
  811.         else
  812.             cellBG := warningStateColor
  813. else
  814.     if isStockUp
  815.         if TCurrentPriceS > D100SMA
  816.             cellBG := warningStateColor
  817.         else
  818.             cellBG := doesNotMeetCriteriaStateColor
  819.     else
  820.         if TCurrentPriceS > D100SMA
  821.             cellBG := doesNotMeetCriteriaStateColor
  822.         else
  823.             cellBG := meetCriteriaStateColor
  824.            
  825. nCurrentRow := nCurrentRow + 1            
  826. table.cell(dataTable, 0, nCurrentRow, symbolMark + " 100SMA(D)", text_halign=text.align_left, bgcolor=cellBG)
  827. table.cell(dataTable, 1, nCurrentRow, str.tostring(deltaSMA100S, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  828. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  829. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  830.  
  831.  
  832. //----------------------------------------------
  833. //Show 200SMA(D) Status
  834.  
  835. deltaSMA200S = TCurrentPriceS - D200SMA
  836. symbolMark := TCurrentPriceS > D200SMA ? symbolUpString : symbolDownString
  837.  
  838. if isMarketUp
  839.     if isStockUp
  840.         if TCurrentPriceS > D200SMA
  841.             cellBG := meetCriteriaStateColor
  842.         else
  843.             cellBG := doesNotMeetCriteriaStateColor
  844.     else
  845.         if TCurrentPriceS > D200SMA
  846.             cellBG := doesNotMeetCriteriaStateColor
  847.         else
  848.             cellBG := warningStateColor
  849. else
  850.     if isStockUp
  851.         if TCurrentPriceS > D200SMA
  852.             cellBG := warningStateColor
  853.         else
  854.             cellBG := doesNotMeetCriteriaStateColor
  855.     else
  856.         if TCurrentPriceS > D200SMA
  857.             cellBG := doesNotMeetCriteriaStateColor
  858.         else
  859.             cellBG := meetCriteriaStateColor
  860.            
  861. nCurrentRow := nCurrentRow + 1            
  862. table.cell(dataTable, 0, nCurrentRow, symbolMark + " 200SMA(D)", text_halign=text.align_left, bgcolor=cellBG)
  863. table.cell(dataTable, 1, nCurrentRow, str.tostring(deltaSMA200S, "#.##"), text_halign=text.align_left, bgcolor=cellBG)
  864. table.cell_set_text_size(dataTable, 0, nCurrentRow, textSize)
  865. table.cell_set_text_size(dataTable, 1, nCurrentRow, textSize)
  866.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement