0% found this document useful (0 votes)
123 views4 pages

Gann 45° Price & Time Lines

The document contains code for plotting Gann angle lines at 45 and 90 degrees on a price chart. It defines user inputs for settings like price level, number of lines, colors, and displays the lines on the chart. Key levels are calculated and stored in arrays based on the price and time inputs. Lines are then drawn between those levels on the chart according to the defined settings.

Uploaded by

Bipin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views4 pages

Gann 45° Price & Time Lines

The document contains code for plotting Gann angle lines at 45 and 90 degrees on a price chart. It defines user inputs for settings like price level, number of lines, colors, and displays the lines on the chart. Key levels are calculated and stored in arrays based on the price and time inputs. Lines are then drawn between those levels on the chart according to the defined settings.

Uploaded by

Bipin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

///////////////////////////////////

// Gann 45 degrees 45
///////////////////////////////////

// ---------------------------
// -- User Inputs --
// ---------------------------

iMode = "Both"
fTime = "Future"
var iPrice = input.price(5000, "Price", group = "Price & Time")
iFullRev = input.float(270, "Full Revolution Value", group = "Price & Time")
pLen = input.int(120, "Price Lines", maxval = 100000, minval = 1, group = "Lines")
tLen = 2
iPriceDegree = 45
iTimeDegree = 45
tPrice = true
cPrice = input.color(color.rgb(27, 251, 2), "Price Color", group = "Customization")
cTime = color.teal
cMidLine = color.yellow
iPriceStyle = input.string("Dashed", "Price Line Style", options = ["Dotted",
"Solid", "Dashed"], group = "Customization")
iTimeStyle = "Dotted"

// ----------------------------
// -- Time to Unix --
// ----------------------------

// Borrow some code from TV docs to convert input timeframe to Unix


float inputTf =
timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
float unixTF = 60000 * request.security(syminfo.tickerid, "D", inputTf)

// ---------------------------
// -- Initializer --
// ---------------------------

// Convert price to degrees for future use


initializer = iFullRev * math.sqrt(iPrice)

// Initialize arrays
pLowValues = array.new_float()
pHighValues = array.new_float()
tValues = array.new_float()

// Calculate key levels for price and time to store in arrays


if barstate.islastconfirmedhistory
if tPrice
if iMode == "Low" or iMode == "Both"
for i = iMode == "Both" ? 1 : 0 to pLen
array.push(pLowValues, math.pow(((initializer + (iPriceDegree *
i))/iFullRev), 2))
if iMode == "High" or iMode == "Both"
for i = iMode == "Both" ? 1 : 0 to iMode == "Both" ? pLen : pLen-1
dInc = (initializer - (iPriceDegree * i))
if dInc < 0
break
array.push(pHighValues, math.pow((dInc/iFullRev), 2))

// ------------------------------
// -- Plotting Lines --
// ------------------------------

// Variables to track # of lines plotted


pLowLineNum = 0
pHighLineNum = 0
tLineNum = 0

// Arrays to hold lines


iLine = array.new_line()
pLine = array.new_line()
tLine = array.new_line()

// Determine style from user input


pStyle = iPriceStyle == "Dotted" ? line.style_dotted : iPriceStyle == "Solid" ?
line.style_solid : iPriceStyle == "Dashed" ? line.style_dashed : na
tStyle = iTimeStyle == "Dotted" ? line.style_dotted : iTimeStyle == "Solid" ?
line.style_solid : iTimeStyle == "Dashed" ? line.style_dashed : na
g45lwidth = input.int(2,title="G 45 linewidth")
// Draw mid line if "Both" is selected
if barstate.islastconfirmedhistory and iMode == "Both" and tPrice
array.push(iLine, line.new(0, iPrice, bar_index, iPrice, xloc=xloc.bar_time,
color=cMidLine, extend=extend.both, style=pStyle,width = g45lwidth))

// Loop to draw price lines


if barstate.islastconfirmedhistory and tPrice
pLowLineNum := 0
pHighLineNum := 0
if iMode == "Low" or iMode == "Both"
for i = 0 to pLen-1
if pLowLineNum >= 500 and iMode != "Both"
break
else if pLowLineNum >=250
break
array.push(pLine, line.new(0, array.get(pLowValues, i), bar_index,
array.get(pLowValues, i), xloc=xloc.bar_time, color=cPrice, extend=extend.both,
style=pStyle,width = g45lwidth))
pLowLineNum += 1
if iMode == "High" or iMode == "Both"
for i = 0 to array.size(pHighValues)-1
if pHighLineNum >= 500 and iMode != "Both"
break
else if pHighLineNum >= 250
break
array.push(pLine, line.new(0, array.get(pHighValues, i), bar_index,
array.get(pHighValues, i), xloc=xloc.bar_time, color=cPrice, extend=extend.both,
style=pStyle,width = g45lwidth))
pHighLineNum += 1

///////////////////////////////////
// Gann 45 degrees 90
///////////////////////////////////
// ---------------------------
// -- User Inputs --
// ---------------------------
dopen = request.security(syminfo.tickerid,"D",open)
iMode1 = "Both"
fTime1 = "Future"
custom = input.bool(true,title="custom price for gann ?")
iPrice1 = custom ? input.price(5000, "Price", group = "Price & Time") : dopen
iTime1 = "D"
iFullRev1 = input.float(90, "Full Revolution Value", group = "Price & Time")
pLen1 = input.int(100, "Price Lines", maxval = 100000, minval = 1, group = "Lines")
tLen1 = input.int(2, "Time Lines", maxval = 500, minval = 1, group = "Lines")
iPriceDegree1 = 45
iTimeDegree1 = 45
tPrice1 = input.bool(true, "Toggle Price", group = "Customization")
cPrice1 = input.color(color.rgb(252, 148, 2), "Price Color", group =
"Customization")
cTime1 = color.teal
cMidLine1 = color.yellow
iPriceStyle1 = input.string("Dashed", "Price Line Style", options = ["Dotted",
"Solid", "Dashed"], group = "Customization")
iTimeStyle1 = "Dotted"

// ----------------------------
// -- Time to Unix --
// ----------------------------

// Borrow some code from TV docs to convert input timeframe to Unix


float inputTf1 =
timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
float unixTF1 = 60000 * request.security(syminfo.tickerid, iTime1, inputTf1)

// ---------------------------
// -- Initializer --
// ---------------------------

// Convert price to degrees for future use


initializer1 = iFullRev1 * math.sqrt(iPrice1)

// Initialize arrays
pLowValues1 = array.new_float()
pHighValues1 = array.new_float()
tValues1 = array.new_float()

// Calculate key levels for price and time to store in arrays


if barstate.islastconfirmedhistory
if tPrice1
if iMode1 == "Low" or iMode1 == "Both"
for i = iMode1 == "Both" ? 1 : 0 to pLen1
array.push(pLowValues1, math.pow(((initializer1 + (iPriceDegree1 *
i))/iFullRev1), 2))
if iMode1 == "High" or iMode1 == "Both"
for i1 = iMode1 == "Both" ? 1 : 0 to iMode1 == "Both" ? pLen1 : pLen1-1
dInc1 = (initializer1 - (iPriceDegree1 * i1))
if dInc1 < 0
break
array.push(pHighValues1, math.pow((dInc1/iFullRev1), 2))

// ------------------------------
// -- Plotting Lines --
// ------------------------------

// Variables to track # of lines plotted


pLowLineNum1 = 0
pHighLineNum1 = 0
tLineNum1 = 0

// Arrays to hold lines


iLine1 = array.new_line()
pLine1 = array.new_line()
tLine1 = array.new_line()

// Determine style from user input


pStyle1 = iPriceStyle1 == "Dotted" ? line.style_dotted : iPriceStyle1 == "Solid" ?
line.style_solid : iPriceStyle1 == "Dashed" ? line.style_dashed : na
tStyle1 = iTimeStyle1 == "Dotted" ? line.style_dotted : iTimeStyle1 == "Solid" ?
line.style_solid : iTimeStyle1 == "Dashed" ? line.style_dashed : na
g45width = input.int(2,title="G 45 linewidth")
// Draw mid line if "Both" is selected
if barstate.islastconfirmedhistory and iMode1 == "Both" and tPrice1
array.push(iLine1, line.new(0, iPrice1, bar_index, iPrice1, xloc=xloc.bar_time,
color=cMidLine1, extend=extend.both, style=pStyle1,width = g45width))

// Loop to draw price lines


if barstate.islastconfirmedhistory and tPrice1
pLowLineNum1 := 0
pHighLineNum1 := 0
if iMode1 == "Low" or iMode1 == "Both"
for i1 = 0 to pLen1-1
if pLowLineNum1 >= 500 and iMode1 != "Both"
break
else if pLowLineNum1 >=250
break
array.push(pLine1, line.new(0, array.get(pLowValues1, i1), bar_index,
array.get(pLowValues1, i1), xloc=xloc.bar_time, color=cPrice1, extend=extend.both,
style=pStyle1,width = g45width))
pLowLineNum1 += 1
if iMode1 == "High" or iMode1 == "Both"
for i1 = 0 to array.size(pHighValues1)-1
if pHighLineNum1 >= 500 and iMode1 != "Both"
break
else if pHighLineNum1 >= 250
break
array.push(pLine1, line.new(0, array.get(pHighValues1, i1), bar_index,
array.get(pHighValues1, i1), xloc=xloc.bar_time, color=cPrice1, extend=extend.both,
style=pStyle1,width = g45width))
pHighLineNum1 += 1

You might also like