Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. // LOVE JOY PEACE PATIENCE KINDNESS GOODNESS FAITHFULNESS GENTLENESS SELF-CONTROL
  2. // © JoshuaMcGowan
  3.  
  4. //@version=4
  5. // Murat Notes: Calculate the volume from the core trading session opening 9.30-9.45 EST of the last 30 days. Build an average. This is the relative volume= RVol
  6. // Than look for the volume opening of the day. If it is 20% above the the Rvol it is a trending market. Means support and resistance levels rarely will hold. a break out or flush through resistance levels are quite probable.
  7. // in a range of +20%- -20% it is a normal trading day.
  8. // If opening volume is under 20% than it will probably be a ranging market (inside day, so inside last days volume area.)
  9.  
  10. // Original Code: https://www.tradingview.com/script/isSfahiX-Averages-PineCoders-FAQ/
  11. // @author=LucF, for PineCoders
  12.  
  13. study("Thirteen Friends - Relative Volume", overlay=false, max_bars_back=5000)
  14.  
  15. // Source we will be averaging. Testing using vol_sess1 as source to get around bar lookback limitation.
  16. source = volume
  17.  
  18. // Will be adding in Inputs for New York, London, and Tokyo
  19. // London - Opening Hours 8:00am (UTC 800)
  20. // New York - Opening Hours 9:30am (UTC 1430)
  21. // Tokyo - Opening Hours 9:00am (UTC 0000)
  22.  
  23. sessionType = input(title="Session Selection", options=["New York", "London", "Tokyo"], defval="New York")
  24.  
  25. session = sessionType == "New York" ? time(timeframe.period, "1430-1445") :
  26. sessionType == "London" ? time(timeframe.period, "0800-0815") :
  27. sessionType == "Tokyo" ? time(timeframe.period, "0000-0015") :
  28. na
  29.  
  30. // Defines 15 min window Murat is interested in. // Commented out when adding session selection inputs.
  31. // timeSession = time(timeframe.period, "1430-1445")
  32.  
  33. // Condition on which we want to calculate our average.
  34. condition = false
  35.  
  36. // The hour info below should line up with this info. time_session1 = time(timeframe.period, "1430-1445")
  37. // The following taken from: https://stackoverflow.com/questions/58063534/find-high-low-for-a-particular-intraday-time-interval
  38. if (hour == 14 and minute == 30) and (sessionType=="New York")
  39. condition := true
  40.  
  41. if (hour == 08 and minute == 00) and (sessionType=="London")
  42. condition := true
  43.  
  44. if (hour == 00 and minute == 00) and (sessionType=="Tokyo")
  45. condition := true
  46.  
  47. // ————— Case 2. The average of "source" for the last "x" occurrences where "condition" is true.
  48. x = input(30, "Opening Sessions")
  49. avgWhenLast(_src, _cond, _cnt) =>
  50. // Returns average of _src for the last _cnt occurrences of _cond (lookback length = _cnt*10).
  51. _total = 0.0
  52. _count = 0
  53. // Since we don't know how many bars we must go back to find the x occurrences we need,
  54. // we use _cnt*10 as the lookback upper bound, hoping we can find what we need in those bars.
  55. // This will generate a runtime error if _cnt is too high.
  56. // On the 15min chart the conditon occurs every 96 bars. If using 30 conditions as average would need 2880
  57. // _loopLimit = _cnt * 1666 // commenting out this original line since we do know how many bars back we need
  58. _loopLimit = 2881
  59. for _i = 0 to _loopLimit
  60. if _cond[_i]
  61. // We found an occurrence, increment count and add source to total.
  62. _count := _count + 1
  63. _total := _total + _src[_i]
  64. if _count == _cnt
  65. // We've reached our count, exit loop.
  66. break
  67. // Calculate average. If we haven't found the required number of occurrences, set to na.
  68. _average = _count == _cnt ? _total / _cnt : na
  69.  
  70. plot(avgWhenLast(source, condition, x), "Relative Volume", color.fuchsia)
  71.  
  72. // Now that we have the relative volume we can setup the +- 20% levels to monitor
  73.  
  74. limit = (avgWhenLast(source, condition, x)) * 0.2
  75. upper = (avgWhenLast(source, condition, x)) + limit
  76. lower = (avgWhenLast(source, condition, x)) - limit
  77.  
  78. // Adding in TV Vol Study
  79. barColorsOnPrevClose = input(title="Color bars based on previous close", type=input.bool, defval=false)
  80. palette = barColorsOnPrevClose ? close[1] > close ? color.red : color.green : open > close ? color.red : color.green
  81. plot(volume, color = palette, style=plot.style_columns, title="Volume", transp=65)
  82.  
  83. // Additional Plots and Debug Plots
  84. plot (upper, title="upper", color=color.aqua, style=plot.style_linebr, linewidth=2)
  85. plot (lower, title="lower", color=color.aqua, style=plot.style_linebr, linewidth=2)
  86. // plot(condition==true?1:0, title= "Condition", transp=100)
  87. // plot(na(timeSession) ? 0 : 1, title="timeSession", transp=100)
  88. // plot((volume[1] > upper[1]) and (condition[1]==true) ? 1 : 0, title="Trending Alert", transp=100)
  89. // plot((volume[1] < lower[1]) and (condition[1]==true) ? 1 : 0, title="Ranging Alert", transp=100)
  90.  
  91. // Labels
  92. showLabels = input(true, "Show Labels")
  93. trend = (volume[1] > upper[1]) and (condition[1]==true)
  94. range = (volume[1] < lower[1]) and (condition[1]==true)
  95.  
  96. plotshape(showLabels==true and trend ? upper : na, title="Trending Label", color=color.aqua, text="Hunt\nTrending Setups",
  97. textcolor=color.white,
  98. style=shape.labeldown,
  99. location=location.absolute)
  100.  
  101. plotshape(showLabels==true and range ? lower : na, title="Ranging Label", color=color.aqua, text="Hunt\nRanging Setups",
  102. textcolor=color.white,
  103. style=shape.labelup,
  104. location=location.absolute)
  105.  
  106. // Alert Conditions
  107. // Need to test these out fully but first crack at it. Might need timeSession[1]==1 and volume[1] for intended effect.
  108. alertcondition((volume[1] > upper[1]) and (condition[1]==true), title="Trending Market", message="Trending Market")
  109. alertcondition((volume[1] < lower[1]) and (condition[1]==true), title="Ranging Market", message="Ranging Market")
  110.  
  111. //PMAFTW//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement