Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © nemo_tman
- // Method of calculating 1/1 line and getting bar index for labels was taken from © LonesomeTheBlue`s "Gann Fan" indicator
- //@version=5
- indicator("Gann fan by nemo", overlay = true)
- first_date = input.time(timestamp("11.11.2022 00:00 GMT+5"), confirm = true)
- second_date = input.time(timestamp("12.11.2022 00:00 GMT+5"), confirm = true)
- downLineColor = input.color(color.new(color.orange, 30))
- upLineColor = input.color(color.new(color.green, 30))
- label_pos = input.int(50, "Label position", 10, 200)
- show_date_labels = input.bool(false, title = "Left & Right points labels")
- var int first_bar_index = 0
- var int second_bar_index = 0
- var int highs_bar_index = 0
- var int lows_bar_index = 0
- var float l_ = 0
- var float h_ = 0
- var divs = array.from(2.0, 3.0, 4.0, 8.0)
- var line downL16to1 = na
- // for horisontal labels (16/1 - 2/1) positioning
- line_get_bar_index(gline, x_bar_index, yloc, mult)=>
- ystart = line.get_price(gline, x_bar_index)
- slope = math.abs(ystart - line.get_price(gline, x_bar_index + 1))
- int ret = x_bar_index + math.floor((yloc - ystart) / slope) * mult
- //
- is_low(f, b, s)=>
- if low[b - f] < low[b - s] and high[b - f] < high[b - s]
- bool isLow = true
- // time to bar index
- if time == first_date
- first_bar_index := bar_index
- if show_date_labels
- low_label = label.new(bar_index, low, text = "Left point", color = color.yellow, textcolor = color.rgb(0, 0, 0), style = label.style_label_right)
- if time == second_date
- second_bar_index := bar_index
- if show_date_labels
- high_label = label.new(bar_index, high, text = "Right point", color = color.yellow, textcolor = color.black, style = label.style_label_left)
- //after second selected bar processed (we not need more) - checking first selected bar high or low and...
- //после того как дошли и обработали бар второй даты/точки (нам дальше не надо), - определяем первая дата хай или лой и...
- if second_bar_index > 0 and second_bar_index == bar_index
- if is_low(first_bar_index, bar_index, second_bar_index)
- l_ := low[bar_index - first_bar_index]
- lows_bar_index := first_bar_index
- h_ := high[bar_index - second_bar_index]
- highs_bar_index := second_bar_index
- else
- l_ := low[bar_index - second_bar_index]
- lows_bar_index := second_bar_index
- h_ := high[bar_index - first_bar_index]
- highs_bar_index := first_bar_index
- // ...calculating 1/1 line
- // ...делаем расчет линии 1/1
- float perc = (h_ - l_) /82
- float hh = h_ + perc * 10
- float ll = l_ - perc * 8
- float middle = (hh - ll) / 131.0
- // uplines from lows
- upLine16to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle * 16, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- upLine8to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle * 8, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- upLine4to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle * 4, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- upLine3to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle * 3, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- upLine2to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle * 2, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- upLine1to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- upLine1to2 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle / 2, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- upLine1to3 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle / 3, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- upLine1to4 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle / 4, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- upLine1to8 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle / 8, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- upLine1to16 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle / 16, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
- label.new(x = line_get_bar_index(upLine16to1, lows_bar_index, line.get_price(upLine1to1, lows_bar_index + label_pos), 1), y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "16/1", textcolor = upLineColor, style = label.style_none)
- label.new(x = line_get_bar_index(upLine8to1, lows_bar_index, line.get_price(upLine1to1, lows_bar_index + label_pos), 1), y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "8/1", textcolor = upLineColor, style = label.style_none)
- label.new(x = line_get_bar_index(upLine4to1, lows_bar_index, line.get_price(upLine1to1, lows_bar_index + label_pos), 1), y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "4/1", textcolor = upLineColor, style = label.style_none)
- label.new(x = line_get_bar_index(upLine3to1, lows_bar_index, line.get_price(upLine1to1, lows_bar_index + label_pos), 1), y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "3/1", textcolor = upLineColor, style = label.style_none)
- label.new(x = line_get_bar_index(upLine2to1, lows_bar_index, line.get_price(upLine1to1, lows_bar_index + label_pos), 1), y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "2/1", textcolor = upLineColor, style = label.style_none)
- label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "1/1", textcolor = upLineColor, style = label.style_none)
- label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to2, lows_bar_index + label_pos), text = "1/2", textcolor = upLineColor, style = label.style_none)
- label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to3, lows_bar_index + label_pos), text = "1/3", textcolor = upLineColor, style = label.style_none)
- label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to4, lows_bar_index + label_pos), text = "1/4", textcolor = upLineColor, style = label.style_none)
- label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to8, lows_bar_index + label_pos), text = "1/8", textcolor = upLineColor, style = label.style_none)
- label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to16, lows_bar_index + label_pos), text = "1/16", textcolor = upLineColor, style = label.style_none)
- // downlines from highs
- downL16to1 := line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle * 16, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- downL8to1 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle * 8, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- downL4to1 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle * 4, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- downL3to1 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle * 3, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- downL2to1 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle * 2, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- downL1to1 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- downL1to2 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle / 2, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- downL1to3 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle / 3, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- downL1to4 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle / 4, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- downL1to8 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle / 8, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- downL1to16 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle / 16, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
- label.new(x = line_get_bar_index(downL16to1, highs_bar_index, line.get_price(downL1to1, highs_bar_index + label_pos), -1), y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "16/1", textcolor = downLineColor, style = label.style_none)
- label.new(x = line_get_bar_index(downL8to1, highs_bar_index, line.get_price(downL1to1, highs_bar_index + label_pos), -1), y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "8/1", textcolor = downLineColor, style = label.style_none)
- label.new(x = line_get_bar_index(downL4to1, highs_bar_index, line.get_price(downL1to1, highs_bar_index + label_pos), -1), y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "4/1", textcolor = downLineColor, style = label.style_none)
- label.new(x = line_get_bar_index(downL3to1, highs_bar_index, line.get_price(downL1to1, highs_bar_index + label_pos), -1), y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "3/1", textcolor = downLineColor, style = label.style_none)
- label.new(x = line_get_bar_index(downL2to1, highs_bar_index, line.get_price(downL1to1, highs_bar_index + label_pos), -1), y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "2/1", textcolor = downLineColor, style = label.style_none)
- label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "1/1", textcolor = downLineColor, style = label.style_none)
- label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to2, highs_bar_index + label_pos), text = "1/2", textcolor = downLineColor, style = label.style_none)
- label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to3, highs_bar_index + label_pos), text = "1/3", textcolor = downLineColor, style = label.style_none)
- label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to4, highs_bar_index + label_pos), text = "1/4", textcolor = downLineColor, style = label.style_none)
- label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to8, highs_bar_index + label_pos), text = "1/8", textcolor = downLineColor, style = label.style_none)
- label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to16, highs_bar_index + label_pos), text = "1/16", textcolor = downLineColor, style = label.style_none)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement