0% found this document useful (0 votes)
100 views

GS9

This document defines a Pine script study that draws Gann Square of 9 lines and labels on a chart. It calculates Gann price levels based on the close price, and draws red and blue lines at the primary and secondary price levels if enabled by user inputs. Labels can also be added to identify the price levels. The study allows customizing whether to show the lines and labels, their colors, and the number of price levels to display.

Uploaded by

Txt
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

GS9

This document defines a Pine script study that draws Gann Square of 9 lines and labels on a chart. It calculates Gann price levels based on the close price, and draws red and blue lines at the primary and secondary price levels if enabled by user inputs. Labels can also be added to identify the price levels. The study allows customizing whether to show the lines and labels, their colors, and the number of price levels to display.

Uploaded by

Txt
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

//@version=4

study("Gann Square of 9 | Mister AG",overlay=true)


RedGan=input(title="On/Off Red line", type=input.bool, defval=true)
BlueGan=input(title="On/Off Blue line", type=input.bool, defval=true)
labelOn=input(title="On/Off Label ", type=input.bool, defval=true)
LabelColor=input(title="Label color", type=input.color,defval=color.black)
Extend=input(title="Extend line", type=input.bool, defval=true)
PriceLevel=input(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) =>
GannLabel=label.new(x, y, text,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
for i=0 to 3
gNum=0
if min == rangeMin and i==0
gNum:=min + (min+2)
else if min > rangeMin and i ==0
gNum:=round(array.get(GannNum,array.size(GannNum)-1)) + (min+1) +
min
else
gNum:=round(array.get(GannNum,array.size(GannNum)-1)) + (min+2) +
min
array.push(GannNum,gNum)

maxItem=array.size(GannNum)-1
next=0
denomenator=0.0
if close[0] >= 10000
denomenator :=0.01
else if close[0] >= 1000
denomenator :=0.1
else if close[0] >= 100
denomenator :=1
else if close[0] >=10
denomenator :=10
else if close[0] >=0.05
denomenator :=100
else
denomenator :=1000

price=close[0]*denomenator
resistance=0.0
support=0.0
blueGannPrice1=0.0
GannPos=0
for i=0 to array.size(GannNum)-1
if i==maxItem
next:=i
else
next:=i+1

if array.get(GannNum,i) <= price and array.get(GannNum,next) > price


resistance:=array.get(GannNum,next)/denomenator
support:=array.get(GannNum,i)/denomenator
blueGannPrice1:=(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] >= blueGannPrice1 ? 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,"\R1 = " +
tostring(resistance))
label.set_textcolor(rl1,LabelColor)
sl1:=drawLabel(labelPosition,support,"\S1 = " + 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 ? "\R2 = " : "\S2 = "
rl2:=drawLabel(labelPosition,resistancePrice2,resistanceText2 +
tostring(resistancePrice2))
label.set_textcolor(rl2,LabelColor)

if BlueGan
blueGann1=drawLine(blueGannPrice1,startLine,endLine,Extend,color.blue)
if labelOn
BlueText1 = close[0] >= blueGannPrice1 ? "\S1 = " : "\R1 = "
bl1:=drawLabel(labelPosition,blueGannPrice1,BlueText1 +
tostring(blueGannPrice1))
label.set_textcolor(bl1,LabelColor)
if PriceLevel == 5
BlueGannPrice2 = GannWeightPosition > 0 ?
(array.get(GannNum,GannPos+1)+array.get(GannNum,GannPos+2))/2 :
(array.get(GannNum,GannPos-1)+array.get(GannNum,GannPos))/2
BlueGannPrice2 := BlueGannPrice2/denomenator
blueGann2=drawLine(BlueGannPrice2,startLine,endLine,Extend,color.blue)
if labelOn
BlueText2 = GannWeightPosition > 0 ? "\R1 = " : "\S1 = "
bl2:=drawLabel(labelPosition,BlueGannPrice2,BlueText2 +
tostring(BlueGannPrice2))
label.set_textcolor(bl2,LabelColor)

You might also like