Advertisement
Alpha-Blend

75551345 support

Feb 24th, 2023
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. var print_stack_absciss = array.new_int()
  2. var print_stack_string = array.new_string()
  3. var print_stack_color = array.new_color()
  4. var print_stack_range = array.new_int(2, 0)
  5.  
  6. secondsToTime(seconds) =>
  7. int res = 1000 * seconds
  8. res
  9.  
  10. getDt() =>
  11. int dt = secondsToTime(timeframe.in_seconds(timeframe.period))
  12. dt
  13.  
  14. getBarIndexAtTime(int _time_point) =>
  15. int m_bar_ind = na
  16. int i = 0
  17. for count = 0 to 5000
  18. if time[count] >= _time_point and time[count + 1] < _time_point
  19. m_bar_ind := count
  20. break
  21. // @returns
  22. m_bar_ind
  23.  
  24. timeToIndex(theTime) =>
  25. int index = getBarIndexAtTime(theTime)
  26. index
  27.  
  28. daysToTime(days)=>
  29. int theTimeDiff = math.round(days*86400000)
  30.  
  31. indexToTime(index) =>
  32. int theTime = na
  33. if index >= 0
  34. theTime := time[index]
  35. else
  36. theTime := time - index * getDt()
  37. // theTime := time + daysToTime(2)
  38. theTime
  39.  
  40. getAbsciss(absciss, cfg="index") =>
  41. int indexToUse = na
  42. int timeToUse = na
  43. switch cfg
  44. "index" =>
  45. indexToUse := absciss
  46. timeToUse := indexToTime(absciss)
  47. "time" =>
  48. indexToUse := timeToIndex(absciss)
  49. timeToUse := absciss
  50. [indexToUse, timeToUse]
  51.  
  52. print(txt = "", color=color.gray, absciss=0, ordinate=0, where=low, size=1, cfg="index") =>
  53. if barstate.islast
  54. [indexToUse, timeToUse] = getAbsciss(absciss, cfg)
  55. int lowRange = array.get(print_stack_range, 0)
  56. int highRange = array.get(print_stack_range, 1)
  57. if indexToUse > highRange
  58. array.set(print_stack_range, 1, indexToUse)
  59. if indexToUse < lowRange
  60. array.set(print_stack_range, 0, indexToUse)
  61. print_stack_absciss.push(timeToUse)
  62. print_stack_color.push(color)
  63. print_stack_string.push(txt)
  64.  
  65. var global_print_counter = array.new_int()
  66. array.push(global_print_counter, 0)
  67. printB(txt = "", colour=color.gray, absciss=0, ordinate=0, where=low, size=1, cfg="index") =>
  68. if barstate.islast
  69. [indexToUse, timeToUse] = getAbsciss(absciss, cfg)
  70. if indexToUse < 0
  71. indexToUse := 0
  72. float cl = close[indexToUse]
  73. int print_counter = array.get(global_print_counter, 0)
  74. float whereAbouts = (where==low)? math.min(where[indexToUse], where[indexToUse+1]) : math.max(where[indexToUse], where[indexToUse+1])
  75. float y = (absciss)? whereAbouts - (ordinate+size)*0.005*cl : 0.98*cl - print_counter*0.005*cl
  76. printLabel = label.new(timeToUse, y, txt, style = label.style_none, textcolor=colour, xloc=xloc.bar_time)
  77. label.delete(printLabel[1])
  78. if absciss == 0
  79. array.set(global_print_counter, 0, print_counter + size)
  80.  
  81. GetLabels(start, end, labels) =>
  82. // texts = array.new_string(0, na)
  83. // abscisses = array.new_int(0, na)
  84. // ordinates = array.new_float(0, na)
  85. // colors = array.new_color(0, na)
  86. int size = array.size(print_stack_absciss)
  87. // var labels = array.new_label(labelsSize, na)
  88. // printB(str.format("start is {0}", start), absciss = -1)
  89. // printB(str.format("end is {0}", end), absciss = -1)
  90. // print(str.format("size is {0}", size))
  91. if size > 0
  92. for j = start to end
  93. int time_j = indexToTime(j)
  94. // print(str.format("j is {0}", j))
  95. strings = array.new_string(0, "")
  96. color color_i = na
  97. for i = 0 to size - 1
  98. // print(str.format("i is {0}", i))
  99. int absciss_i = array.get(print_stack_absciss, i)
  100. // print(str.format("absciss_i is {0}", absciss_i))
  101. if absciss_i == time_j
  102. string string_i = array.get(print_stack_string, i)
  103. strings.push(string_i)
  104. color_i := array.get(print_stack_color, i)
  105. if array.size(strings)
  106. // texts.push(array.join(strings, "\n"))
  107. // abscisses.push(time_j)
  108. // ordinates.push(high[(j<0)?0:j])
  109. // colors.push(color_i)
  110. // labels.push(label.new(time_j, high[(j<0)?0:j], array.join(strings, "\n"), style = label.style_label_down, color = color.new(color.white, 100), textcolor = color_i, xloc=xloc.bar_time))
  111. if array.size(labels)
  112. lbl = array.get(labels, j - start)
  113. // lbl = array.get(labels, j)
  114. label.set_xy(lbl, time_j, high[(j<0)?0:j])
  115. label.set_text(lbl, array.join(strings, "\n"))
  116. label.set_textcolor(lbl, color_i)
  117. // if array.size(labels)
  118. // for i = 0 to array.size(labels) - 1
  119. // label.delete(array.get(labels, i)[1])
  120. // // var label lbl = label.new(na, na, na, style = label.style_label_down, color = color.new(color.white, 100), xloc=xloc.bar_time)
  121. // // label.set_xy(lbl, time_j, high[(j<0)?0:j])
  122. // // label.set_text(lbl, array.join(strings, "\n"))
  123. // // label.set_textcolor(lbl, color_i)
  124.  
  125. //@version=5
  126. indicator("Label Test", overlay = true)
  127. print(str.format("Number is: {0}", 2), absciss = -20)
  128. print(str.format("Test is: {0}", 3), absciss = -20)
  129. print(str.format("Number is: {0}", 4), absciss = -10)
  130. print(str.format("Test is: {0}", 5), absciss = -10)
  131. plot(close)
  132.  
  133. // var label lbl = label.new(na, na, na, style = label.style_label_down, color = color.new(color.white, 100), xloc=xloc.bar_time)
  134. int start = array.get(print_stack_range, 0)
  135. int end = array.get(print_stack_range, 1)
  136. int labelsSize = end - start
  137. labels = array.new_label(0, na)
  138. // printB(str.format("labelsSize is {0}", labelsSize))
  139. for i = 0 to labelsSize - 1
  140. labels.push(label.new(na, na, na, style = label.style_label_down, color = color.new(color.white, 100), xloc=xloc.bar_time))
  141.  
  142. GetLabels(start, end, labels)
  143.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement