xmd79

Expected Liquidity

Dec 21st, 2022
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © RickSimpson
  3.  
  4. //@version=5
  5. indicator('Expected Liquidity', 'Expected Liquidity', true, max_lines_count=500, max_labels_count=500)
  6.  
  7. //Inputs
  8.  
  9. i_period = input.int(46, 'Period', minval=15, maxval=60, group='Expected Liquidity Settings')
  10.  
  11. //Constants Variables Declaration
  12.  
  13. highbar = true
  14. highfractal = true
  15. lowfractal = true
  16. closefractal = true
  17.  
  18. //Pivots Definition
  19.  
  20. hb = ta.highest(high, i_period)
  21. lb = ta.lowest(low, i_period)
  22. dist = hb - lb
  23.  
  24. //Fibonacci Levels Calculation
  25.  
  26. hf = hb - dist * 0.236
  27. chf = hb - dist * 0.382
  28. clf = hb - dist * 0.618
  29. lf = hb - dist * 0.764
  30.  
  31. //Premium/Discount Type Definition
  32.  
  33. pfractal = high > hb[1]
  34. dfractal = low < lb[1]
  35.  
  36. //Liquidity Levels Calculation
  37.  
  38. premiumexpectstart = hb[3] == hb[2] and hb[2] == hb[1] and pfractal
  39. discountexpectstart = lb[3] == lb[2] and lb[2] == lb[1] and dfractal
  40.  
  41. //Liquidity Range Calculation
  42.  
  43. highexpect = premiumexpectstart or high[1] == hb
  44. lowexpect = discountexpectstart or low[1] == lb
  45. highbar := highexpect ? true : lowexpect ? false : highbar[1]
  46. barexpin = ta.crossover(close, hf)
  47. barexpout = ta.crossunder(close, hf)
  48. highfractal := barexpin ? true : barexpout ? false : highfractal[1]
  49. fractexpin = ta.crossunder(close, lf)
  50. fractexpout = ta.crossover(close, lf)
  51. lowfractal := fractexpin ? true : fractexpout ? false : lowfractal[1]
  52. closefractal := not highfractal and not lowfractal ? true : false
  53.  
  54. //Drawing Calculation
  55.  
  56. stateislast = barstate.islast
  57. stateislast := barstate.isrealtime and timeframe.isintraday ? not barstate.isconfirmed : barstate.islast
  58. hbdtrue = stateislast and highfractal
  59. lbdtrue = stateislast and lowfractal
  60. chfdtrue = stateislast and closefractal and highbar
  61. clfdtrue = stateislast and closefractal and not highbar
  62.  
  63. //Conditions
  64.  
  65. hbexpect = hb
  66. hbexpect := hbdtrue ? hb : lbdtrue ? lf : chfdtrue ? hf : clfdtrue ? chf : na
  67. lbexpect = lb
  68. lbexpect := hbdtrue ? hf : lbdtrue ? lb : chfdtrue ? clf : clfdtrue ? lf : na
  69.  
  70. //Plotting
  71.  
  72. plot(hbexpect, 'Premium Liquidity Level', color.red, linewidth=3, offset=3)
  73. plot(lbexpect, 'Discount Liquidity Level', color.green, linewidth=3, offset=3)
  74.  
  75. //Alerts
  76.  
  77. if ta.cross(close, hbexpect)
  78. alert('Premium Liquidity Break! • ' + str.tostring(math.round_to_mintick(high)), alert.freq_once_per_bar)
  79. if ta.cross(close, lbexpect)
  80. alert('Discount Liquidity Break! • ' + str.tostring(math.round_to_mintick(low)), alert.freq_once_per_bar)
Advertisement
Add Comment
Please, Sign In to add comment