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/
- // © layartrader
- //@version=5
- indicator('Gann Square of 9', overlay=true)
- RedGan = input(title='On/Off Red line', defval=true)
- GreenGan = input(title='On/Off Green line', defval=true)
- labelOn = input(title='On/Off Label ', defval=true)
- LabelColor = input(title='Label color', defval=color.black)
- Extend = input(title='Extend line', defval=true)
- PriceLevel = input.int(title='Price Level', defval=3, options=[3, 5])
- var label rl1 = na
- var label rl2 = na
- var label sl1 = na
- var label bl1 = na
- var label bl2 = na
- label.delete(rl1)
- label.delete(rl2)
- label.delete(sl1)
- label.delete(bl1)
- label.delete(bl2)
- drawLine(resistance, start, end, extend, linecolor) =>
- gannLine = line.new(x1=start, y1=resistance, x2=end, y2=resistance)
- line.set_color(gannLine, linecolor)
- if extend
- line.set_extend(id=gannLine, extend=extend.left)
- gannLine
- drawLabel(x, y, text_1) =>
- GannLabel = label.new(x, y, text_1, xloc=xloc.bar_time, style=label.style_none)
- GannLabel
- max = 20
- rangeMin = 0
- var GannNum = array.new_float(0)
- dt = time - time[1]
- labelPosition = time + 3 * dt
- if barstate.islast
- for min = rangeMin to max by 1
- for i = 0 to 3 by 1
- gNum = 0
- if min == rangeMin and i == 0
- gNum := min + min + 2
- gNum
- else if min > rangeMin and i == 0
- gNum := math.round(array.get(GannNum, array.size(GannNum) - 1)) + min + 1 + min
- gNum
- else
- gNum := math.round(array.get(GannNum, array.size(GannNum) - 1)) + min + 2 + min
- gNum
- array.push(GannNum, gNum)
- maxItem = array.size(GannNum) - 1
- next = 0
- denomenator = 0.0
- if close[0] >= 10000
- denomenator := 0.01
- denomenator
- else if close[0] >= 1000
- denomenator := 0.1
- denomenator
- else if close[0] >= 100
- denomenator := 1
- denomenator
- else if close[0] >= 10
- denomenator := 10
- denomenator
- else if close[0] >= 0.05
- denomenator := 100
- denomenator
- else
- denomenator := 1000
- denomenator
- price = close[0] * denomenator
- resistance = 0.0
- support = 0.0
- greenGannPrice1 = 0.0
- GannPos = 0
- for i = 0 to array.size(GannNum) - 1 by 1
- if i == maxItem
- next := i
- next
- else
- next := i + 1
- next
- if array.get(GannNum, i) <= price and array.get(GannNum, next) > price
- resistance := array.get(GannNum, next) / denomenator
- support := array.get(GannNum, i) / denomenator
- greenGannPrice1 := (support + resistance) / 2
- GannPos := i
- break
- // label.new(bar_index, 0, "\nArrayWork = " + tostring(text), size = size.small)
- //Print lines
- startLine = bar_index[0]
- endLine = bar_index[10]
- GannWeightPosition = close[0] >= greenGannPrice1 ? 2 : -1
- if RedGan
- resistance1 = drawLine(resistance, startLine, endLine, Extend, color.red)
- support1 = drawLine(support, startLine, endLine, Extend, color.red)
- if labelOn
- rl1 := drawLabel(labelPosition, resistance, 'Sell 1 = ' + str.tostring(resistance))
- label.set_textcolor(rl1, LabelColor)
- sl1 := drawLabel(labelPosition, support, 'Buy 1 = ' + str.tostring(support))
- label.set_textcolor(sl1, LabelColor)
- if PriceLevel == 5
- resistancePrice2 = array.get(GannNum, GannPos + GannWeightPosition) / denomenator
- resistance2 = drawLine(resistancePrice2, startLine, endLine, Extend, color.red)
- if labelOn
- resistanceText2 = GannWeightPosition > 0 ? 'Buy 2 = ' : 'Sell 2 = '
- rl2 := drawLabel(labelPosition, resistancePrice2, resistanceText2 + str.tostring(resistancePrice2))
- label.set_textcolor(rl2, LabelColor)
- if GreenGan
- greenGann1 = drawLine(greenGannPrice1, startLine, endLine, Extend, color.green)
- if labelOn
- GreenText1 = close[0] >= greenGannPrice1 ? 'Buy 1 = ' : 'Sell 1 = '
- bl1 := drawLabel(labelPosition, greenGannPrice1, GreenText1 + str.tostring(greenGannPrice1))
- label.set_textcolor(bl1, LabelColor)
- if PriceLevel == 5
- GreenGannPrice2 = GannWeightPosition > 0 ? (array.get(GannNum, GannPos + 1) + array.get(GannNum, GannPos + 2)) / 2 : (array.get(GannNum, GannPos - 1) + array.get(GannNum, GannPos)) / 2
- GreenGannPrice2 /= denomenator
- greenGann2 = drawLine(GreenGannPrice2, startLine, endLine, Extend, color.green)
- if labelOn
- GreenText2 = GannWeightPosition > 0 ? 'Sell 1 = ' : 'Buy 1 = '
- bl2 := drawLabel(labelPosition, GreenGannPrice2, GreenText2 + str.tostring(GreenGannPrice2))
- label.set_textcolor(bl2, LabelColor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement