retesere20

---recycler----

Aug 2nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.48 KB | None | 0 0
  1. // ============= By UpWork.com/fl/pavletabatadze ============//
  2. // v1: http://tinyurl.com/y729ue8d , v2: http://tinyurl.com/yb2ch7p9
  3. //@version=3
  4.  
  5. study("Hi-Lo Between Crossovers", overlay=true, max_bars_back=5000)
  6.  
  7. ma1_length = input(defval=10, type=integer)
  8. ma2_length = input(defval=30, type=integer)
  9. show_ema_lines = input(defval=false)
  10. //max_arrows = input(defval=10, type=integer, title="Arrows amount (max.10)" )
  11. max_arrows = 10
  12. start_arrows_offset = input(defval=0, type=integer, title="start plotting from last X arrows" )
  13.  
  14. ma1_val = ema(close, ma1_length)
  15. ma2_val = ema(close, ma2_length)
  16.  
  17. plot( show_ema_lines ? ma1_val : na, color= green, title="MA 1")
  18. plot( show_ema_lines ? ma2_val : na, color= red, title="MA 2")
  19.  
  20. arrow_down_color = green
  21. arrow_up_color =red
  22.  
  23.  
  24. highest_(values, length) =>
  25. h_val = na
  26. if length >= 1
  27. for i = 0 to length-1
  28. if (na(h_val) or (not na(values[i]) and values[i] > h_val) )
  29. h_val := values[i]
  30. h_val
  31.  
  32. lowest_(values, length) =>
  33. l_val = na
  34. if length >= 1
  35. for i = 0 to length-1
  36. if (na(l_val) or (not na(values[i]) and values[i] < l_val) )
  37. l_val := values[i]
  38. l_val
  39.  
  40.  
  41. cross_up = ma1_val > ma2_val
  42. cross_down = ma1_val < ma2_val
  43. cross_up_first = cross_up and not cross_up[1]
  44. cross_down_first= cross_down and not cross_down[1]
  45.  
  46. cross_up_first_count = 0
  47. cross_up_first_count := cross_up_first ? cross_up_first_count[1] +1 : cross_up_first_count[1]
  48.  
  49. cross_down_first_count = 0
  50. cross_down_first_count := cross_down_first ? cross_down_first_count[1] +1 : cross_down_first_count[1]
  51.  
  52. // count_to_last_up = 0.0
  53. // count_to_last_up := cross_up_first or cross_down_first ? 0 : count_to_last_up[1] + 1
  54. // count_to_last_down = 0.0
  55. // count_to_last_down := cross_down_first or cross_up_first ? 0 : count_to_last_down[1] + 1
  56.  
  57. highest_after_last_cross = 0.0
  58. highest_after_last_cross := cross_down_first or cross_up_first? high : ( high > highest_after_last_cross[1] ? high : highest_after_last_cross[1])
  59. lowest_after_last_cross = 0.0
  60. lowest_after_last_cross := cross_up_first or cross_down_first ? low : ( low < lowest_after_last_cross[1] ? low : lowest_after_last_cross[1])
  61.  
  62. highest_bn_last_offset = 0.0
  63. highest_bn_last_offset := cross_up_first or cross_down_first ? 0 : ( high == highest_after_last_cross ? 0 : highest_bn_last_offset[1] + 1 )
  64.  
  65. lowest_bn_last_offset = 0.0
  66. lowest_bn_last_offset := cross_down_first or cross_up_first ? 0 : ( low == lowest_after_last_cross ? 0 : lowest_bn_last_offset[1] + 1 )
  67.  
  68.  
  69.  
  70.  
  71. offset_h = round(highest_bn_last_offset)
  72. offset_l = round(lowest_bn_last_offset)
  73. o_h = -offset_h[1]
  74. o_l = -offset_l[1]
  75.  
  76. // as we have large loops, lets divide the functions (so, less if/else in checking). also, create offsets to save time
  77.  
  78. crosser_high(which_arrow, start_offset) =>
  79. x=0
  80. cross_counter=0
  81. for i=start_offset to start_offset+4999
  82. if (cross_down_first[i])
  83. cross_counter := cross_counter+1
  84. if (cross_counter==which_arrow)
  85. x := - i + o_h[i] -1
  86. break
  87. x
  88.  
  89. crosser_low(which_arrow, start_offset) =>
  90. x=0
  91. cross_counter=0
  92. for i=start_offset to start_offset+4999
  93. if (cross_up_first[i])
  94. cross_counter := cross_counter+1
  95. if (cross_counter==which_arrow)
  96. x := - i + o_l[i] -1
  97. break
  98. x
  99.  
  100.  
  101. start_offset_h = not barstate.islast ? 0 : -crosser_high( start_arrows_offset, 0 )
  102. start_offset_l = not barstate.islast ? 0 : -crosser_low( start_arrows_offset, 0 )
  103.  
  104. ofs_h1= max_arrows < 1 ? 0 : crosser_high(1, start_offset_h)
  105. plotchar(barstate.islast and ofs_h1!=0 ? true:na, offset=ofs_h1, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
  106. ofs_l1= max_arrows < 1 ? 0 : crosser_low(1, start_offset_l)
  107. plotchar(barstate.islast and ofs_l1!=0 ? true:na, offset=ofs_l1, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
  108.  
  109. ofs_h2= max_arrows < 2 ? 0 : crosser_high(2, start_offset_h)
  110. plotchar(barstate.islast and ofs_h2!=0 ? true:na, offset=ofs_h2, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
  111. ofs_l2= max_arrows < 2 ? 0 : crosser_low(2, start_offset_l)
  112. plotchar(barstate.islast and ofs_l2!=0 ? true:na, offset=ofs_l2, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
  113.  
  114. ofs_h3= max_arrows < 3 ? 0 : crosser_high(3, start_offset_h)
  115. plotchar(barstate.islast and ofs_h3!=0 ? true:na, offset=ofs_h3, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
  116. ofs_l3= max_arrows < 3 ? 0 : crosser_low(3, start_offset_l)
  117. plotchar(barstate.islast and ofs_l3!=0 ? true:na, offset=ofs_l3, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
  118.  
  119. ofs_h4= max_arrows < 4 ? 0 : crosser_high(4, start_offset_h)
  120. plotchar(barstate.islast and ofs_h4!=0 ? true:na, offset=ofs_h4, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
  121. ofs_l4= max_arrows < 4 ? 0 : crosser_low(4, start_offset_l)
  122. plotchar(barstate.islast and ofs_l4!=0 ? true:na, offset=ofs_l4, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
  123.  
  124. ofs_h5= max_arrows < 5 ? 0 : crosser_high(5, start_offset_h)
  125. plotchar(barstate.islast and ofs_h5!=0 ? true:na, offset=ofs_h5, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
  126. ofs_l5= max_arrows < 5 ? 0 : crosser_low(5, start_offset_l)
  127. plotchar(barstate.islast and ofs_l5!=0 ? true:na, offset=ofs_l5, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
  128.  
  129. ofs_h6= max_arrows < 6 ? 0 : crosser_high(6, start_offset_h)
  130. plotchar(barstate.islast and ofs_h6!=0 ? true:na, offset=ofs_h6, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
  131. ofs_l6= max_arrows < 6 ? 0 : crosser_low(6, start_offset_l)
  132. plotchar(barstate.islast and ofs_l6!=0 ? true:na, offset=ofs_l6, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
  133.  
  134. ofs_h7= max_arrows < 7 ? 0 : crosser_high(7, start_offset_h)
  135. plotchar(barstate.islast and ofs_h7!=0 ? true:na, offset=ofs_h7, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
  136. ofs_l7= max_arrows < 7 ? 0 : crosser_low(7, start_offset_l)
  137. plotchar(barstate.islast and ofs_l7!=0 ? true:na, offset=ofs_l7, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
  138.  
  139. ofs_h8= max_arrows < 8 ? 0 : crosser_high(8, start_offset_h)
  140. plotchar(barstate.islast and ofs_h8!=0 ? true:na, offset=ofs_h8, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
  141. ofs_l8= max_arrows < 8 ? 0 : crosser_low(8, start_offset_l)
  142. plotchar(barstate.islast and ofs_l8!=0 ? true:na, offset=ofs_l8, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
  143.  
  144. ofs_h9= max_arrows < 9 ? 0 : crosser_high(9, start_offset_h)
  145. plotchar(barstate.islast and ofs_h9!=0 ? true:na, offset=ofs_h9, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
  146. ofs_l9= max_arrows < 9 ? 0 : crosser_low(9, start_offset_l)
  147. plotchar(barstate.islast and ofs_l9!=0 ? true:na, offset=ofs_l9, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
  148.  
  149. ofs_h10= max_arrows < 10 ? 0 : crosser_high(10, start_offset_h)
  150. plotchar(barstate.islast and ofs_h10!=0 ? true:na, offset=ofs_h10, char="⬇", color=arrow_down_color, size=size.small, location=location.abovebar)
  151. ofs_l10= max_arrows < 10 ? 0 : crosser_low(10, start_offset_l)
  152. plotchar(barstate.islast and ofs_l10!=0 ? true:na, offset=ofs_l10, char="⬆", color=arrow_up_color, size=size.small, location=location.belowbar)
Add Comment
Please, Sign In to add comment