OPEN-SOURCE SCRIPT

CAPEX

68
//version=6
indicator("美光 CapEx 噴發追蹤器", overlay=true)

// --- 輸入設定 ---
threshold = input.float(20.0, title="CapEx 噴發閾值 (%)", minval=1.0)
lookback = input.int(4, title="對比前幾季", minval=1)

// --- 取得財務數據 (資本支出 - 季度) ---
// 使用 request.financial 抓取美光的資本支出 (Capital Expenditures)
capex = request.financial("NASDAQ:MU", "CAPITAL_EXPENDITURES", "FQ")

// --- 計算變動率 ---
// 因為財務數據在圖表上是階梯狀的,我們取當前有效值
current_capex = nz(capex)
prev_capex = nz(capex[lookback])

// 計算增長率 (注意:capex 在財報是負數,所以我們取絕對值來計算)
capex_growth = (math.abs(current_capex) - math.abs(prev_capex)) / math.abs(prev_capex) * 100

// --- 判斷噴發條件 ---
is_surge = capex_growth >= threshold

// --- 繪製視覺效果 ---
// 當 CapEx 噴發時,背景顯示紅色 (代表擴產警訊)
bgcolor(is_surge ? color.new(color.red, 85) : na, title="CapEx 噴發區間")

// 在圖表下方標註文字
plotshape(is_surge, style=shape.labelup, location=location.bottom, color=color.red, text="CapEx 激增", textcolor=color.white, size=size.small)

// --- 儀表板 (選用) ---
var table tb = table.new(position.top_right, 2, 2, bgcolor=color.new(color.black, 70), border_width=1)
if barstate.islast
table.cell(tb, 0, 0, "本季 CapEx:", text_color=color.white)
table.cell(tb, 1, 0, str.tostring(current_capex / 1e9, "#.##") + " B", text_color=color.red)
table.cell(tb, 0, 1, "較上季增長:", text_color=color.white)
table.cell(tb, 1, 1, str.tostring(capex_growth, "#.##") + "%", text_color=is_surge ? color.red : color.green)

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.