Indicator · Pine Script v6 · On the chart

TN Swarm Modular Executor

by raybird· code credited to TeleNexus Sovereign AI — 蜂群聯邦共識執行器 v6

TN Swarm Modular Executor combines four distinct sub-strategy modules—Momentum (CCI), Mean Reversion (RSI), Breakout (Bollinger Bands), and Volatility (ATR channels)—into a multi-agent consensus engine.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code192
Settings10inputs
LicenceNone statedfile: MPL-2.0
Last update2 months ago15 Aug 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

192 lines of Pine Script v6 from strategies/swarm_modular_executor_v6.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

swarm_modular_executor_v6.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TeleNexus Sovereign AI — 蜂群聯邦共識執行器 v6
//@version=6

// ──────────────────────────────────────────
// TeleNexus Swarm Modular Executor v6
//  聯邦蜂群共識引擎 + 主權多策略集成
// ──────────────────────────────────────────

indicator("TN Swarm Modular Executor v6", overlay = true, format = format.price, precision = 2)

// ──── 列舉:蜂群成員策略 ────
enum SwarmMember
    MemberMomentum       = "動能突襲者"
    MemberMeanReversion  = "均值狙擊手"
    MemberBreakout       = "突破獵手"
    MemberVolatility     = "波動收割者"

// ──── 列舉:共識等級 ────
enum ConsensusGrade
    Unanimous     = "全體一致"
    SuperMajority = "絕對多數"
    SimpleMajority= "簡單多數"
    Minority      = "少數異見"
    NoConsensus   = "無共識"

// ──── 列舉:執行規訓 ────
enum ExecutionRegime
    Sovereign   = "主權模式"
    Balanced    = "平衡模式"
    Aggressive  = "激進模式"

// ──── 輸入參數 ────
ExecutionRegime regime        = input.enum(ExecutionRegime.Balanced, "執行規訓")
int momLen                     = input.int(14, "動能深度 (Mom)", group = "蜂群參數")
int rsiLen                     = input.int(14, "RSI 深度 (MeanRev)", group = "蜂群參數")
int bbLen                      = input.int(20, "布林帶長度 (Breakout)", group = "蜂群參數")
float bbMult                   = input.float(2.0, "布林帶倍數", group = "蜂群參數")
int atrLen                     = input.int(14, "ATR 長度 (Vol)", group = "蜂群參數")
float atrMult                  = input.float(1.5, "ATR 乘數", group = "蜂群參數")
float sovereignStopMult        = input.float(2.0, "主權停損倍數", group = "風險管理")
float sovereignTakeMult        = input.float(3.0, "主權停利倍數", group = "風險管理")
bool showConsensusPanel        = input.bool(true, "顯示共識面板", group = "視覺化")

// ──── 蜂群成員訊號計算 ────

// 成員1:動能突襲者 (Momentum — CCI 動能)
float cci = ta.cci(high, low, close, momLen)
bool momLong  = cci > 100.0
bool momShort = cci < -100.0
float momStrength = math.abs(cci - 50.0) / 150.0  // 正規化 0~1

// 成員2:均值狙擊手 (Mean Reversion — RSI 極端)
float rsi = ta.rsi(close, rsiLen)
bool mrLong  = rsi < 30.0
bool mrShort = rsi > 70.0
float mrStrength = math.abs(rsi - 50.0) / 50.0

// 成員3:突破獵手 (Breakout — 布林帶突破)
float bbBasis = ta.sma(close, bbLen)
float bbDev   = ta.stdev(close, bbLen) * bbMult
float bbUpper = bbBasis + bbDev
float bbLower = bbBasis - bbDev
bool boLong  = close > bbUpper and close > open
bool boShort = close < bbLower and close < open
float boStrength = math.abs(close - bbBasis) / bbDev

// 成員4:波動收割者 (Volatility — ATR 通道突破)
float atrVal = ta.atr(atrLen)
float volUpper = close + atrVal * atrMult
float volLower = close - atrVal * atrMult
bool volLong  = high > volUpper
bool volShort = low < volLower
float volStrength = atrVal / ta.sma(atrVal, atrLen)

// ──── 聯邦共識引擎 ────
int totalMembers = 4
int longVotes  = (momLong ? 1 : 0) + (mrLong ? 1 : 0) + (boLong ? 1 : 0) + (volLong ? 1 : 0)
int shortVotes = (momShort ? 1 : 0) + (mrShort ? 1 : 0) + (boShort ? 1 : 0) + (volShort ? 1 : 0)

bool hasConsensusLong  = longVotes >= 2
bool hasConsensusShort = shortVotes >= 2

ConsensusGrade gradeLong  = ConsensusGrade.NoConsensus
ConsensusGrade gradeShort = ConsensusGrade.NoConsensus

if longVotes == totalMembers
    gradeLong := ConsensusGrade.Unanimous
else if longVotes >= 3
    gradeLong := ConsensusGrade.SuperMajority
else if longVotes >= 2
    gradeLong := ConsensusGrade.SimpleMajority
else if longVotes >= 1
    gradeLong := ConsensusGrade.Minority

if shortVotes == totalMembers
    gradeShort := ConsensusGrade.Unanimous
else if shortVotes >= 3
    gradeShort := ConsensusGrade.SuperMajority
else if shortVotes >= 2
    gradeShort := ConsensusGrade.SimpleMajority
else if shortVotes >= 1
    gradeShort := ConsensusGrade.Minority

// ──── 權重動態閾值 (根據規訓調整) ────
int requiredVotes = switch regime
    ExecutionRegime.Sovereign   => 4   // 全體一致
    ExecutionRegime.Balanced    => 3   // 絕對多數
    ExecutionRegime.Aggressive  => 2   // 簡單多數

bool finalLong  = longVotes >= requiredVotes
bool finalShort = shortVotes >= requiredVotes

// ──── 共識強度 (加權平均) ────
float consensusStrengthLong = switch longVotes
    4 => 1.0
    3 => 0.85
    2 => 0.65
    1 => 0.35
    => 0.0

float consensusStrengthShort = switch shortVotes
    4 => 1.0
    3 => 0.85
    2 => 0.65
    1 => 0.35
    => 0.0

// ──── 動態停損停利 (ATR 基準) ────
float atrBase = ta.atr(atrLen)
float stopLossPts   = atrBase * sovereignStopMult
float takeProfitPts = atrBase * sovereignTakeMult

// ──── 主權過濾:避免重複進場 ────
bool alreadyInLong  = strategy.opentrades > 0 and strategy.opentrades.size > 0 ? strategy.opentrades[0].tradeDirection == strategy.trade_direction.long : false
bool alreadyInShort = strategy.opentrades > 0 and strategy.opentrades.size > 0 ? strategy.opentrades[0].tradeDirection == strategy.trade_direction.short : false

// ──── 執行引擎 ────
if finalLong and not alreadyInLong
    strategy.entry("SwarmLong", strategy.long, comment = str.format("長 {0}/{1} | {2}", longVotes, totalMembers, gradeLong))
    strategy.exit("SwarmLongExit", "SwarmLong", stop = close - stopLossPts, limit = close + takeProfitPts)

if finalShort and not alreadyInShort
    strategy.entry("SwarmShort", strategy.short, comment = str.format("短 {0}/{1} | {2}", shortVotes, totalMembers, gradeShort))
    strategy.exit("SwarmShortExit", "SwarmShort", stop = close + stopLossPts, limit = close - takeProfitPts)

// ──── 蜂群狀態視覺化 ────
plot(bbBasis, "BB Basis", color = color.new(color.gray, 70))
bbUpperPlot = plot(bbUpper, "BB Upper", color = color.new(color.blue, 50))
bbLowerPlot = plot(bbLower, "BB Lower", color = color.new(color.blue, 50))
fill(bbUpperPlot, bbLowerPlot, color = color.new(color.blue, 90))

// 共識訊號標記
int consensusBarIndex = last_bar_index - 1
plotshape(hasConsensusLong and barstate.isconfirmed ? close * 0.998 : na, "🐝 長共識", shape.triangleup, location.belowbar, color.new(color.green, 30), size = size.tiny)
plotshape(hasConsensusShort and barstate.isconfirmed ? close * 1.002 : na, "🐝 短共識", shape.triangledown, location.abovebar, color.new(color.red, 30), size = size.tiny)

// ──── 共識面板 (最後一根) ────
if barstate.islast and showConsensusPanel
    string panelText = str.format(
        "📊  TeleNexus 蜂群共識\n\n" +
        "▸ 動能突襲者 (CCI {0}):   {1}\n" +
        "▸ 均值狙擊手 (RSI {2}):    {3}\n" +
        "▸ 突破獵手 (BB {4}):      {5}\n" +
        "▸ 波動收割者 (ATR {6}):   {7}\n\n" +
        "══════════════════════\n" +
        "🐂 多做   → {8}/{9} ({10})\n" +
        "🐻 短做   → {11}/{12} ({13})\n" +
        "⚡ 強度(L): {14}  | (S): {15}\n" +
        "🎯 規訓: {16}\n" +
        "🛡  SL {17} pt | TP {18} pt\n" +
        "📅 v26.0527.1830",
        cci, momLong ? "✅" : "❌",
        rsi, mrLong ? "✅" : "❌",
        close > bbUpper ? "↑" : close < bbLower ? "↓" : "−",
        boLong ? "✅" : "❌",
        atrVal, volLong ? "✅" : "❌",
        longVotes, totalMembers, gradeLong,
        shortVotes, totalMembers, gradeShort,
        consensusStrengthLong, consensusStrengthShort,
        regime
    )

    var label consensusLabel = label.new(
        bar_index + 50, high, panelText,
        color = color.new(color.black, 10),
        textcolor = color.white,
        size = size.small,
        style = label.style_label_left
    )
    label.set_text(consensusLabel, panelText)
    label.delete(consensusLabel[1])

Overview

TN Swarm Modular Executor calculates individual member signals and aggregates their votes to determine overall market directional bias and consensus strength. Traders can select different execution regimes (Balanced, Sovereign, Aggressive) and adjust underlying indicator parameters. Output signals and an optional consensus summary panel display directly on the price chart.

Details

Published by

raybird on GitHub

Code credit

TeleNexus Sovereign AI — 蜂群聯邦共識執行器 v6, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Oscillators & momentum, Volatility & bands, Breakout, Screeners & dashboards

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
執行規訓enumExecutionRegime.Balancedregime
動能深度 (Mom)int14momLen
RSI 深度 (MeanRev)int14rsiLen
布林帶長度 (Breakout)int20bbLen
布林帶倍數float2.0bbMult
ATR 長度 (Vol)int14atrLen
ATR 乘數float1.5atrMult
主權停損倍數float2.0sovereignStopMult
主權停利倍數float3.0sovereignTakeMult
顯示共識面板booltrueshowConsensusPanel
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup
330 stars

This multi-symbol indicator evaluates a combined trading condition across up to 40 user-defined symbols. It processes MACD bullish crossovers, RSI thresholds, Bollinger Band boundaries, and DMI/ADX trend filters using security calls. When buy or sell criteria

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of Multi MACD + BB + RSI [Alorse]

Raschke Patterns

by TradersPost
218 stars

This overlay indicator marks Linda Raschke short-term bar setups on the price chart. It flags Turtle Soup and Turtle Soup plus one false breakouts of a prior extreme, 80-20 bars, inside bars, failed inside-bar breakouts, outside up and down bars, NR4 and NR7 c

Indicator v6 Candlestick patternsBreakout Repaints
Updated 3 months ago · None stated GitHub repository of Raschke Patterns

8zz反指標v2

by hansai-art
121 stars

The 8zz Contrarian Indicator plots reverse sentiment trading signals directly on the price chart based on tracked retail post activity. It generates bullish signals during retail panic and bearish signals during market euphoria. The indicator features adjustab

Indicator v6 Moving averagesOscillators & momentum
Updated 3 months ago · None stated GitHub repository of 8zz反指標v2
114 stars

This indicator identifies standard deviation breakout signals by comparing standard deviation against its simple moving average. A long signal triggers when standard deviation crosses above its moving average during a bullish candle, while a short signal occur

Indicator v4 Volatility & bandsBreakout Repaints
Updated 1 year ago · None stated GitHub repository of Stdev Breakout Strategy

This indicator displays a customizable dashboard table on the price chart. It combines Market Action Pulse state, McClellan breadth z-score, VIX Mood Ring status, and Risk Assessment Model hazard score. Users select symbols such as NASDAQ:QQQE or VIX, toggle c

Indicator v6 Screeners & dashboardsOscillators & momentum Repaints

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers