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, our community Telegram - https://t.me/TGann
- // Method of calculating 1/1 line was seen on youtube channel "КриптоBoy-Китобой".
- // @version=5
- indicator("Gann fan v3", overlay = true)
- first_date = input.time(timestamp("11.11.2022 00:00 GMT+5"), title = "Beginning of impulse", confirm = true)
- second_date = input.time(timestamp("12.11.2022 00:00 GMT+5"), title = "End of impulse", confirm = true)
- var color [] line_col = array.from(
- input(defval = #ff5252, title = "16/1", inline = "a", group = "===== Line colors ====="), //0
- input(defval = #ff52d4, title = "8/1", inline = "a", group = "===== Line colors ====="), //1
- input(defval = #ff7a52, title = "4/1", inline = "a", group = "===== Line colors ====="), //2
- input(defval = #dbe08c, title = "3/1", inline = "a", group = "===== Line colors ====="), //3
- input(defval = #f3ff52, title = "2/1", inline = "a", group = "===== Line colors ====="), //4
- input(defval = #ffffff, title = "1/1", inline = "a", group = "===== Line colors ====="), //5
- input(defval = #5552ff, title = "1/2", inline = "a1", group = "===== Line colors ====="), //6
- input(defval = #52a3ff, title = "1/3", inline = "a1", group = "===== Line colors ====="), //7
- input(defval = #52ffe8, title = "1/4", inline = "a1", group = "===== Line colors ====="), //8
- input(defval = #52ff8c, title = "1/8", inline = "a1", group = "===== Line colors ====="), //9
- input(defval = #83ff52, title = "1/16", inline = "a1", group = "===== Line colors =====")) //10
- main_fan = input.bool(true, "Main fan")
- from_zero = input.bool(false, "Fan from zero")
- from_ATH = input.bool(false, "Fan from ATH")
- fan_down = input.bool(false, "Downwards fan from price", inline = "b2")
- fan_up = input.bool(false, "Upwards fan from price", inline = "b3")
- fan_down_p = input.float(0, "", inline = "b2")
- fan_up_p = input.float(0, "", inline = "b3")
- show_date_labels = input.bool(false, title = "Left & Right points labels")
- lines = array.from(16, 8, 4, 3, 2, 1, 2, 3, 4, 8, 16)
- 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 float hh_ = 0 //first bars high price
- var float ll_ = 0 //first bars low price
- var float p_ = 0
- var float k_ = 0
- var bool up = false
- float auto_ath = ta.max(high)
- // function that check is bar low or high
- is_low(f, b, s)=>
- if low[b - f] < low[b - s] and high[b - f] < high[b - s]
- magic = true
- else
- magic = false
- // time to bar index
- if time == first_date
- first_bar_index := bar_index
- ll_ := low
- hh_ := high
- if show_date_labels
- low_label = label.new(bar_index, low, text = "Left (first) 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 (second) point", color = color.yellow, textcolor = color.black, style = label.style_label_left)
- //after second selected bar processed, 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
- up := true
- 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
- up := false
- // ...calculating 1/1 line
- int count = 0
- p_ := h_ - l_
- while p_ < 100000
- p_ := p_ * 10
- count := count + 1
- p_ := math.round(p_)
- p_ := math.sqrt(p_)
- k_ := p_ / math.pow(10, count - 1)
- // plot lines
- for i = 0 to 10
- if main_fan == true
- line.new(x1 = first_bar_index, y1 = up ? ll_ : hh_, x2 = first_bar_index + 1, y2 = i < 6 ? (up ? ll_ + k_ * array.get(lines, i) : hh_ - k_ * array.get(lines, i)) : (up ? ll_ + k_ / array.get(lines, i) : hh_ - k_ / array.get(lines, i)),
- extend = extend.right, color = array.get(line_col, i), style = line.style_solid, width = 1)
- if from_zero == true
- line.new(x1 = first_bar_index, y1 = 0, x2 = first_bar_index + 1, y2 = i < 6 ? k_ * array.get(lines, i) : k_ / array.get(lines, i),
- extend = extend.right, color = array.get(line_col, i), style = line.style_solid, width = 1)
- if from_ATH == true
- line.new(x1 = first_bar_index, y1 = auto_ath, x2 = first_bar_index + 1, y2 = i < 6 ? auto_ath - k_ * array.get(lines, i) : auto_ath - k_ / array.get(lines, i),
- extend = extend.right, color = array.get(line_col, i), style = line.style_solid, width = 1)
- if fan_down == true
- line.new(x1 = first_bar_index, y1 = fan_down_p, x2 = first_bar_index + 1, y2 = i < 6 ? fan_down_p - k_ * array.get(lines, i) : fan_down_p - k_ / array.get(lines, i),
- extend = extend.right, color = array.get(line_col, i), style = line.style_solid, width = 1)
- if fan_up == true
- line.new(x1 = first_bar_index, y1 = fan_up_p, x2 = first_bar_index + 1, y2 = i < 6 ? fan_up_p + k_ * array.get(lines, i) : fan_up_p + k_ / array.get(lines, i),
- extend = extend.right, color = array.get(line_col, i), style = line.style_solid, width = 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement