本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("CA Flight Check - Reclaim Map", shorttitle="CA Flight Check", overlay=true, max_lines_count=10, max_labels_count=10, max_bars_back=1000)
// === SETTINGS ===
string gLevels = "Price Structure"
bool autoSensitivity = input.bool(true, "Adapt pivot detection to timeframe", group=gLevels)
int manualPivot = input.int(4, "Manual pivot length", minval=2, maxval=15, group=gLevels)
int historyLength = input.int(250, "Level history (bars)", minval=50, maxval=500, group=gLevels)
float secondGap = input.float(1.5, "Second resistance spacing (ATR)", minval=0.5, maxval=5.0, step=0.25, group=gLevels)
string gTech = "Technical Checks"
int emaLen = input.int(50, "EMA length", minval=5, group=gTech)
int rsiLen = input.int(14, "RSI length", minval=2, group=gTech)
int volumeLen = input.int(20, "Volume average", minval=2, group=gTech)
int atrLen = input.int(14, "ATR length", minval=2, group=gTech)
string gView = "Appearance"
bool showEMA = input.bool(true, "Show EMA 50", group=gView)
bool showLevels = input.bool(true, "Show labeled levels", group=gView)
bool showDashboard = input.bool(true, "Show Flight Check dashboard", group=gView)
// === COLORS ===
color green = color.rgb(28, 164, 118)
color red = color.rgb(215, 82, 95)
color amber = color.rgb(230, 166, 72)
color teal = color.rgb(62, 179, 169)
color grey = color.rgb(164, 177, 194)
color dark = color.rgb(22, 32, 47)
// === TIMEFRAME SETTINGS ===
int pivotLen = autoSensitivity ? (timeframe.isdaily ? 3 : timeframe.isintraday and timeframe.multiplier <= 60 ? 3 : 4) : manualPivot
// === TECHNICAL DATA ===
float ema = ta.ema(close, emaLen)
float rsi = ta.rsi(close, rsiLen)
float atr = ta.atr(atrLen)
float avgVolume = ta.sma(volume, volumeLen)
float relativeVolume = not na(volume) and not na(avgVolume) and avgVolume > 0 ? volume / avgVolume : na
// === CONFIRMED PIVOTS ===
float pivotHigh = ta.pivothigh(high, pivotLen, pivotLen)
float pivotLow = ta.pivotlow(low, pivotLen, pivotLen)
var array<float> prices = array.new_float()
var array<int> anchors = array.new_int()
var array<int> registered = array.new_int()
if barstate.isconfirmed
int i = 0
while i < array.size(prices)
if bar_index - array.get(registered, i) > historyLength
array.remove(prices, i)
array.remove(anchors, i)
array.remove(registered, i)
else
i += 1
if not na(pivotHigh)
array.push(prices, pivotHigh)
array.push(anchors, bar_index - pivotLen)
array.push(registered, bar_index)
if not na(pivotLow)
array.push(prices, pivotLow)
array.push(anchors, bar_index - pivotLen)
array.push(registered, bar_index)
while array.size(prices) > 120
array.shift(prices)
array.shift(anchors)
array.shift(registered)
// === LEVEL SEARCH ===
findPivot(float reference, bool above, float gap) =>
int chosen = -1
float distance = 1e20
if array.size(prices) > 0
for i = 0 to array.size(prices) - 1
float level = array.get(prices, i)
float diff = above ? level - reference : reference - level
if diff > gap and diff < distance
chosen := i
distance := diff
chosen
// Use the most recent completed historical extremes
// when confirmed pivots offer no suitable level.
float historyHigh = ta.highest(high[1], historyLength)
float historyLow = ta.lowest(low[1], historyLength)
// Reference price is live so a crossed level
// immediately changes from support to resistance.
float currentPrice = close
int r1Index = findPivot(currentPrice, true, 0.0)
int s1Index = findPivot(currentPrice, false, 0.0)
float r1 = r1Index >= 0 ? array.get(prices, r1Index) : na
float s1 = s1Index >= 0 ? array.get(prices, s1Index) : na
int r1Anchor = r1Index >= 0 ? array.get(anchors, r1Index) : na
int s1Anchor = s1Index >= 0 ? array.get(anchors, s1Index) : na
if na(r1) and not na(historyHigh) and historyHigh > currentPrice
r1 := historyHigh
for n = 1 to historyLength
if not na(high[n]) and high[n] >= historyHigh
r1Anchor := bar_index - n
break
if na(s1) and not na(historyLow) and historyLow < currentPrice
s1 := historyLow
for n = 1 to historyLength
if not na(low[n]) and low[n] <= historyLow
s1Anchor := bar_index - n
break
float r2 = na
int r2Anchor = na
if not na(r1) and not na(atr)
float gap = math.max(atr * secondGap, currentPrice * 0.02)
int r2Index = findPivot(r1, true, gap)
if r2Index >= 0
r2 := array.get(prices, r2Index)
r2Anchor := array.get(anchors, r2Index)
else if not na(historyHigh) and historyHigh > r1 + gap
r2 := historyHigh
for n = 1 to historyLength
if not na(high[n]) and high[n] >= historyHigh
r2Anchor := bar_index - n
break
// === EMA ===
plot(showEMA ? ema : na, "EMA 50", color=amber, linewidth=1)
// === LABELED PRICE LEVELS ===
var line r1Line = na
var line r2Line = na
var line s1Line = na
var label r1Label = na
var label r2Label = na
var label s1Label = na
if barstate.islast
if not na(r1Line)
line.delete(r1Line)
if not na(r2Line)
line.delete(r2Line)
if not na(s1Line)
line.delete(s1Line)
if not na(r1Label)
label.delete(r1Label)
if not na(r2Label)
label.delete(r2Label)
if not na(s1Label)
label.delete(s1Label)
if showLevels
int right = bar_index + 3
if not na(r1) and not na(r1Anchor)
r1Line := line.new(r1Anchor, r1, right, r1, color=amber, width=2, style=line.style_dashed)
r1Label := label.new(right, r1, "🟠 R1 " + str.tostring(r1, format.mintick), style=label.style_label_left, color=amber, textcolor=color.black, size=size.small)
if not na(r2) and not na(r2Anchor)
r2Line := line.new(r2Anchor, r2, right, r2, color=teal, width=2, style=line.style_dashed)
r2Label := label.new(right, r2, "🚀 R2 " + str.tostring(r2, format.mintick), style=label.style_label_left, color=teal, textcolor=color.black, size=size.small)
if not na(s1) and not na(s1Anchor)
s1Line := line.new(s1Anchor, s1, right, s1, color=red, width=2, style=line.style_dashed)
s1Label := label.new(right, s1, "🛡️ S1 " + str.tostring(s1, format.mintick), style=label.style_label_left, color=red, textcolor=color.white, size=size.small)
// === TECHNICAL CHECKS ===
// Use the last completed candle for technical readings.
int k = barstate.isconfirmed ? 0 : 1
bool ready = not na(ema[k + 3]) and not na(rsi[k])
bool trendUp = ready and close[k] > ema[k] and ema[k] > ema[k + 3]
bool trendDown = ready and close[k] < ema[k] and ema[k] < ema[k + 3]
bool momentumUp = ready and rsi[k] >= 50
bool momentumDown = ready and rsi[k] < 45
bool volumeReady = not na(relativeVolume[k])
bool volumeUp = volumeReady and relativeVolume[k] >= 1.10
string outlook = "MIXED CONDITIONS"
if not ready
outlook := "LOADING"
else if trendUp and momentumUp
outlook := volumeUp ? "UPWARD ALIGNED" : "UP / LOW ACTIVITY"
else if trendDown and momentumDown
outlook := volumeUp ? "DOWN / HIGH ACTIVITY" : "DOWNWARD PRESSURE"
string structure = "BETWEEN LEVELS"
if na(r1) and na(s1)
structure := "NO LEVELS FOUND"
else if na(s1)
structure := "BELOW KNOWN LEVELS"
else if na(r1)
structure := "ABOVE KNOWN LEVELS"
// === DASHBOARD ===
var table dash = table.new(position.bottom_right, 2, 9, bgcolor=dark, border_width=1, border_color=color.new(color.gray, 75))
drawRow(int row, string title, string value, color c) =>
table.cell(dash, 0, row, title, text_color=color.silver, text_size=size.small, text_halign=text.align_left)
table.cell(dash, 1, row, value, text_color=c, text_size=size.small, text_halign=text.align_right)
checkText(bool condition) =>
condition ? "✅ YES" : "❌ NO"
if barstate.islast
if showDashboard
color header = color.rgb(37, 53, 72)
table.cell(dash, 0, 0, "🚀 FLIGHT CHECK", bgcolor=header, text_color=color.white, text_size=size.small)
table.cell(dash, 1, 0, "4H / LIVE LEVELS", bgcolor=header, text_color=grey, text_size=size.small)
drawRow(1, "Resistance R1", na(r1) ? "NONE" : str.tostring(r1, format.mintick), amber)
drawRow(2, "Resistance R2", na(r2) ? "NONE" : str.tostring(r2, format.mintick), teal)
drawRow(3, "Support S1", na(s1) ? "NONE" : str.tostring(s1, format.mintick), red)
drawRow(4, "Above rising EMA 50", checkText(trendUp), trendUp ? green : red)
drawRow(5, "RSI above 50", checkText(momentumUp), momentumUp ? green : red)
string volumeText = not volumeReady ? "N/A" : checkText(volumeUp) + " / " + str.tostring(relativeVolume[k], "#.##") + "x"
drawRow(6, "Volume above average", volumeText, not volumeReady ? grey : volumeUp ? green : red)
color outlookColor = str.contains(outlook, "DOWN") ? red : str.contains(outlook, "UP") ? green : amber
drawRow(7, "Technical outlook", outlook, outlookColor)
drawRow(8, "Price structure", structure, grey)
else
table.clear(dash, 0, 0, 1, 8)