本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// 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 Intraday Levels", shorttitle="Gann_Circle_Intraday", overlay=true)
srLineCount = input(title="Number of Gann Levels", type=input.integer, minval=1, maxval=24, defval=8)
supportLineColor = input(color.red, "Support", input.color, inline = "COLOR")
resistanceLineColor = input(color.lime, "Resistance", input.color, inline = "COLOR")
// Milliseconds in a day
msec_day = 1000 * 60 * 60 * 24
t = time("1440", session.regular)
is_first = na(t[1]) and not na(t) or t[1] < t
// 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 refLine = na
var line supportLine = na
var label supportLabel = na
var line resistanceLine = na
var label resistanceLabel = na
var lineArray = array.new_line()
var labelArray = array.new_label()
// Plot only for TODAY
if (timenow - time <= msec_day)
// Opening bar of the day
if is_first
// Delete previous lines
lineArraySize = array.size(lineArray)
for i = 0 to lineArraySize
if array.size(lineArray) > 0
ln = array.shift(lineArray)
line.delete(ln)
array.clear(lineArray)
// Delete previous labels
labelArraySize = array.size(labelArray)
for i = 0 to labelArraySize
if array.size(labelArray) > 0
lbl = array.shift(labelArray)
label.delete(lbl)
array.clear(labelArray)
// Calculate Gann circle intraday levels on confirmation of the opening bar
if barstate.isconfirmed
supportLevel = 0.0
resistanceLevel = 0.0
firstSupport = 0.0
firstResistance = 0.0
// Decimal length to be displayed
decimalLength = dec(low)
// Handle smaller prices
var int div = 1
if low <= 10
div := 10000
else
div := 1
// High and Low of the opening bar
refLine := line.new(x1=bar_index[1], y1=high, x2=bar_index, y2=high, style=line.style_dashed, extend=extend.right, color=color.blue)
array.push(lineArray, refLine)
refLine := line.new(x1=bar_index[1], y1=low, x2=bar_index, y2=low, style=line.style_dashed, extend=extend.right, color=color.blue)
array.push(lineArray, refLine)
// Calculate Gann Circle Intraday levels
sqrt_low = sqrt(low * div)
sqrt_high = sqrt(high * div)
for i = 1 to srLineCount
supportLevel := ((sqrt_high - 0.25) * (sqrt_high - 0.25)) / div
resistanceLevel := ((sqrt_low + 0.25) * (sqrt_low + 0.25)) / div
// Keep track of the support and resistance levels generated in the first iteration of the loop
if i == 1
firstSupport := supportLevel
firstResistance := resistanceLevel
// Plot only those support levels which are lower than the first resistance level
if supportLevel < firstResistance
supportLine := line.new(x1=bar_index[1], y1=supportLevel, x2=bar_index, y2=supportLevel, style=line.style_solid, extend=extend.right, color=supportLineColor)
array.push(lineArray, supportLine)
supportLabel := label.new(time, supportLevel, xloc=xloc.bar_time, text="(" + tostring(truncate(supportLevel, decimalLength)) + ")", style=label.style_none, textcolor=color.gray)
label.set_x(supportLabel, label.get_x(supportLabel) + 28800000)
array.push(labelArray, supportLabel)
// Plot only those resistance levels which are higher than the first support level
if resistanceLevel > firstSupport
resistanceLine := line.new(x1=bar_index[1], y1=resistanceLevel, x2=bar_index, y2=resistanceLevel, style=line.style_solid, extend=extend.right, color=resistanceLineColor)
array.push(lineArray, resistanceLine)
resistanceLabel := label.new(time, resistanceLevel, xloc=xloc.bar_time, text="(" + tostring(truncate(resistanceLevel, decimalLength)) + ")", style=label.style_none, textcolor=color.gray)
label.set_x(resistanceLabel, label.get_x(resistanceLabel) + 28800000)
array.push(labelArray, resistanceLabel)
sqrt_high := sqrt(supportLevel * div)
sqrt_low := sqrt(resistanceLevel * div)
// END