本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Seckin_Tuncay
//@version=6
indicator("Gann Box Navigator", shorttitle="GANN BOX", overlay=true, max_lines_count=150, max_labels_count=100)
// ═══════════════════════════════════════════════
// 0 · Language / Dil
// ═══════════════════════════════════════════════
G0 = "0 · Language / Dil"
lang = input.string("English", "Language / Dil", options=["English", "Türkçe"], group=G0, tooltip="EN: Language of the info table, warning messages and alerts. Settings labels stay in English; every tooltip is written in both languages.\n\nTR: Bilgi tablosu, uyarı mesajları ve alarmların dili. Ayar başlıkları İngilizce kalır; tüm açıklamalar iki dilde yazılmıştır.")
bool TR = lang == "Türkçe"
t(string en, string tr) =>
TR ? tr : en
// ═══════════════════════════════════════════════
// 1 · Anchor
// ═══════════════════════════════════════════════
G1 = "1 · Anchor"
anchorMode = input.string("Single Date", "Anchor Mode", options=["Single Date", "Two Points", "Auto Pivot", "Manual Box"], group=G1, tooltip="EN:\n• Two Points: pick a top candle and a bottom candle on the chart. The box spans from the top candle's high to the bottom candle's low and starts at whichever point is older.\n• Single Date: pick one candle; the other edge is found automatically (section 2).\n• Auto Pivot: the box is built from the latest confirmed pivot and moves when a new pivot forms.\n• Manual Box: enter all four corners (dates + prices) yourself.\n\nTR:\n• Two Points (İki Nokta): grafikte bir tepe ve bir dip mumu seçersin. Kutu tepe mumunun high'ı ile dip mumunun low'u arasına kurulur, hangisi daha eskiyse oradan başlar.\n• Single Date (Tek Tarih): tek bir mum seçersin, diğer uç otomatik bulunur (2. bölüm).\n• Auto Pivot (Otomatik Pivot): kutu son onaylı pivottan kurulur, yeni pivotta taşınır.\n• Manual Box (Manuel Kutu): dört köşeyi (tarih + fiyat) elle girersin.")
pivType = input.string("Most Recent", "Pivot Type", options=["Most Recent", "Last Low", "Last High"], group=G1, tooltip="EN: Auto Pivot mode only. Which pivot the box is anchored to.\n\nTR: Sadece Auto Pivot modu. Kutunun hangi pivottan kurulacağı: en yenisi, son dip ya da son tepe.")
pivL = input.int(20, "Pivot Left Bars", minval=2, group=G1, tooltip="EN: Auto Pivot mode. Bars to the left that a pivot must dominate.\n\nTR: Auto Pivot modu. Pivotun solunda baskın olması gereken bar sayısı.")
pivR = input.int(10, "Pivot Right Bars", minval=1, group=G1, tooltip="EN: Auto Pivot mode. A pivot is confirmed this many bars later. Smaller = earlier but more frequent box changes.\n\nTR: Auto Pivot modu. Pivot bu kadar bar sonra onaylanır. Küçültürsen kutu daha erken kurulur ama daha sık yer değiştirir.")
anchorPos = input.string("Corner", "Anchor Position", options=["Corner", "Middle (0.5)"], group=G1, tooltip="EN: Single Date and Auto Pivot modes. Corner: a low becomes the bottom-left corner, a high the top-left corner. Middle: the anchor sits on the 0.5 price level and the box is mirrored around it. Two Points mode always uses the corners.\n\nTR: Single Date ve Auto Pivot modları. Corner (Köşe): dip sol alt, tepe sol üst köşe olur. Middle (Orta): çapa 0.5 fiyat seviyesine oturur, kutu ona göre simetrik kurulur. Two Points modu her zaman köşeleri kullanır.")
// ═══════════════════════════════════════════════
// 2 · Size
// ═══════════════════════════════════════════════
G2 = "2 · Size"
heightMode = input.string("Opposite Extreme", "Height", options=["Opposite Extreme", "ATR Multiple", "Previous Swing", "Fixed Price"], group=G2, tooltip="EN: Single Date and Auto Pivot modes.\n• Opposite Extreme: from a high anchor down to the lowest low since, or from a low anchor up to the highest high since. The box grows when a new extreme prints.\n• ATR Multiple: ATR at the anchor × multiplier.\n• Previous Swing: distance to the previous opposite pivot × swing multiplier.\n• Fixed Price: the value below.\n\nTR: Single Date ve Auto Pivot modları.\n• Opposite Extreme (Karşı Uç): tepe çapasından sonraki en düşük fiyata ya da dip çapasından sonraki en yüksek fiyata kadar. Yeni uç oluştukça kutu büyür.\n• ATR Multiple (ATR Katı): çapadaki ATR × çarpan.\n• Previous Swing (Önceki Salınım): bir önceki karşı pivota olan mesafe × salınım çarpanı.\n• Fixed Price (Sabit Fiyat): aşağıdaki değer.")
atrLen = input.int(50, "ATR Length", minval=1, group=G2, tooltip="EN: On newly listed symbols with fewer bars, the average true range so far is used instead.\n\nTR: Yeni listelenen sembollerde yeterli mum yoksa o ana kadarki ortalama gerçek aralık kullanılır.")
atrMult = input.float(20.0, "ATR Multiplier", minval=1, step=0.5, group=G2, tooltip="EN: Total box height = ATR at the anchor × this value.\n\nTR: Kutunun toplam yüksekliği = çapadaki ATR × bu değer.")
fixedH = input.float(100.0, "Fixed Height (price)", minval=0, group=G2)
widthMode = input.string("Fixed Bars", "Width", options=["Fixed Bars", "Between Points", "Previous Swing"], group=G2, tooltip="EN:\n• Fixed Bars: the bar count below.\n• Between Points (Two Points mode): bars between the top and bottom × Between Points Multiplier.\n• Previous Swing: bars from the previous opposite pivot to the anchor × swing multiplier.\nA common Gann choice is the duration of the previous major swing.\n\nTR:\n• Fixed Bars (Sabit Bar): aşağıdaki bar sayısı.\n• Between Points (Noktalar Arası, Two Points modu): tepe ile dip arasındaki bar sayısı × çarpan.\n• Previous Swing (Önceki Salınım): önceki karşı pivottan çapaya kadar olan süre × salınım çarpanı.\nGann'da yaygın tercih, bir önceki büyük salınımın süresidir.")
widthBars = input.int(150, "Width (bars)", minval=10, maxval=500, group=G2)
ptMult = input.float(4.0, "Between Points Multiplier", minval=0.25, step=0.25, group=G2, tooltip="EN: With 4 the second point lands on the 0.25 time line, with 2 on the 0.5 line, with 1 on the right edge.\n\nTR: 4 ile ikinci nokta 0.25 zaman çizgisine, 2 ile 0.5 zaman çizgisine, 1 ile sağ kenara denk gelir.")
swingMult = input.float(2.0, "Swing Multiplier", minval=0.25, step=0.25, group=G2, tooltip="EN: Previous Swing modes. With 2 and Middle anchor, the previous opposite pivot lands on the box edge.\n\nTR: Previous Swing modları. 2 değeri ve Middle çapa ile önceki karşı pivot kutu kenarına denk gelir.")
// ═══════════════════════════════════════════════
// 3 · Points
// ═══════════════════════════════════════════════
G3 = "3 · Points"
ptA = input.time(timestamp("2025-10-06T00:00"), "Point 1", confirm=true, group=G3, tooltip="EN: When adding the indicator you are asked to click two candles. The order does not matter.\n• Two Points: one of the two swing candles. The indicator detects which one is the top and which is the bottom.\n• Single Date: this is the anchor candle.\n• Manual Box: one edge of the box.\nYou can change the date here or drag the marker on the chart. The chart shows a label (TOP, BOTTOM, ANCHOR…) on each point.\n\nTR: Göstergeyi eklerken iki muma tıklaman istenir. Sıra önemli değil.\n• Two Points: iki salınım mumundan biri. Hangisinin tepe, hangisinin dip olduğunu gösterge kendisi bulur.\n• Single Date: çapa mumu budur.\n• Manual Box: kutunun bir kenarı.\nTarihi buradan değiştirebilir ya da işaretçiyi sürükleyebilirsin. Grafikte her noktanın üzerinde ne olduğunu gösteren bir etiket (TEPE, DİP, ÇAPA…) çıkar.")
ptB = input.time(timestamp("2026-06-01T00:00"), "Point 2", confirm=true, group=G3, tooltip="EN: The second point. Two Points: the other swing candle. Manual Box: the other edge. Not used in Single Date and Auto Pivot modes.\n\nTR: İkinci nokta. Two Points: diğer salınım mumu. Manual Box: diğer kenar. Single Date ve Auto Pivot modlarında kullanılmaz.")
mAncSrc = input.string("High", "Anchor Price", options=["High", "Low", "Close"], group=G3, tooltip="EN: Single Date mode. Which price of Point 1 is the anchor. In Corner mode, High opens the box downward; Low/Close open it upward.\n\nTR: Single Date modu. Point 1 mumunun hangi fiyatı çapa olsun. Corner modunda High kutuyu aşağı, Low/Close yukarı açar.")
mTop = input.float(0.0, "Top Price (level 0)", group=G3, tooltip="EN: Manual Box mode.\n\nTR: Manual Box modu, üst fiyat.")
mBot = input.float(0.0, "Bottom Price (level 1)", group=G3, tooltip="EN: Manual Box mode.\n\nTR: Manual Box modu, alt fiyat.")
// ═══════════════════════════════════════════════
// 4 · Display
// ═══════════════════════════════════════════════
G4 = "4 · Display"
showPL = input.bool(true, "Price Levels", group=G4)
showTL = input.bool(true, "Time Levels", group=G4, tooltip="EN: Vertical lines at 0.25 · 0.382 · 0.5 · 0.618 · 0.75 of the box width. In Gann analysis turns tend to cluster near these times.\n\nTR: Kutu genişliğinin 0.25 · 0.382 · 0.5 · 0.618 · 0.75 noktalarındaki dikey çizgiler. Gann analizinde dönüşler bu zamanların yakınında yoğunlaşma eğilimindedir.")
showAng = input.bool(true, "Angles", group=G4, tooltip="EN: Diagonals from each corner to the opposite corner and to the midpoints of the opposite sides. They act as moving support/resistance.\n\nTR: Her köşeden karşı köşeye ve karşı kenarların ortalarına çizilen çaprazlar. Hareketli destek/direnç gibi çalışır.")
showLbl = input.bool(true, "Level Labels", group=G4)
showPts = input.bool(true, "Point Labels", group=G4, tooltip="EN: Labels on the chosen points showing what each one is (TOP, BOTTOM, ANCHOR, START, END) and its price.\n\nTR: Seçilen noktaların üzerinde ne olduklarını (TEPE, DİP, ÇAPA, BAŞLANGIÇ, BİTİŞ) ve fiyatlarını gösteren etiketler.")
cPtTop = input.color(#F23645, "Top", group=G4, inline="c0")
cPtBot = input.color(#089981, "Bottom", group=G4, inline="c0")
corrMode = input.string("Auto", "Corridor Fill", options=["Auto", "Bearish", "Bullish", "Off"], group=G4, tooltip="EN: Auto shades the bearish corridor when price is below the 0.5 level and the bullish corridor when above.\n\nTR: Auto, fiyat 0.5 seviyesinin altındaysa düşüş, üstündeyse yükseliş koridorunu boyar.")
showInfo = input.bool(true, "Position Table", group=G4, tooltip="EN: Shows where price and time currently are inside the box (0 = top / left, 1 = bottom / right).\n\nTR: Fiyatın ve zamanın kutu içindeki konumunu gösterir (0 = üst / sol, 1 = alt / sağ).")
cBorder = input.color(color.gray, "Border · 0 · 1", group=G4, inline="c1")
cAng = input.color(#2196F3, "Angles", group=G4, inline="c1")
cL25 = input.color(#FF9800, "0.25", group=G4, inline="c2")
cL382 = input.color(#81C784, "0.382", group=G4, inline="c2")
cL50 = input.color(#4CAF50, "0.5", group=G4, inline="c2")
cL618 = input.color(#009688, "0.618", group=G4, inline="c3")
cL75 = input.color(#2196F3, "0.75", group=G4, inline="c3")
cCorr = input.color(color.new(#FF9800, 75), "Corridor", group=G4, inline="c3")
// ═══════════════════════════════════════════════
// 5 · Alerts
// ═══════════════════════════════════════════════
G5 = "5 · Alerts"
alertLv = input.bool(true, "Alert on price level crosses", group=G5, tooltip="EN: When creating the alert, choose the condition 'Any alert() function call'. Alerts fire only while the bar is inside the box.\n\nTR: Alarm oluştururken koşul olarak 'Herhangi bir alert() fonksiyon çağrısı' seçilmeli. Alarm sadece mum kutunun içindeyken tetiklenir.")
// ═══════════════════════════════════════════════
// Pivot tracking
// ═══════════════════════════════════════════════
atrRaw = ta.atr(atrLen)
trCum = ta.cum(ta.tr(true))
atrV = na(atrRaw) ? trCum / (bar_index + 1) : atrRaw
ph = ta.pivothigh(high, pivL, pivR)
pl = ta.pivotlow(low, pivL, pivR)
hiR = ta.highest(high, pivR)
loR = ta.lowest(low, pivR)
prevClose = close[1]
var float hP = na
var int hB = na
var float hAtr = na
var float hOppP = na
var int hOppB = na
var float lP = na
var int lB = na
var float lAtr = na
var float lOppP = na
var int lOppB = na
var float lExt = na // highest high since the low pivot
var float hExt = na // lowest low since the high pivot
if not na(lExt)
lExt := math.max(lExt, high)
if not na(hExt)
hExt := math.min(hExt, low)
if not na(pl)
lOppP := hP
lOppB := hB
lP := pl
lB := bar_index - pivR
lAtr := atrV[pivR]
lExt := hiR
if not na(ph)
hOppP := lP
hOppB := lB
hP := ph
hB := bar_index - pivR
hAtr := atrV[pivR]
hExt := loR
// Single date anchor
bool dateMode = anchorMode == "Single Date"
bool mLow = mAncSrc != "High"
var float mP = na
var int mB = na
var float mAtr = na
var float mOppP = na
var int mOppB = na
var float mExt = na
if not na(mB)
mExt := mLow ? math.max(mExt, high) : math.min(mExt, low)
if dateMode and na(mB) and time >= ptA
mB := bar_index
mP := mAncSrc == "Low" ? low : mAncSrc == "High" ? high : close
mAtr := atrV
mOppP := mLow ? hP : lP
mOppB := mLow ? hB : lB
mExt := mLow ? high : low
// Two points
bool twoMode = anchorMode == "Two Points"
var int aBi = na
var float aHi = na
var float aLo = na
var int bBi = na
var float bHi = na
var float bLo = na
if na(aBi) and time >= ptA
aBi := bar_index
aHi := high
aLo := low
if na(bBi) and time >= ptB
bBi := bar_index
bHi := high
bLo := low
// Which point is the top: the pairing that gives the larger range
bool aIsTop = not na(aBi) and not na(bBi) and (aHi - bLo) >= (bHi - aLo)
float tH = aIsTop ? aHi : bHi
int tB = aIsTop ? aBi : bBi
float dL = aIsTop ? bLo : aLo
int dB = aIsTop ? bBi : aBi
bool twoOk = twoMode and not na(aBi) and not na(bBi) and aBi != bBi and tH > dL
bool haveL = not na(lB)
bool haveH = not na(hB)
bool useLow = twoMode ? (twoOk and dB < tB) : dateMode ? mLow : pivType == "Last Low" ? true : pivType == "Last High" ? false : (haveL and (not haveH or lB > hB))
float aP = dateMode ? mP : useLow ? lP : hP
int aB = dateMode ? mB : useLow ? lB : hB
float aAtr = dateMode ? mAtr : useLow ? lAtr : hAtr
float oP = dateMode ? mOppP : useLow ? lOppP : hOppP
int oB = dateMode ? mOppB : useLow ? lOppB : hOppB
float aExt = dateMode ? mExt : useLow ? lExt : hExt
float extH = na(aExt) or na(aP) ? na : math.abs(aP - aExt) * (anchorPos == "Corner" ? 1.0 : 2.0)
float H = switch heightMode
"Opposite Extreme" => na(extH) or extH <= 0 ? aAtr * atrMult : extH
"ATR Multiple" => aAtr * atrMult
"Previous Swing" => na(oP) ? aAtr * atrMult : math.abs(aP - oP) * swingMult
=> fixedH
int W = switch
widthMode == "Previous Swing" and not twoMode and not na(oB) and not na(aB) => math.min(500, math.max(10, int(math.round((aB - oB) * swingMult))))
widthMode == "Between Points" and twoOk => math.max(10, int(math.round(math.abs(tB - dB) * ptMult)))
=> widthBars
// ═══════════════════════════════════════════════
// Box geometry
// ═══════════════════════════════════════════════
bool manual = anchorMode == "Manual Box"
float top = na
float bot = na
int L = na
int R = na
if manual
top := math.max(mTop, mBot)
bot := math.min(mTop, mBot)
L := math.min(ptA, ptB)
R := math.max(ptA, ptB)
else if twoMode
if twoOk
top := tH
bot := dL
L := math.min(tB, dB)
R := math.min(L + W, last_bar_index + 499) // Pine can draw at most 500 bars into the future
else if not na(aP) and not na(H) and not na(aB)
if anchorPos == "Middle (0.5)"
top := aP + H / 2
bot := aP - H / 2
else
top := useLow ? aP + H : aP
bot := useLow ? aP : aP - H
L := aB
R := math.min(aB + W, last_bar_index + 499)
bool valid = not na(top) and not na(bot) and not na(L) and not na(R) and top > bot and R > L
string xl = manual ? xloc.bar_time : xloc.bar_index
lvP(float p) =>
top - p * (top - bot)
lvX(float x) =>
L + int(math.round(x * (R - L)))
lvCol(float p) =>
p == 0.25 ? cL25 : p == 0.382 ? cL382 : p == 0.5 ? cL50 : p == 0.618 ? cL618 : p == 0.75 ? cL75 : cBorder
var levels = array.from(0.0, 0.25, 0.382, 0.5, 0.618, 0.75, 1.0)
// ═══════════════════════════════════════════════
// Drawing helpers
// ═══════════════════════════════════════════════
var lns = array.new<line>()
var lbs = array.new<label>()
var lfs = array.new<linefill>()
clearAll() =>
for f in lfs
linefill.delete(f)
for l in lns
line.delete(l)
for b in lbs
label.delete(b)
array.clear(lfs)
array.clear(lns)
array.clear(lbs)
ln(int x1, float y1, int x2, float y2, color c) =>
l = line.new(x1, y1, x2, y2, xloc=xl, color=c, width=1, style=line.style_solid)
array.push(lns, l)
l
lb(int x, float y, string txt, color c, string stl) =>
array.push(lbs, label.new(x, y, txt, xloc=xl, color=color.new(color.black, 100), textcolor=c, style=stl, size=size.small))
ptLb(int x, float y, string txt, color c, bool above) =>
array.push(lbs, label.new(x, y, txt + "\n" + str.tostring(y, format.mintick), xloc=xl, color=c, textcolor=color.white, style=above ? label.style_label_down : label.style_label_up, size=size.small))
// ═══════════════════════════════════════════════
// Drawing (rebuilt on the last bar)
// ═══════════════════════════════════════════════
var table info = table.new(position.top_right, 2, 3, bgcolor=color.new(color.black, 30), border_width=1)
if barstate.islast
clearAll()
table.clear(info, 0, 0, 1, 2)
if valid
float ym = lvP(0.5)
int xm = lvX(0.5)
// Border
ln(L, top, R, top, cBorder)
ln(L, bot, R, bot, cBorder)
ln(L, top, L, bot, cBorder)
ln(R, top, R, bot, cBorder)
// Levels
for p in levels
c = lvCol(p)
bool inner = p > 0 and p < 1
if showPL and inner
ln(L, lvP(p), R, lvP(p), c)
if showTL and inner
ln(lvX(p), top, lvX(p), bot, c)
if showLbl and showPL
lb(L, lvP(p), str.tostring(p), c, label.style_label_right)
lb(R, lvP(p), str.tostring(p) + " · " + str.tostring(lvP(p), format.mintick), c, label.style_label_left)
if showLbl and showTL
lb(lvX(p), top, str.tostring(p), c, label.style_label_down)
lb(lvX(p), bot, str.tostring(p), c, label.style_label_up)
// Angles: corner to opposite corner and to the opposite side midpoints
if showAng
ln(L, top, R, bot, cAng)
ln(L, bot, R, top, cAng)
ln(L, top, xm, bot, cAng)
ln(L, top, R, ym, cAng)
ln(L, bot, xm, top, cAng)
ln(L, bot, R, ym, cAng)
ln(R, top, xm, bot, cAng)
ln(R, top, L, ym, cAng)
ln(R, bot, xm, top, cAng)
ln(R, bot, L, ym, cAng)
// Corridor fill
string cm = corrMode == "Auto" ? (close < ym ? "Bearish" : "Bullish") : corrMode
if cm == "Bearish"
a = ln(L, top, R, bot, color.new(cCorr, 0))
b = ln(L, top, xm, bot, color.new(cCorr, 0))
array.push(lfs, linefill.new(a, b, cCorr))
else if cm == "Bullish"
a = ln(L, bot, R, top, color.new(cCorr, 0))
b = ln(L, bot, xm, top, color.new(cCorr, 0))
array.push(lfs, linefill.new(a, b, cCorr))
// Point labels
if showPts
if twoMode
ptLb(tB, tH, t("TOP", "TEPE"), cPtTop, true)
ptLb(dB, dL, t("BOTTOM", "DİP"), cPtBot, false)
else if dateMode
ptLb(aB, aP, t("ANCHOR", "ÇAPA"), mLow ? cPtBot : cPtTop, not mLow)
else if manual
ptLb(L, top, t("START", "BAŞLANGIÇ"), cBorder, true)
ptLb(R, top, t("END", "BİTİŞ"), cBorder, true)
else
ptLb(aB, aP, useLow ? t("PIVOT LOW", "PİVOT DİP") : t("PIVOT HIGH", "PİVOT TEPE"), useLow ? cPtBot : cPtTop, not useLow)
// Position table
if showInfo
float nowX = manual ? float(time) : float(bar_index)
float pricePos = (top - close) / (top - bot)
float timePos = (nowX - L) / (R - L)
string modeTxt = manual ? t("Manual box", "Manuel kutu") : twoMode ? t("Two points", "İki nokta") : dateMode ? t("Date anchor", "Tarih çapası") : useLow ? t("Low anchor", "Dip çapası") : t("High anchor", "Tepe çapası")
table.cell(info, 0, 0, "GANN BOX", text_color=color.white, text_size=size.small)
table.cell(info, 1, 0, modeTxt, text_color=color.white, text_size=size.small)
table.cell(info, 0, 1, t("Price position", "Fiyat konumu"), text_color=color.white, text_size=size.small)
table.cell(info, 1, 1, str.tostring(pricePos, "0.000"), text_color=color.white, text_size=size.small)
table.cell(info, 0, 2, t("Time position", "Zaman konumu"), text_color=color.white, text_size=size.small)
table.cell(info, 1, 2, str.tostring(timePos, "0.000"), text_color=color.white, text_size=size.small)
else
string msg = manual ? t("GANN BOX: In Manual Box mode, enter the top/bottom prices and dates in section 3", "GANN BOX: Manual Box modunda 3. bölümden üst/alt fiyatı ve tarihleri girin") : twoMode ? (na(aBi) or na(bBi) ? t("GANN BOX: Point 1 or Point 2 is outside the loaded chart data. Pick both from visible candles", "GANN BOX: Point 1 veya Point 2 grafikteki verinin dışında. İkisini de görünen mumlardan seçin") : t("GANN BOX: Point 1 and Point 2 must be two different candles", "GANN BOX: Point 1 ve Point 2 iki farklı mum olmalı")) : dateMode ? t("GANN BOX: The anchor date is outside the loaded chart data. Pick a visible candle", "GANN BOX: Çapa tarihi grafikteki verinin dışında. Görünen bir mum seçin") : t("GANN BOX: No confirmed pivot yet. Reduce the pivot bar counts", "GANN BOX: Henüz onaylı pivot yok. Pivot bar sayılarını küçültün")
table.cell(info, 0, 0, msg, text_color=color.white, bgcolor=color.new(color.orange, 20), text_size=size.small)
// ═══════════════════════════════════════════════
// Alerts
// ═══════════════════════════════════════════════
if alertLv and valid and barstate.isconfirmed
bool inBox = manual ? (time >= L and time <= R) : (bar_index >= L and bar_index <= R)
if inBox
for p in levels
float y = lvP(p)
string lvl = str.tostring(p) + " (" + str.tostring(y, format.mintick) + ")"
if close > y and prevClose <= y
alert(t("Gann Box · " + syminfo.ticker + ": price crossed above level " + lvl, "Gann Kutusu · " + syminfo.ticker + ": fiyat " + lvl + " seviyesini yukarı kesti"), alert.freq_once_per_bar_close)
else if close < y and prevClose >= y
alert(t("Gann Box · " + syminfo.ticker + ": price crossed below level " + lvl, "Gann Kutusu · " + syminfo.ticker + ": fiyat " + lvl + " seviyesini aşağı kesti"), alert.freq_once_per_bar_close)