本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// AC-LTI · Absolute Capital Long Term Investment
// Original implementation, 4 Oct 2026. No third-party code.
// THE ONE RULE, identical to the daily #spot-bags post (ac-cron lti_state.py) and the backtest
// (absolute-capital tools/lti-ema-backtest, tools/strategy-shootout):
// LONG = EMA 12 above EMA 21 AND close above EMA 50 -> hold BTC
// CASH = EMA 12 below EMA 21 -> out
// CAUTION = anything else (12 over 21, close under the 50) -> out, cash ready to re-enter (ruled 26 Sep 2026)
// Built for the 2D chart on BTC. Replaces the April 2026 AC·LTS logic (cross-only entry with a grace window, exit on the
// 12/21 cross-under, CAUTION held), which lost to buy-and-hold over 2016-2026 (60.8% vs 63.8% a year).
indicator("Absolute Capital - Long Term Investment (AC·LTI)", shorttitle="AC·LTI", overlay=true, max_labels_count=500)
// ─── Inputs ───────────────────────────────────────────────
len12 = input.int(12, minval=1, title="EMA 12", group="Lengths")
len21 = input.int(21, minval=1, title="EMA 21", group="Lengths")
len50 = input.int(50, minval=1, title="EMA 50", group="Lengths")
colLong = input.color(#00E87A, title="LONG", group="Colours")
colCaution = input.color(#B8B8B8, title="CAUTION", group="Colours")
colCash = input.color(#5C5C5C, title="CASH", group="Colours")
showBars = input.bool(true, title="Colour the bars by state", group="Display")
showLabels = input.bool(true, title="Label every state change", group="Display")
showTable = input.bool(true, title="Show the state table", group="Display")
// ─── The rule ─────────────────────────────────────────────
e12 = ta.ema(close, len12)
e21 = ta.ema(close, len21)
e50 = ta.ema(close, len50)
// 2 = LONG, 1 = CAUTION, 0 = CASH
state = e12 > e21 and close > e50 ? 2 : e12 < e21 ? 0 : 1
stateCol = state == 2 ? colLong : state == 1 ? colCaution : colCash
stateText = state == 2 ? "LONG" : state == 1 ? "CAUTION" : "CASH"
changed = barstate.isconfirmed and state != state[1]
// ─── Plots ────────────────────────────────────────────────
p12 = plot(e12, "EMA 12", color.new(stateCol, 0), 2)
p21 = plot(e21, "EMA 21", color.new(stateCol, 40), 2)
plot(e50, "EMA 50", color.new(#FFFFFF, 50), 1)
fill(p12, p21, color.new(stateCol, 82), title="12/21 fill")
barcolor(showBars ? stateCol : na)
// ─── State-change labels (confirmed bars only, so they never repaint) ──
atr = ta.atr(14)
if showLabels and changed
if state == 2
label.new(bar_index, low - atr * 0.8, "LONG", style=label.style_label_up, color=colLong, textcolor=#000000, size=size.normal)
else
label.new(bar_index, high + atr * 0.8, state == 1 ? "CAUTION" : "CASH", style=label.style_label_down, color=stateCol, textcolor=#000000, size=size.normal)
// ─── State table ──────────────────────────────────────────
var table t = table.new(position.top_right, 2, 3, bgcolor=color.new(#0A0A0A, 5), border_color=color.new(#00E87A, 60), border_width=1, frame_color=color.new(#00E87A, 40), frame_width=1)
if showTable and barstate.islast
table.cell(t, 0, 0, "ABSOLUTE CAPITAL", text_color=#00E87A, text_size=size.normal)
table.cell(t, 1, 0, "AC·LTI", text_color=#00E87A, text_size=size.normal)
table.cell(t, 0, 1, "State", text_color=color.white, text_size=size.normal)
table.cell(t, 1, 1, stateText, text_color=stateCol, text_size=size.normal)
table.cell(t, 0, 2, "Timeframe", text_color=color.white, text_size=size.normal)
table.cell(t, 1, 2, timeframe.period == "2D" ? "2 Day" : timeframe.period, text_color=timeframe.period == "2D" ? color.white : #FF4D4D, text_size=size.normal)
// ─── Alerts (fire once, on the confirmed bar) ─────────────
alertcondition(changed and state == 2, "AC·LTI LONG", "AC·LTI: LONG. EMA 12 over 21 and price over the 50.")
alertcondition(changed and state == 1, "AC·LTI CAUTION", "AC·LTI: CAUTION. Out, cash ready to re-enter.")
alertcondition(changed and state == 0, "AC·LTI CASH", "AC·LTI: CASH. EMA 12 under 21.")
alertcondition(changed, "AC·LTI any state change", "AC·LTI state changed.")