0% found this document useful (0 votes)
81 views2 pages

Gann Circle Swing Levels

This document contains the source code for calculating Gann circle swing levels in Pine Script. It takes a swing point value as input, calculates the square root of that value, and then generates support and resistance lines by squaring increments above and below the square root. It outputs the levels and labels them on the chart.

Uploaded by

pndymrigankarka
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)
81 views2 pages

Gann Circle Swing Levels

This document contains the source code for calculating Gann circle swing levels in Pine Script. It takes a swing point value as input, calculates the square root of that value, and then generates support and resistance lines by squaring increments above and below the square root. It outputs the levels and labels them on the chart.

Uploaded by

pndymrigankarka
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/ 2

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © PriceTimeSquare

//@version=4
study("Gann Circle Swing Levels", shorttitle="Gann_Circle_Swing", overlay=true)

swing_point = input(title="Swing Point", type=input.float, defval=0.0)


low_high = input(title="Low / High ?", defval="LOW", options=["LOW", "HIGH"])
srLineCount = input(title="Number of Gann Levels", type=input.integer, minval=1,
maxval=50, defval=8)

color_support = input(color.red, "Support", input.color, group = "SETTINGS", inline


= "L2")
color_resistance = input(color.lime, "Resistance", input.color, group = "SETTINGS",
inline = "L2")
color_swing = input(color.blue, "Swing Point", input.color, group = "SETTINGS",
inline = "L2")
posX_label = input(1, title="Pos. Label x-axis", group = "SETTINGS")

// Truncates a given number to a certain number of decimals


truncate(number, decimals) =>
factor = pow(10, decimals)
int(number * factor) / factor

// Decimal approximation
dec(number) =>
var int decLen = 0
if number <= 10
decLen := 5
else if number <= 999
decLen := 2
else if number <= 9999
decLen := 1
else
decLen := 0

// Variable declaration
var line gLine = na
var label gLabel = na
var color lineColor = color.lime

if barstate.islast

var float level = 0.0

// Decimal length to be displayed


var int decimalLength = dec(swing_point)

// Swing point (High OR Low Swing level from input)


line.delete(gLine[1])
gLine := line.new(x1=bar_index[1], y1=swing_point, x2=bar_index,
y2=swing_point, style=line.style_solid, extend=extend.both, color=color_swing,
width=2)

label.delete(gLabel[1])
gLabel := label.new(time + (time-time[1])*posX_label, swing_point,
xloc=xloc.bar_time, text="(" + tostring(truncate(swing_point, decimalLength)) +
")", style=label.style_none, textcolor=color.gray)
// Handle smaller prices
var int div = 1
if swing_point <= 10
div := 10000
else
div := 1

// Calculate Gann Circle levels


var float sqrt_swing_point = sqrt(swing_point * div)

for i = 1 to srLineCount

if low_high == "LOW"
level := truncate(((sqrt_swing_point + 2) * (sqrt_swing_point + 2)) /
div, decimalLength)
lineColor := color_resistance
else
level := truncate(((sqrt_swing_point - 2) * (sqrt_swing_point - 2)) /
div, decimalLength)
lineColor := color_support

line.delete(gLine[1])
gLine := line.new(x1=bar_index[1], y1=level, x2=bar_index, y2=level,
style=line.style_solid, extend=extend.both, color=lineColor)

label.delete(gLabel[1])
gLabel := label.new(time + (time-time[1])*posX_label, level,
xloc=xloc.bar_time, text="(" + tostring(level) + ")", style=label.style_none,
textcolor=color.gray)

sqrt_swing_point := sqrt(level * div)


// END

You might also like