Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 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)
  14.  
  15. // Source we will be averaging.
  16. source = volume
  17.  
  18. // Defines 15 min window Murat is interested in.
  19. timeSession = time(timeframe.period, "1430-1445")
  20.  
  21. // Condition on which we want to calculate our average.
  22. condition = false
  23.  
  24. // // The following taken from: https://stackoverflow.com/questions/58063534/find-high-low-for-a-particular-intraday-time-interval
  25. // locVol = 0.0
  26.  
  27. // // Gets the high/low from the 1min resolution.
  28. // sessionVolume = security(syminfo.tickerid, "15", volume, lookahead=true)
  29.  
  30. // // The hour info below should line up with this info. time_session1 = time(timeframe.period, "1700-1701")
  31. if hour == 14 and minute == 30
  32. condition := true
  33. // locVol := sessionVolume
  34. // else
  35. // locVol := locVol[1]
  36.  
  37. // Condition on which we want to calculate our average.
  38. // condition = change(timeSession) and timeSession==1
  39.  
  40. // if change(timeSession) and timeSession==1
  41. // condition := 1
  42.  
  43. // ————— Case 2. The average of "source" for the last "x" occurrences where "condition" is true.
  44. x = input(3, "Case 2: Average this many last occurrences")
  45. avgWhenLast(_src, _cond, _cnt) =>
  46. // Returns average of _src for the last _cnt occurrences of _cond (lookback length = _cnt*10).
  47. _total = 0.0
  48. _count = 0
  49. // Since we don't know how many bars we must go back to find the x occurrences we need,
  50. // we use _cnt*10 as the lookback upper bound, hoping we can find what we need in those bars.
  51. // This will generate a runtime error if _cnt is too high.
  52. // On the 15min chart the conditon occurs every 96 bars. If using 30 conditions as average would need _cnt*2880
  53. _loopLimit = _cnt * 1666
  54. for _i = 0 to _loopLimit
  55. if _cond[_i]
  56. // We found an occurrence, increment count and add source to total.
  57. _count := _count + 1
  58. _total := _total + _src[_i]
  59. if _count == _cnt
  60. // We've reached our count, exit loop.
  61. break
  62. // Calculate average. If we haven't found the required number of occurrences, set to na.
  63. _average = _count == _cnt ? _total / _cnt : na
  64.  
  65. plot(avgWhenLast(source, condition, x), "Case 2 Average", color.fuchsia)
  66.  
  67. // Plots and Debug Plots
  68. // plot (locVol, title="Session Volume", color=color.aqua, style=plot.style_linebr)
  69. plot(condition==true?1:0, title= "Condition", transp=100)
  70. plot(na(timeSession) ? 0 : 1, title="timeSession", transp=100)
  71. // plot(locVol, title="locVol", transp=100)
  72.  
  73. //END//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement