Advertisement
--SubZer0--

QuickCheck For ThinkOrSwim - v1.5

Nov 21st, 2022 (edited)
1,321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 34.60 KB | Source Code | 0 0
  1. ###########################################################################
  2. #QuickCheck - Automatically Validate Basic Criteria For Stock Selection
  3. #Creator: u/--SubZer0--
  4. #Version: 1.5
  5. #Last Updated: 11.20.2022
  6.  
  7. #Attributtion:
  8. #RealRelativeStrength: u/WorkPiece
  9. #RelativeVolume: u/HurlTeaInTheSea
  10. #############################################################################
  11.  
  12. #Hide the price plot as we dont need it for this indicator
  13. HidePricePlot(yes);
  14.  
  15. input symbolUpPrefix = " ";
  16. input symbolDownPrefix = " ";
  17. input ComparedWithSecurity = "SPY";
  18.  
  19. input minPrice = 10;
  20. input minBidAskSpread = 0.03;
  21. input minATR = 2;
  22. input atrLength = 14;
  23.  
  24. input nDaysForDailyVolumeAverage = 50;
  25. input minVolumeForToday = 1500000;
  26. input minDailyAverageVolume = 2000000; #default average of 2M shares traded over n days
  27.  
  28.  
  29. DefineGlobalColor("SymbolUpState", CreateColor(100,150,45));
  30. DefineGlobalColor("SymbolDownState", CreateColor(175,45,40));
  31. DefineGlobalColor("MeetsCriteria", CreateColor(70,170,200));
  32. DefineGlobalColor("DoesNotMeetCriteria", Color.GRAY);
  33. DefineGlobalColor("WarningState", CreateColor(240,140,45));
  34. DefineGlobalColor("SeparatorRowColor", Color.WHITE);
  35.  
  36. def priceType = FundamentalType.CLOSE;
  37. def aggregationPeriod = AggregationPeriod.DAY;
  38.  
  39. #Determine if Market is up or down
  40. def dComparedSymbolLast = close(priceType = "Last", symbol = ComparedWithSecurity);
  41. def dComparedSymbolPrevDayClose = close(period = aggregationPeriod, symbol = ComparedWithSecurity)[1];
  42. def dComparedSymbolDayChange = dComparedSymbolLast - dComparedSymbolPrevDayClose;
  43. def isComparedSymbolUp = (dComparedSymbolDayChange >= 0);
  44.  
  45. #Determine if current stock is up or down
  46. def dStockLast = close(priceType = "Last");
  47. def dStockPrevDayClose = close(period = aggregationPeriod)[1];
  48. def dStockDayChange = dStockLast - dStockPrevDayClose;
  49. def isStockUp = (dStockDayChange > 0);
  50.  
  51. def dComparedSymbolPercentChange = (dComparedSymbolDayChange/dComparedSymbolPrevDayClose);
  52. def dStockPercentChange = (dStockDayChange/dStockPrevDayClose);
  53.  
  54. def todayOpen = open(period = aggregationPeriod);
  55. def todayHigh = high(period = aggregationPeriod);
  56. def todayLow = low(period = aggregationPeriod);
  57. def YHigh = high(period = aggregationPeriod)[1];
  58. def YLow = low(period = aggregationPeriod)[1];
  59. def dVWAP = reference VWAP()."VWAP";
  60.  
  61. def twentyDayHigh = Highest(high(period=AggregationPeriod.DAY)[1], 20);
  62. def twentyDayLow = Lowest(low(period=AggregationPeriod.DAY)[1], 20);
  63.  
  64.  
  65. def dCurrentDailyStockVolume = volume(period=aggregationPeriod);
  66. def dAvgDailyStockVolume = Average(volume(period=aggregationPeriod)[1], nDaysForDailyVolumeAverage);
  67. def dStockVolumeFill = dCurrentDailyStockVolume / dAvgDailyStockVolume;
  68.  
  69. def dCurrentDailyComparedSymbolVolume = volume(symbol = ComparedWithSecurity, period=aggregationPeriod);
  70. def dAvgDailyComparedSymbolVolume = Average(volume(symbol = ComparedWithSecurity, period=aggregationPeriod)[1], nDaysForDailyVolumeAverage);
  71. def dComparedSymbolVolumeFill = dCurrentDailyComparedSymbolVolume / dAvgDailyComparedSymbolVolume;
  72.  
  73. ############################################################
  74. #Show if the ComparedSymbol is up for the day or down (Up = above YClose and Down = below YClose)
  75.  
  76. AddLabel(   yes,  
  77.             (if isComparedSymbolUp then symbolUpPrefix else symbolDownPrefix )
  78.             + " "
  79.             + ComparedWithSecurity
  80.             + "         "
  81.             + AsText(dComparedSymbolLast, "%1$.2f")
  82.             + "  ("
  83.             + (if isComparedSymbolUp then "+" else "")            
  84.             + AsText(dComparedSymbolDayChange, "%1$.2f")
  85.             + ")                ",
  86.            
  87.             if isComparedSymbolUp
  88.                 then GlobalColor("SymbolUpState")
  89.                 else GlobalColor("SymbolDownState")
  90.         );
  91.  
  92. ############################################################
  93. #Is current ticker is up for the day or down? (Up = above YClose and Down = below YClose)
  94.  
  95. AddLabel(   yes,  
  96.             if ComparedWithSecurity == GetSymbol()
  97.                 then "                                                            "
  98.                 else
  99.                 (if isStockUp then symbolUpPrefix else symbolDownPrefix )
  100.                 + " "
  101.                 + GetSymbol()
  102.                 + "        "
  103.                 + AsText(dStockLast, "%1$.2f")
  104.                 + "  ("
  105.                 + (if isStockUp then "+" else "")                
  106.                 + AsText(dStockDayChange, "%1$.2f")
  107.                 + ")                     ",
  108.  
  109.                 if ComparedWithSecurity == GetSymbol()
  110.                     then GlobalColor("SeparatorRowColor")
  111.                     else if isStockUp
  112.                             then GlobalColor("SymbolUpState")
  113.                             else GlobalColor("SymbolDownState")
  114.         );
  115.  
  116.  
  117. ############################################################
  118. # Compare net change % of current stock v/s SPY
  119. AddLabel(   yes,
  120.             (if (dStockPercentChange >= dComparedSymbolPercentChange)then symbolUpPrefix else symbolDownPrefix )
  121.             + " NET CHG %"
  122.             + "    "
  123.             + AsPercent(dStockPercentChange)  
  124.             + ( if ComparedWithSecurity != GetSymbol()
  125.                     then (" / " + AsPercent(dComparedSymbolPercentChange) )
  126.                     else "" )
  127.             + "               " ,
  128.  
  129.             if isComparedSymbolUp then
  130.                 if isStockUp then
  131.                     if (dStockPercentChange >= dComparedSymbolPercentChange) then
  132.                         GlobalColor("MeetsCriteria")
  133.                     else GlobalColor("DoesNotMeetCriteria")
  134.                 else
  135.                     if (dStockPercentChange <= dComparedSymbolPercentChange) then
  136.                         GlobalColor("WarningState")
  137.                     else GlobalColor("DoesNotMeetCriteria")
  138.             else
  139.                 if isStockUp then
  140.                     if (dStockPercentChange >= dComparedSymbolPercentChange) then
  141.                         GlobalColor("WarningState")
  142.                     else GlobalColor("DoesNotMeetCriteria")
  143.                 else
  144.                     if (dStockPercentChange <= dComparedSymbolPercentChange)then
  145.                         GlobalColor("MeetsCriteria")
  146.                     else GlobalColor("DoesNotMeetCriteria")
  147.          );
  148.  
  149.  
  150.  
  151. ############################################################
  152. #Get current bid-ask spread
  153.        
  154.  
  155. def bidAskSpread = close(priceType = PriceType.ASK) - close(priceType = PriceType.BID);
  156.  
  157. AddLabel(   yes,
  158.             (if (bidAskSpread > minBidAskSpread) then symbolUpPrefix else symbolDownPrefix )
  159.             + " SPREAD"
  160.             + "          "
  161.             + AsText(bidAskSpread, NumberFormat.TWO_DECIMAL_PLACES)
  162.             + "                        " ,
  163.  
  164.             if isComparedSymbolUp then
  165.                 if isStockUp then
  166.                     if (bidAskSpread > minBidAskSpread) then
  167.                         GlobalColor("DoesNotMeetCriteria")
  168.                     else GlobalColor("MeetsCriteria")
  169.                 else
  170.                     if (bidAskSpread > minBidAskSpread) then
  171.                         GlobalColor("DoesNotMeetCriteria")
  172.                     else GlobalColor("WarningState")
  173.             else
  174.                 if isStockUp then
  175.                     if (bidAskSpread > minBidAskSpread) then
  176.                         GlobalColor("DoesNotMeetCriteria")
  177.                     else GlobalColor("WarningState")
  178.                 else
  179.                     if (bidAskSpread > minBidAskSpread)then
  180.                         GlobalColor("DoesNotMeetCriteria")
  181.                     else GlobalColor("MeetsCriteria")
  182.          );
  183.  
  184.  
  185. ############################################################
  186. #Is current ATR above or below desired ATR on a daily timeframe?
  187. def currentATR = Round(WildersAverage(TrueRange(high(period = aggregationPeriod),
  188.                                       close(period = aggregationPeriod),
  189.                                       low(period = aggregationPeriod)
  190.                                      ),
  191.                         atrLength), 2
  192.                        );
  193.  
  194. AddLabel(   yes,
  195.             (if (currentATR > minATR) then symbolUpPrefix else symbolDownPrefix )
  196.             + " ATR(" + atrLength + "D)"
  197.             + "         "
  198.             + AsText((currentATR))
  199.             + "                       " ,
  200.                
  201.             if isComparedSymbolUp then
  202.                 if isStockUp then
  203.                     if (currentATR > minATR) then
  204.                         GlobalColor("MeetsCriteria")
  205.                     else GlobalColor("DoesNotMeetCriteria")
  206.                 else
  207.                     if (currentATR > minATR) then
  208.                         GlobalColor("WarningState")
  209.                     else GlobalColor("DoesNotMeetCriteria")
  210.             else
  211.                 if isStockUp then
  212.                     if (currentATR > minATR) then
  213.                         GlobalColor("WarningState")
  214.                     else GlobalColor("DoesNotMeetCriteria")
  215.                 else
  216.                     if (currentATR > minATR)then
  217.                         GlobalColor("MeetsCriteria")
  218.                     else GlobalColor("DoesNotMeetCriteria")
  219.          );
  220.          
  221.  
  222. ############################################################
  223. #Get number of transactions per minute
  224. #input showTxCount = yes;
  225. #def tradeAggregationPeriod = AggregationPeriod.FIVE_MIN;
  226. #def txCount = tick_count( period=tradeAggregationPeriod, priceType=PriceType.LAST);
  227. #def txCount = tick_count;
  228.  
  229. #def pastTxCount = tick_count( period=tradeAggregationPeriod, priceType=PriceType.LAST)[1];
  230.  
  231. #AddLabel(  yes,
  232. #           " TRADES             "
  233. #           + AsText(txCount, "%1$.0f")
  234. #           + " | "
  235. #           + AsText(pastTxCount, "%1$.0f")
  236. #           + "            ",
  237. #           Color.White
  238. #        );
  239.  
  240.  
  241.  
  242.  
  243. ############################################################
  244. #Get Day Type - Up-Side, Down-Side, Inside,
  245. AddLabel(   yes,
  246.             if (dStockLast > YHigh)
  247.                 then "  DAY-TYPE       UP                       "
  248.                 else if (dStockLast >= YLow)
  249.                     then "  DAY-TYPE       INSIDE                  "
  250.                     else "  DAY-TYPE        DOWN                ",
  251.  
  252.             if isComparedSymbolUp then
  253.                 if isStockUp then
  254.                     if (dStockLast > YHigh) then
  255.                         GlobalColor("MeetsCriteria")
  256.                     else GlobalColor("DoesNotMeetCriteria")
  257.                 else
  258.                     if (dStockLast < YLow) then
  259.                         GlobalColor("WarningState")
  260.                     else GlobalColor("DoesNotMeetCriteria")
  261.             else
  262.                 if isStockUp then
  263.                     if (dStockLast > YHigh) then
  264.                         GlobalColor("WarningState")
  265.                     else GlobalColor("DoesNotMeetCriteria")
  266.                 else
  267.                     if (dStockLast < YLow)then
  268.                         GlobalColor("MeetsCriteria")
  269.                     else GlobalColor("DoesNotMeetCriteria")
  270.          );
  271.  
  272.  
  273.  
  274. ############################################################
  275. #Add empty row as separator
  276. AddLabel(   yes,
  277.             "                                               ",
  278.             GlobalColor("SeparatorRowColor")
  279.         );
  280.  
  281.  
  282.  
  283. ############################################################
  284. #Source: https://www.reddit.com/r/RealDayTrading/comments/rpi75s/real_relative_strength_indicator/
  285. #Real Relative Strength (Rolling)
  286. #Created By u/WorkPiece 12.26.21
  287. #Concept by u/HSeldon2020
  288.  
  289. input RRSLength = 12; #Hint RRSLength: value of 12 on 5m chart = 1 hour of rolling data
  290.  
  291. ##########Rolling Price Change##########
  292. def comparedRollingMove = close(symbol = ComparedWithSecurity) - close(symbol = ComparedWithSecurity)[RRSLength];
  293. def symbolRollingMove = close - close[RRSLength];
  294.  
  295. ##########Rolling ATR Change##########
  296. def symbolRollingATR = WildersAverage(TrueRange(high[1], close[1], low[1]), RRSLength);
  297. def comparedRollingATR = WildersAverage(TrueRange(high(symbol = ComparedWithSecurity)[1], close(symbol = ComparedWithSecurity)[1], low(symbol = ComparedWithSecurity)[1]), RRSLength);
  298.  
  299.  
  300. ##########Calculations##########
  301. def powerIndex = comparedRollingMove / comparedRollingATR;
  302. def expectedMove = powerIndex * symbolRollingATR;
  303. def diff = symbolRollingMove - expectedMove;
  304. def RRS = diff / symbolRollingATR;
  305.  
  306.  
  307. AddLabel(   yes,
  308.             if ComparedWithSecurity == GetSymbol()
  309.                 then "  RRS                   NA                    "
  310.                 else
  311.                     (if (RRS > 0) then symbolUpPrefix else symbolDownPrefix )
  312.                     + " RRS "
  313.                     + "                "
  314.                     + AsText((RRS))
  315.                     + "                       ",
  316.                            
  317.             if ComparedWithSecurity == GetSymbol()
  318.                 then GlobalColor("MeetsCriteria")
  319.             else
  320.                 if isComparedSymbolUp then
  321.                     if isStockUp then
  322.                         if (RRS > 0) then
  323.                             GlobalColor("MeetsCriteria")
  324.                         else GlobalColor("DoesNotMeetCriteria")
  325.                     else
  326.                         if (RRS > 0) then
  327.                             GlobalColor("DoesNotMeetCriteria")
  328.                         else GlobalColor("WarningState")
  329.                 else
  330.                     if isStockUp then
  331.                         if (RRS > 0) then
  332.                             GlobalColor("WarningState")
  333.                         else GlobalColor("DoesNotMeetCriteria")
  334.                     else
  335.                         if (RRS > 0)then
  336.                             GlobalColor("DoesNotMeetCriteria")
  337.                         else GlobalColor("MeetsCriteria")
  338.          );
  339.  
  340.  
  341.  
  342. ############################################################
  343. # Source: https://www.reddit.com/r/RealDayTrading/comments/ue4ujq/tostv_timebased_relative_volume_rvol_a_better/
  344. # /u/HurlTeaInTheSea v1.0
  345. # Intraday Relative Volume (RVol) indicator:
  346.  
  347. # still works on higher timeframe but it's not a "day" average anymore, so throw error to avoid confusion
  348. addlabel(GetAggregationPeriod() > aggregationPeriod, "RVol is only valid for daily timeframe or lower");
  349.  
  350. input _nDayAverageForRVOL = 20;
  351.  
  352. def days = Max(_nDayAverageForRVOL, 1);
  353.  
  354. # detect new session of day
  355. def isNewDay = GetYYYYMMDD() != GetYYYYMMDD()[1];
  356.  
  357. def cVol;               # cumulative volume
  358. def cVolComp;           # cumulative volume of comp security
  359. def beforeNewDayBars;   # save bar number before new day
  360. def len;                # count number of new days
  361. if isNewDay {
  362.     cVol = volume;
  363.     cVolComp = volume(symbol = ComparedWithSecurity);
  364.     beforeNewDayBars = BarNumber() - 1;
  365.     len = len[1] + 1;
  366. } else {
  367.     cVol = cVol[1] + volume;
  368.     cVolComp = cVolComp[1] + volume(symbol = ComparedWithSecurity);
  369.     beforeNewDayBars = beforeNewDayBars[1];
  370.     len = len[1];
  371. }
  372.  
  373. # starting from last bar of previous session, go back in time and accumulate volume up to current time relative to trading day
  374. # stop after N day cumulative volume average collected
  375. def skip = BarNumber() - beforeNewDayBars;
  376. def aVol = fold i = skip to Max(skip, BarNumber())
  377.     with v = 0
  378.     while BarNumber() >= days + 1 && len >= days + 1 && len - 1 - GetValue(len, i) < days
  379.     do If(GetTime() - RegularTradingStart(GetYYYYMMDD()) >= GetValue(GetTime(), i) - RegularTradingStart(GetValue(GetYYYYMMDD(), i)), v + GetValue(volume, i) / days, v);
  380.  
  381. def aVolComp = fold j = skip to Max(skip, BarNumber())
  382.     with w = 0
  383.     while BarNumber() >= days + 1 && len >= days + 1 && len - 1 - GetValue(len, j) < days
  384.     do If(GetTime() - RegularTradingStart(GetYYYYMMDD()) >= GetValue(GetTime(), j) - RegularTradingStart(GetValue(GetYYYYMMDD(), j)), w + GetValue(volume(symbol = ComparedWithSecurity), j) / days, w);
  385.  
  386. def _rVol = if aVol > 0 then cVol / aVol else 0;
  387. def _rVolComp = if aVolComp > 0 then cVolComp / aVolComp else 0;
  388.  
  389. AddLabel(   yes,
  390.             (if _rVol > 1 then symbolUpPrefix else symbolDownPrefix )
  391.             + " RVOL(" + _nDayAverageForRVOL + "D)"
  392.             + "      "
  393.             + AsPercent(Round(_rVol))
  394.             + ( if ComparedWithSecurity != GetSymbol()
  395.                     then (" / " + AsPercent(Round(_rVolComp)) )
  396.                     else "" )
  397.             + "               ",
  398.                
  399.             if isComparedSymbolUp then
  400.                 if isStockUp then
  401.                     if (_rVol > 1.25 and _rVol > _RvolComp) then
  402.                         GlobalColor("MeetsCriteria")
  403.                     else GlobalColor("DoesNotMeetCriteria")
  404.                 else
  405.                     if (_rVol > 1.25 and _rVol > _RvolComp) then
  406.                         GlobalColor("WarningState")
  407.                     else GlobalColor("DoesNotMeetCriteria")
  408.             else
  409.                 if isStockUp then
  410.                     if (_rVol > 1.25 and _rVol > _RvolComp) then
  411.                         GlobalColor("WarningState")
  412.                     else GlobalColor("DoesNotMeetCriteria")
  413.                 else
  414.                     if (_rVol > 1.25 and _rVol > _RvolComp)then
  415.                         GlobalColor("MeetsCriteria")
  416.                     else GlobalColor("DoesNotMeetCriteria")
  417.          );
  418.          
  419.  
  420. ############################################################
  421. #Show current volume, average daily volume, volume fill
  422.  
  423. def cvFactorStock  = if( dCurrentDailyStockVolume < 1000000) then 1000 else 1000000;
  424. def dCurrentDailyStockVolume_factor = Round(dCurrentDailyStockVolume / cvFactorStock, 2);
  425.  
  426. def avFactorStock  = if( dAvgDailyStockVolume < 1000000) then 1000 else 1000000;
  427. def dAvgDailyStockVolume_factor = Round(dAvgDailyStockVolume / avFactorStock, 2);
  428.  
  429. AddLabel(   yes,
  430.             (if dAvgDailyStockVolume >= minDailyAverageVolume then symbolUpPrefix else symbolDownPrefix )
  431.             + " AvVOL(" + nDaysForDailyVolumeAverage + "D)"
  432.             + "    "
  433.             + dAvgDailyStockVolume_factor
  434.             + (if(dAvgDailyStockVolume < 1000000) then "K" else "M")
  435.             + "                     " ,
  436.  
  437.             if isComparedSymbolUp then
  438.                 if isStockUp then
  439.                     if (dAvgDailyStockVolume > minDailyAverageVolume) then
  440.                         GlobalColor("MeetsCriteria")
  441.                     else GlobalColor("DoesNotMeetCriteria")
  442.                 else
  443.                     if (dAvgDailyStockVolume > minDailyAverageVolume) then
  444.                         GlobalColor("WarningState")
  445.                     else GlobalColor("DoesNotMeetCriteria")
  446.             else
  447.                 if isStockUp then
  448.                     if (dAvgDailyStockVolume > minDailyAverageVolume) then
  449.                         GlobalColor("WarningState")
  450.                     else GlobalColor("DoesNotMeetCriteria")
  451.                 else
  452.                     if (dAvgDailyStockVolume > minDailyAverageVolume) then
  453.                         GlobalColor("MeetsCriteria")
  454.                     else GlobalColor("DoesNotMeetCriteria")
  455.          );
  456.          
  457.  
  458. AddLabel(   yes,
  459.             (if dCurrentDailyStockVolume >= minVolumeForToday then symbolUpPrefix else symbolDownPrefix )
  460.             + " VOLUME"
  461.             + "          "
  462.             + AsText(dCurrentDailyStockVolume_factor,NumberFormat.TWO_DECIMAL_PLACES)
  463.             + (if(dCurrentDailyStockVolume < 1000000) then "K" else "M")
  464.             + "                  " ,
  465.                
  466.             if isComparedSymbolUp then
  467.                 if isStockUp then
  468.                     if (dCurrentDailyStockVolume > minVolumeForToday) then
  469.                         GlobalColor("MeetsCriteria")
  470.                     else GlobalColor("DoesNotMeetCriteria")
  471.                 else
  472.                     if (dCurrentDailyStockVolume > minVolumeForToday) then
  473.                         GlobalColor("WarningState")
  474.                     else GlobalColor("DoesNotMeetCriteria")
  475.             else
  476.                 if isStockUp then
  477.                     if (dCurrentDailyStockVolume > minVolumeForToday) then
  478.                         GlobalColor("WarningState")
  479.                     else GlobalColor("DoesNotMeetCriteria")
  480.                 else
  481.                     if (dCurrentDailyStockVolume > minVolumeForToday)then
  482.                         GlobalColor("MeetsCriteria")
  483.                     else GlobalColor("DoesNotMeetCriteria")
  484.          );
  485.          
  486. ############################################################
  487. # Compare vol fill % of SPY vs current stock
  488. AddLabel(   yes,
  489.             (if (dStockVolumeFill > dComparedSymbolVolumeFill) then symbolUpPrefix else symbolDownPrefix )
  490.             + " VOL FILL"
  491.             + "         "
  492.             + AsPercent(Round(dStockVolumeFill))
  493.  
  494.             + ( if ComparedWithSecurity != GetSymbol()
  495.                     then (" / " + AsPercent(Round(dComparedSymbolVolumeFill)) )
  496.                     else "" )
  497.             +  "                 " ,
  498.  
  499.             if isComparedSymbolUp then
  500.                 if isStockUp then
  501.                     if (dStockVolumeFill < dComparedSymbolVolumeFill) then
  502.                         GlobalColor("DoesNotMeetCriteria")
  503.                     else GlobalColor("MeetsCriteria")
  504.                 else
  505.                     if (dStockVolumeFill < dComparedSymbolVolumeFill) then
  506.                         GlobalColor("DoesNotMeetCriteria")
  507.                     else GlobalColor("WarningState")
  508.             else
  509.                 if isStockUp then
  510.                     if (dStockVolumeFill < dComparedSymbolVolumeFill) then
  511.                         GlobalColor("DoesNotMeetCriteria")
  512.                     else GlobalColor("WarningState")
  513.                 else
  514.                     if (dStockVolumeFill < dComparedSymbolVolumeFill)then
  515.                         GlobalColor("DoesNotMeetCriteria")
  516.                     else GlobalColor("MeetsCriteria")
  517.          );
  518.  
  519.          
  520.  
  521. ############################################################
  522. #Add empty row as separator
  523. AddLabel(   yes,
  524.             "                                               ",
  525.             GlobalColor("SeparatorRowColor")
  526.         );
  527.  
  528.  
  529. ############################################################
  530. #Is current ticker above or below YClose on an intraday timeframe?
  531. AddLabel(   yes,  
  532.  
  533.             (if isStockUp then symbolUpPrefix else symbolDownPrefix )
  534.             + " YCLOSE "
  535.             + "         "
  536.             + AsText((dStockDayChange))
  537.             + "                     " ,
  538.  
  539.             if isComparedSymbolUp then
  540.                 if isStockUp then
  541.                     if (dStockLast > dStockPrevDayClose) then
  542.                         GlobalColor("MeetsCriteria")
  543.                     else GlobalColor("DoesNotMeetCriteria")
  544.                 else
  545.                     if (dStockLast > dStockPrevDayClose) then
  546.                         GlobalColor("DoesNotMeetCriteria")
  547.                     else GlobalColor("WarningState")
  548.             else
  549.                 if isStockUp then
  550.                     if (dStockLast > dStockPrevDayClose) then
  551.                         GlobalColor("WarningState")
  552.                     else GlobalColor("DoesNotMeetCriteria")
  553.                 else
  554.                     if (dStockLast > dStockPrevDayClose)then
  555.                         GlobalColor("DoesNotMeetCriteria")
  556.                     else GlobalColor("MeetsCriteria")
  557.         );
  558.  
  559.  
  560. ############################################################
  561. #Is current ticker above or below VWAP on an intraday timeframe?
  562.  
  563. AddLabel(   yes,  
  564.             (if dStockLast > dVWAP then symbolUpPrefix else symbolDownPrefix )
  565.             + " VWAP "
  566.             + "             "
  567.             + AsText((dStockLast-dVWAP))
  568.             + "                     " ,
  569.            
  570.             if isComparedSymbolUp then
  571.                 if isStockUp then
  572.                     if (dStockLast > dVWAP) then
  573.                         GlobalColor("MeetsCriteria")
  574.                     else GlobalColor("DoesNotMeetCriteria")
  575.                 else
  576.                     if (dStockLast > dVWAP) then
  577.                         GlobalColor("DoesNotMeetCriteria")
  578.                     else GlobalColor("WarningState")
  579.             else
  580.                 if isStockUp then
  581.                     if (dStockLast > dVWAP) then
  582.                         GlobalColor("WarningState")
  583.                     else GlobalColor("DoesNotMeetCriteria")
  584.                 else
  585.                     if (dStockLast > dVWAP) then
  586.                         GlobalColor("DoesNotMeetCriteria")
  587.                     else GlobalColor("MeetsCriteria")
  588.         );
  589.  
  590.  
  591. ############################################################
  592. #Is current ticker above or below today's Open on an intraday timeframe?
  593.  
  594. AddLabel(   yes,
  595.             (if dStockLast > todayOpen then symbolUpPrefix else symbolDownPrefix )
  596.              + " OPEN "
  597.              + "              "
  598.              + AsText((dStockLast-todayOpen))
  599.              + "                     " ,
  600.  
  601.             if isComparedSymbolUp then
  602.                 if isStockUp then
  603.                     if (dStockLast > todayOpen) then
  604.                         GlobalColor("MeetsCriteria")
  605.                     else GlobalColor("DoesNotMeetCriteria")
  606.                 else
  607.                     if (dStockLast > todayOpen) then
  608.                         GlobalColor("DoesNotMeetCriteria")
  609.                     else GlobalColor("WarningState")
  610.             else
  611.                 if isStockUp then
  612.                     if (dStockLast > todayOpen) then
  613.                         GlobalColor("WarningState")
  614.                     else GlobalColor("DoesNotMeetCriteria")
  615.                 else
  616.                     if (dStockLast > todayOpen)then
  617.                         GlobalColor("DoesNotMeetCriteria")
  618.                     else GlobalColor("MeetsCriteria")                
  619.         );
  620.  
  621. ############################################################
  622. #Is current ticker above or below YHigh/YLow on an intraday timeframe?
  623.  
  624. AddLabel(   yes,  
  625.             (if dStockLast > YHigh then symbolUpPrefix else symbolDownPrefix )
  626.             + " YHIGH "
  627.             + "            "
  628.             + AsText((dStockLast-yHigh))
  629.             + "                      " ,
  630.            
  631.             if isComparedSymbolUp then
  632.                 if isStockUp then
  633.                     if (dStockLast > YHigh) then
  634.                         GlobalColor("MeetsCriteria")
  635.                     else GlobalColor("DoesNotMeetCriteria")
  636.                 else
  637.                     if (dStockLast > YHigh) then
  638.                         GlobalColor("DoesNotMeetCriteria")
  639.                     else GlobalColor("WarningState")
  640.             else
  641.                 if isStockUp then
  642.                     if (dStockLast > YHigh) then
  643.                         GlobalColor("WarningState")
  644.                     else GlobalColor("DoesNotMeetCriteria")
  645.                 else
  646.                     if (dStockLast > YHigh)then
  647.                         GlobalColor("DoesNotMeetCriteria")
  648.                     else GlobalColor("MeetsCriteria")                      
  649.         );
  650.  
  651. AddLabel(   yes,  
  652.  
  653.             (if dStockLast > YLow then symbolUpPrefix else symbolDownPrefix )
  654.             + " YLOW "
  655.             + "             "
  656.             + AsText((dStockLast-yLow))
  657.             + "                      ",
  658.            
  659.             if isComparedSymbolUp then
  660.                 if isStockUp then
  661.                     if (dStockLast > YLow) then
  662.                         GlobalColor("MeetsCriteria")
  663.                     else GlobalColor("DoesNotMeetCriteria")
  664.                 else
  665.                     if (dStockLast > YLow) then
  666.                         GlobalColor("DoesNotMeetCriteria")
  667.                     else GlobalColor("WarningState")
  668.             else
  669.                 if isStockUp then
  670.                     if (dStockLast > YLow) then
  671.                         GlobalColor("WarningState")
  672.                     else GlobalColor("DoesNotMeetCriteria")
  673.                 else
  674.                     if (dStockLast > YLow)then
  675.                         GlobalColor("DoesNotMeetCriteria")
  676.                     else GlobalColor("MeetsCriteria")                    
  677.         );
  678.  
  679.  
  680.  
  681. ############################################################
  682. #Is current ticker above or below 20-Day High/Low on a daily timeframe?
  683.  
  684. AddLabel(   yes,  
  685.             (if dStockLast > twentyDayHigh then symbolUpPrefix else symbolDownPrefix )
  686.             + " D20 HIGH "
  687.             + "       "
  688.             + AsText((dStockLast-twentyDayHigh))
  689.             + "                        " ,
  690.            
  691.             if isComparedSymbolUp then
  692.                 if isStockUp then
  693.                     if (dStockLast > twentyDayHigh) then
  694.                         GlobalColor("MeetsCriteria")
  695.                     else GlobalColor("DoesNotMeetCriteria")
  696.                 else
  697.                     if (dStockLast > twentyDayHigh) then
  698.                         GlobalColor("DoesNotMeetCriteria")
  699.                     else GlobalColor("WarningState")
  700.             else
  701.                 if isStockUp then
  702.                     if (dStockLast > twentyDayHigh) then
  703.                         GlobalColor("WarningState")
  704.                     else GlobalColor("DoesNotMeetCriteria")
  705.                 else
  706.                     if (dStockLast > twentyDayHigh)then
  707.                         GlobalColor("DoesNotMeetCriteria")
  708.                     else GlobalColor("MeetsCriteria")                      
  709.         );
  710.  
  711. AddLabel(   yes,  
  712.             (if dStockLast > twentyDayLow then symbolUpPrefix else symbolDownPrefix )
  713.             + " D20 LOW "
  714.             + "        "
  715.             + AsText((dStockLast-twentyDayLow))
  716.             + "                      ",
  717.            
  718.             if isComparedSymbolUp then
  719.                 if isStockUp then
  720.                     if (dStockLast > twentyDayLow) then
  721.                         GlobalColor("MeetsCriteria")
  722.                     else GlobalColor("DoesNotMeetCriteria")
  723.                 else
  724.                     if (dStockLast > twentyDayLow) then
  725.                         GlobalColor("DoesNotMeetCriteria")
  726.                     else GlobalColor("WarningState")
  727.             else
  728.                 if isStockUp then
  729.                     if (dStockLast > twentyDayLow) then
  730.                         GlobalColor("WarningState")
  731.                     else GlobalColor("DoesNotMeetCriteria")
  732.                 else
  733.                     if (dStockLast > twentyDayLow)then
  734.                         GlobalColor("DoesNotMeetCriteria")
  735.                     else GlobalColor("MeetsCriteria")                    
  736.         );
  737.  
  738.  
  739.  
  740. ############################################################
  741. #Is current ticker above or below 50/100/200SMA on an intraday timeframe?
  742. def averageType = AverageType.SIMPLE;
  743.  
  744. def d50SMA = MovingAverage(averageType,
  745.                            Fundamental(priceType, period = aggregationPeriod),
  746.                            50
  747.                           );
  748. def d100SMA = MovingAverage(averageType,
  749.                             Fundamental(priceType, period = aggregationPeriod),
  750.                             100
  751.                            );
  752. def d200SMA = MovingAverage(averageType,
  753.                             Fundamental(priceType, period = aggregationPeriod),
  754.                             200
  755.                            );
  756.  
  757. AddLabel(   yes,  
  758.             (if dStockLast > d50SMA then symbolUpPrefix else symbolDownPrefix )
  759.             + " 50SMA(D) "
  760.             + "       "
  761.             + AsText((dStockLast-d50SMA))
  762.             + "                      "  ,
  763.            
  764.             if isComparedSymbolUp then
  765.                 if isStockUp then
  766.                     if (dStockLast > d50SMA) then
  767.                         GlobalColor("MeetsCriteria")
  768.                     else GlobalColor("DoesNotMeetCriteria")
  769.                 else
  770.                     if (dStockLast > d50SMA) then
  771.                         GlobalColor("DoesNotMeetCriteria")
  772.                     else GlobalColor("WarningState")
  773.             else
  774.                 if isStockUp then
  775.                     if (dStockLast > d50SMA) then
  776.                         GlobalColor("WarningState")
  777.                     else GlobalColor("DoesNotMeetCriteria")
  778.                 else
  779.                     if (dStockLast > d50SMA)then
  780.                         GlobalColor("DoesNotMeetCriteria")
  781.                     else GlobalColor("MeetsCriteria")                  
  782.          );
  783.  
  784. AddLabel(   yes,  
  785.             (if dStockLast > d100SMA then symbolUpPrefix else symbolDownPrefix )
  786.             + " 100SMA(D) "
  787.             + "     "
  788.             + AsText((dStockLast-d100SMA))
  789.             + "                      "  ,
  790.            
  791.             if isComparedSymbolUp then
  792.                 if isStockUp then
  793.                     if (dStockLast > d100SMA) then
  794.                         GlobalColor("MeetsCriteria")
  795.                     else GlobalColor("DoesNotMeetCriteria")
  796.                 else
  797.                     if (dStockLast > d100SMA) then
  798.                         GlobalColor("DoesNotMeetCriteria")
  799.                     else GlobalColor("WarningState")
  800.             else
  801.                 if isStockUp then
  802.                     if (dStockLast > d100SMA) then
  803.                         GlobalColor("WarningState")
  804.                     else GlobalColor("DoesNotMeetCriteria")
  805.                 else
  806.                     if (dStockLast > d100SMA)then
  807.                         GlobalColor("DoesNotMeetCriteria")
  808.                     else GlobalColor("MeetsCriteria")
  809.         );
  810.  
  811. AddLabel(   yes,
  812.             (if dStockLast > d200SMA then symbolUpPrefix else symbolDownPrefix )
  813.             + " 200SMA(D) "
  814.             + "     "
  815.             + AsText((dStockLast-d200SMA))
  816.             + "                      " ,
  817.                
  818.             if isComparedSymbolUp then
  819.                 if isStockUp then
  820.                     if (dStockLast > d200SMA) then
  821.                         GlobalColor("MeetsCriteria")
  822.                     else GlobalColor("DoesNotMeetCriteria")
  823.                 else
  824.                     if (dStockLast > d200SMA) then
  825.                         GlobalColor("DoesNotMeetCriteria")
  826.                     else GlobalColor("WarningState")
  827.             else
  828.                 if isStockUp then
  829.                     if (dStockLast > d200SMA) then
  830.                         GlobalColor("WarningState")
  831.                     else GlobalColor("DoesNotMeetCriteria")
  832.                 else
  833.                     if (dStockLast > d200SMA)then
  834.                         GlobalColor("DoesNotMeetCriteria")
  835.                     else GlobalColor("MeetsCriteria")
  836.         );
  837.  
  838.  
  839.  
  840.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement