Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var print_stack_absciss = array.new_int()
- var print_stack_string = array.new_string()
- var print_stack_color = array.new_color()
- var print_stack_range = array.new_int(2, 0)
- secondsToTime(seconds) =>
- int res = 1000 * seconds
- res
- getDt() =>
- int dt = secondsToTime(timeframe.in_seconds(timeframe.period))
- dt
- getBarIndexAtTime(int _time_point) =>
- int m_bar_ind = na
- int i = 0
- for count = 0 to 5000
- if time[count] >= _time_point and time[count + 1] < _time_point
- m_bar_ind := count
- break
- // @returns
- m_bar_ind
- timeToIndex(theTime) =>
- int index = getBarIndexAtTime(theTime)
- index
- daysToTime(days)=>
- int theTimeDiff = math.round(days*86400000)
- indexToTime(index) =>
- int theTime = na
- if index >= 0
- theTime := time[index]
- else
- theTime := time - index * getDt()
- // theTime := time + daysToTime(2)
- theTime
- getAbsciss(absciss, cfg="index") =>
- int indexToUse = na
- int timeToUse = na
- switch cfg
- "index" =>
- indexToUse := absciss
- timeToUse := indexToTime(absciss)
- "time" =>
- indexToUse := timeToIndex(absciss)
- timeToUse := absciss
- [indexToUse, timeToUse]
- print(txt = "", color=color.gray, absciss=0, ordinate=0, where=low, size=1, cfg="index") =>
- if barstate.islast
- [indexToUse, timeToUse] = getAbsciss(absciss, cfg)
- int lowRange = array.get(print_stack_range, 0)
- int highRange = array.get(print_stack_range, 1)
- if indexToUse > highRange
- array.set(print_stack_range, 1, indexToUse)
- if indexToUse < lowRange
- array.set(print_stack_range, 0, indexToUse)
- print_stack_absciss.push(timeToUse)
- print_stack_color.push(color)
- print_stack_string.push(txt)
- var global_print_counter = array.new_int()
- array.push(global_print_counter, 0)
- printB(txt = "", colour=color.gray, absciss=0, ordinate=0, where=low, size=1, cfg="index") =>
- if barstate.islast
- [indexToUse, timeToUse] = getAbsciss(absciss, cfg)
- if indexToUse < 0
- indexToUse := 0
- float cl = close[indexToUse]
- int print_counter = array.get(global_print_counter, 0)
- float whereAbouts = (where==low)? math.min(where[indexToUse], where[indexToUse+1]) : math.max(where[indexToUse], where[indexToUse+1])
- float y = (absciss)? whereAbouts - (ordinate+size)*0.005*cl : 0.98*cl - print_counter*0.005*cl
- printLabel = label.new(timeToUse, y, txt, style = label.style_none, textcolor=colour, xloc=xloc.bar_time)
- label.delete(printLabel[1])
- if absciss == 0
- array.set(global_print_counter, 0, print_counter + size)
- GetLabels(start, end, labels) =>
- // texts = array.new_string(0, na)
- // abscisses = array.new_int(0, na)
- // ordinates = array.new_float(0, na)
- // colors = array.new_color(0, na)
- int size = array.size(print_stack_absciss)
- // var labels = array.new_label(labelsSize, na)
- // printB(str.format("start is {0}", start), absciss = -1)
- // printB(str.format("end is {0}", end), absciss = -1)
- // print(str.format("size is {0}", size))
- if size > 0
- for j = start to end
- int time_j = indexToTime(j)
- // print(str.format("j is {0}", j))
- strings = array.new_string(0, "")
- color color_i = na
- for i = 0 to size - 1
- // print(str.format("i is {0}", i))
- int absciss_i = array.get(print_stack_absciss, i)
- // print(str.format("absciss_i is {0}", absciss_i))
- if absciss_i == time_j
- string string_i = array.get(print_stack_string, i)
- strings.push(string_i)
- color_i := array.get(print_stack_color, i)
- if array.size(strings)
- // texts.push(array.join(strings, "\n"))
- // abscisses.push(time_j)
- // ordinates.push(high[(j<0)?0:j])
- // colors.push(color_i)
- // 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))
- if array.size(labels)
- lbl = array.get(labels, j - start)
- // lbl = array.get(labels, j)
- label.set_xy(lbl, time_j, high[(j<0)?0:j])
- label.set_text(lbl, array.join(strings, "\n"))
- label.set_textcolor(lbl, color_i)
- // if array.size(labels)
- // for i = 0 to array.size(labels) - 1
- // label.delete(array.get(labels, i)[1])
- // // var label lbl = label.new(na, na, na, style = label.style_label_down, color = color.new(color.white, 100), xloc=xloc.bar_time)
- // // label.set_xy(lbl, time_j, high[(j<0)?0:j])
- // // label.set_text(lbl, array.join(strings, "\n"))
- // // label.set_textcolor(lbl, color_i)
- //@version=5
- indicator("Label Test", overlay = true)
- print(str.format("Number is: {0}", 2), absciss = -20)
- print(str.format("Test is: {0}", 3), absciss = -20)
- print(str.format("Number is: {0}", 4), absciss = -10)
- print(str.format("Test is: {0}", 5), absciss = -10)
- plot(close)
- // var label lbl = label.new(na, na, na, style = label.style_label_down, color = color.new(color.white, 100), xloc=xloc.bar_time)
- int start = array.get(print_stack_range, 0)
- int end = array.get(print_stack_range, 1)
- int labelsSize = end - start
- labels = array.new_label(0, na)
- // printB(str.format("labelsSize is {0}", labelsSize))
- for i = 0 to labelsSize - 1
- labels.push(label.new(na, na, na, style = label.style_label_down, color = color.new(color.white, 100), xloc=xloc.bar_time))
- GetLabels(start, end, labels)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement