Indicator

Indicator

Indicator

Smart Mahjong ConceptsSmart Mahjong Concepts
NOTICE / DISCLAIMER
This architecture is NOT a mere entertainment tool or a superficial game. It is a highly advanced algorithmic volume allocation and multi-state logic simulation engine disguised as a traditional matching framework (Mahjong), specifically designed to test the computational overhead and localized rendering boundaries of Pine Script v6 under live tick conditions.
EXECUTIVE SUMMARY
This script is deployed as a Proof of Concept (PoC) to demonstrate the extreme limits of Pine Script v6's array processing, state evaluation capabilities, and localized UI rendering. This open-source architecture functions as a rigorous technical benchmark for developers building institutional-grade algorithmic dashboards and multi-state logic controllers directly on PulseWire charts.
HOW TO PLAY (Mahjong Crash Course & Execution Flow)
Since PulseWire doesn't allow direct mouse clicks on chart objects, we've engineered a dropdown-based state machine to play the game. Here is how you play and the basic rules of Mahjong:
1. The Goal of Mahjong:
Your objective is to draw and discard tiles to complete a 14-tile winning hand. A standard winning hand consists of four "Sets" (3 sequential tiles or 3 identical tiles) and one "Pair" (2 identical tiles). We also support special hands like "Seven Pairs" (7 different pairs) and "Thirteen Orphans" (one of each 1, 9, and honor tile).
2. Available Yaku (Winning Patterns) & Advanced Logic:
You need at least one "Yaku" to win. This engine automatically calculates the following built-in Yaku:
- Ready Hand (Riichi): Toggle the Riichi switch to declare your hand is 1 tile away from winning. This costs 1,000 points (deducted from your HUD score) and adds +1 Han to your final win.
- Dora (Bonus Tile): Check the "Dora Indicator" tile displayed at the top of your HUD. Every matching tile in your winning hand adds +1 Han.
- All Simples (Tanyao): A hand with NO 1s, 9s, or Honor/Letter tiles.
- Value Tiles (Yakuhai): A set of 3 matching Honor/Letter tiles.
- Half Flush (Honitsu): A hand using only one suit plus Honor/Letter tiles.
- Full Flush (Chinitsu): A hand using ONLY one suit.
- All Triplets (Toitoi): A hand where all 4 sets are identical triplets.
- Seven Pairs (Chiitoitsu): Exactly 7 different pairs.
- Thirteen Orphans (Kokushi Musou): The legendary hand containing all terminals and honors.
3. Step-by-Step Execution:
- Initialization: Apply the script to a chart. The system automatically deals 13 tiles to you and the CPU.
- Read Your Hand: Look at the grey index numbers (1 to 14) displayed right below your tiles.
- Your First Turn: Open the settings. The Turn 1 parameter is pre-set to "14" (your first drawn tile index) to ensure the engine initializes seamlessly without triggering any unselected or error standby states. If you want to discard a different tile, simply change this dropdown to match the grey index number (1 to 14) of the tile you want to drop. Click OK.
- CPU Turn: The moment you hit OK, the engine moves your tile to the River, sorts your hand, and triggers the CPU. The CPU draws, thinks using a retro AI algorithm, and discards.
- Subsequent Turns: A new tile is drawn for you. Open settings, go to Turn 2, pick the index of your next discard, and hit OK. Repeat up to Turn 18.
- Declaring a Win: When your 14 tiles form a valid hand with at least one Yaku, check the Tsumo (self-draw) or Ron (win on opponent's discard) box at the bottom of the settings. The HUD will lock in your score! (Warning: Checking these without a valid hand results in a "Chombo" penalty).
CONFIGURATION & FILTERING OPTIONS
- Fixed Screen Table Compression: The layout uses a highly optimized 12-column matrix for discard streams (River arrays). By packing tiles tightly across rows 1-2 (Opponent) and 6-7 (Player), it completely aligns with the horizontal hand width, eliminating redundant dead space.
- Hand Guide Indices: Dynamic, real-time index markers (1 to 14) map directly below the Player hand elements. This provides structural input verification, eliminating input errors when executing parameters.
- SMC Volume Profile Filtering: A toggle-driven threshold filter isolates significant volume nodes. Users can specify a threshold percentage (0.0% to 100.0%). Any price bucket whose volume does not meet the specified percentage relative to the Point of Control (POC) node volume is skipped during the rendering loop.
- Standardized Price Coordination: Every individual row of the Mahjong Volume Profile displays its absolute price boundary, formatted using format.mintick inside structural brackets (e.g., ). The maximum volume bar is automatically prefixed with a distinct 'POC' string asset tracker.
SYSTEM CAPABILITIES AND LIMITATIONS
Capabilities:
1. Complete Replication of Identical States: Given an identical Game Seed, the script guarantees 100% stable replication of all wall shuffles, initial tile distributions, and CPU discard paths across any device or chart timeframe.
2. Visual Synthesis of Financial Volume Data: The horizontal length of the rendered profile tracks live traded volume metrics pro-rata, allowing traders to confirm institutional support levels while running state logic simulation.
3. Clean Pro-Rata Volume Extraction: Noise reduction filtering eliminates low-volume spikes, cleanly isolating key supply/demand clusters on the chart.
Limitations:
1. Strict Monzen (Concealed Hand) Architecture: To preserve absolute computational efficiency and prevent Abstract Syntax Tree (AST) node exhaustion, this engine enforces a strict "Concealed Hand Only" constraints. By omitting open-meld variables (Meelee / Pon, Chii, Kan), the system optimizes recursive backtracking matrix pipelines, shifting the structural meta towards maximizing full-flush and terminal anomalous state logic (e.g., Thirteen Orphans) directly on live charts.
2. No Direct Mouse-Click Tile Interaction: PulseWire does not expose coordinate click events to Pine Script. Discards must be executed through parameter dropdowns.
3. No Asynchronous Network Multi-Player: Pine Script lacks external socket capabilities. Synchronization between human players across machines is impossible; gameplay is Player-vs-CPU local simulation.
4. Hardware Object Limits: PulseWire enforces a strict cap of 500 max labels/boxes per indicator. Scaling VP resolution too high with filtering off will cause automated visual clipping.
ARCHITECTURE & QUANTITATIVE LOGIC (Technical Specifications)
1. Volume Allocation Engine (Pro-Rata Range Overlap Distribution)
Instead of simple volume summation based on close prices, the script calculates the exact geometric intersection between each bar's High-Low range and the discrete price bins. Volume is distributed across multiple bins according to the overlap percentage.
Let bar high be H, bar low be L, and bar volume be V. Let a specific bin b have an upper bound BinTop and lower bound BinBot. The distributed volume delta dV for bin b from bar i is computed as follows:
If H > L: Overlap = max(0, min(H, BinTop) - max(L, BinBot)), Ratio = Overlap / (H - L), dV = V * Ratio.
If H = L: BinIdx = floor((H - LL) / BinSize). If BinIdx equals b, dV = V; else, dV = 0.
2. Bounding Box Scaling Algorithm (Localized UI Vector Scaling)
Standard label.new() text strings are hard-capped at size.huge (approx. 36px). To override this, vector Unicode strings are injected into a box.new() container. The Y-axis boundaries are mathematically locked using Top = Y + 0.5 and Bottom = Y - 0.5 units. By enforcing a strict coordinate bounding box, the text engine is overridden, forcing the vectors to dynamically scale up to 100px+ relative to the visual layout.
3. Floating Relative Coordinate System
To prevent visual collision with candlestick series, the UI baseline is decoupled from absolute historical coordinates via the formula: Base_Y = Close + Global_Shift.
4. Deterministic Pseudo-Random Array Shuffling (LCG Implementation)
To eliminate chart repainting, a secure Linear Congruential Generator (LCG) loop reorganizes the 136-element primary array via modulo arithmetic: Swap_Index = (Seed + i * 7) % (i + 1).
5. Trigonometric Color Matrix Generation
To eliminate computational rigidity, sine waves handle multi-phase shift conversions for RGB gradients: R = floor(sin(Freq * Index) * 127 + 128).
6. Modular State Evaluation Engine (AST Optimization)
To circumvent server-side compilation timeouts, all scoring algorithms are entirely externalized across four custom libraries.
INPUT PARAMETERS REFERENCE & CRITICAL WARNINGS
- UI Mode: Fixed Screen (Table) / Off for Chart-Linked (Label). Default is false.
- Game Seed: Default is 777. The seed for the LCG algorithm. Warning: Changing this value mid-game completely breaks transaction state history.
- Declare Riichi: Default is false. Deducts 1,000 pts from the HUD and adds +1 Han to a valid win.
- Turn 1 (t1): Default is "14". Pre-set to 14 (the first drawn tile index) to eliminate application-stage state mismatch faults.
- Turn 2 to Turn 18 (t2 to t18): Default is "0". Warning: Inputs must be executed sequentially.
- Tsumo / Ron (is_tsumo / is_ron): Boolean (bool). Default is false. Warning: Do not toggle both to true simultaneously.
- VP Volume Threshold (%) (vp_thresh): Range: 0.0 to 100.0. Default is 20.0. CRITICAL WARNING: Setting filter_vp to true with a very low threshold (e.g., 0.0% to 1.0%) on low-volume assets exhausts the 500 max boxes limit, triggering clipping faults. Keep at 20.0%+ on live charts.
=======================================================
📝 日本語説明(Japanese Description)
注意/免責事項
本アーキテクチャは、単なるエンターテインメントツールや表面的なゲームではありません。ライブティック条件下におけるPine Script v6の計算負荷と局所的レンダリングの限界をテストするために、伝統的なマッチングフレームワーク(麻雀)に偽装した、高度なアルゴリズム出来高按分および多状態ロジックシミュレーションエンジンです。
エグゼクティブ・サマリー
本スクリプトは、Pine Script v6における配列処理、状態評価、および局所的なUIレンダリングの極限を実証するための概念実証モデル(Proof of Concept)です。PulseWire上で機関投資家レベルのアルゴリズム・ダッシュボードや多状態ロジックコントローラを構築する開発者に向けた、オープンソースの技術的ベンチマークです。
遊び方とゲームの流れ(麻雀ルール超簡易ガイド付き)
PulseWireの仕様上、画面の牌を直接マウスでクリックすることはできません。そのため、設定画面の「プルダウン」を使ってゲームを進めます。麻雀を知らない方でも直感的に遊べるように設計しています。
1. 麻雀のクリア条件(アガリの形)
14枚の牌を使って、「3枚セット×4つ」+「2枚のペア×1つ」を作るのが基本ルールです。(セット=連番、または同じ牌3枚)。例外として「ペアを7つ作る(七対子)」などの特殊な形もあります。
2. 実装されている役(ヤク)と拡張ロジック
アガるためには「役」が最低1つ必要です。本エンジンは以下の役およびボーナスを自動計算します。
- リーチ (Riichi): テンパイ(あと1枚でアガリ)の時に設定画面でリーチを宣言できます。HUDの点棒が1,000点減り、アガった時に「+1飜(Han)」が加算されます。
- 現物ドラ (Dora): HUDの最上部に「Dora Indicator」としてドラ表示牌が1枚表示されています。アガった時、自分の手牌の中にこの表示牌と「全く同じ牌(現物)」があれば、その枚数分だけ「+X飜」が加算されます。
- 断么九(タンヤオ): 1、9、字牌を使わず、2〜8の牌だけで作る。
- 役牌(ヤクハイ): 東南西北白發中のどれかを3枚揃える。
- 混一色(ホンイツ): 1つの色(例:萬子だけ)と字牌だけで作る。
- 清一色(チンイツ): 1つの色だけで作る。
- 対々和(トイトイ): 3枚セットをすべて「同じ牌3枚」で作る。
- 七対子(チートイツ): 2枚のペアを7種類作る。
- 国士無双(コクシムソウ): 1、9、字牌の全13種類を揃える最強の役。
3. 対局の進め方
- 初期化: チャートに入れると、自動的に13枚の牌が配られます。
- 手牌の確認: 自分の牌のすぐ下に「1〜14」のグレーの番号が振られています。これが捨てる時の「指定番号」です。
- 1巡目(Turn 1): 最初のツモ牌が引かれ、手牌が14枚になります。設定画面を開くと、初期エラー状態(インジケーター適用直後の未選択によるスタンドバイ不整合)を構造的に回避するため、`Turn 1` はデフォルトで「14(一番右のツモ牌のインデックス)」がプリセットされています。これにより、適用した瞬間に有効な初期トランザクションが確立されます。もし別の牌を捨てたい場合は、捨てたい牌の下にある番号(1〜14)をプルダウンで選び、「OK」を押します。
- CPUのターン: OKを押した瞬間、選んだ牌が河(捨て場)に移動し、即座にCPUがツモって、レトロなAI思考で最適な牌を捨ててきます。
- 2巡目以降: あなたに新しい牌が配られます。設定画面の `Turn 2` で捨てる番号を選び、OKを押す。これを18巡目まで繰り返します。
- アガリの宣言: 手牌がアガリの形になり、役が完成したら、設定画面の一番下にある `Tsumo(ツモ)` または `Ron(ロン)` にチェックを入れてください。画面中央に役と点数(飜数)がドン!と表示されます。(※役がないのにチェックを入れると「チョンボ」と怒られます)。
構成およびフィルタリングオプション
- 固定画面テーブルの凝縮レイアウト: 捨牌(河)の格納に高度に最適化された12列マトリックスを採用。対面とプレイヤーの河を手牌の横幅と完璧に同調させ、画面上の無駄なデッドスペースを完全に排除しました。
- SMCボリュームプロファイルの閾値フィルタ: 出来高ノイズをカットするスイッチ。出来高閾値%を指定し、最大出来高(POC)に対して指定割合に満たない価格帯は描画ループからスキップされ、チャートから完全に非表示になります。
- 精密な価格帯およびPOCの数値可視化: プロファイルの各行の左側に、市場価格座標が format.mintick を用いて正確に計算・ブラケット表示されます(例: )。POCには専用の識別文字列が付与されます。
システムの技術的限界(達成可能な事項と不可能な事項)
達成可能な事項:
1. 完全決定論的な同一状態の再現: Game Seedが同一であれば、どの端末・時間足でも、完全に同一の山牌、CPU打牌経路がミリ秒単位の狂いもなく100%再現されます。
2. 市場出来高データとの視覚的融合: バックグラウンドのプロファイル横幅は実際の取引高にプロラタ(比例配分)で連動しており、機関投資家のサポート価格帯(POC)を確認しながら状態シミュレーションを進めることができます。
3. ノイズレスな出来高ノードの抽出: 閾値フィルタリングにより、価格アクション上の微小な出来高スパイクをクレンジングします。
不可能な事項:
1. 厳格な門前仕様アーキテクチャ(鳴きの排除): 絶対的な計算効率を維持し、ASTノードの枯渇を防止するため、本エンジンは厳格な「門前限定制約」を強制しています。鳴き変数(ポン、チー、カン)を省略することで、システムは再帰的なバックトラッキング行列パイプラインを最適化し、清一色や国士無双などの大物手状態ロジックの最大化へと構造的メタをシフトさせています。
2. マウスクリックによる直接的な牌選択: PulseWireの仕様上、画面クリックの座標取得が不可能なため、打牌は設定画面のプルダウンから番号指定で行う必要があります。
3. 非同期ネットワーク通信対戦: Pine Scriptは外部サーバーとのソケット通信機能を備えていません。よって対人ネットワーク対戦は不可能であり、対CPU戦のローカルシミュレーション限定となります。
4. オブジェクト上限による描画の消去: 1つのインジケーターが保持できるオブジェクト数は500個が限界です。プロファイルの行数を極大値に設定しフィルタリングをオフにすると、自動消去(クリッピング)が発生します。
アーキテクチャおよび定量的ロジック(技術仕様)
1. 出来高按分エンジン(プロラタ値幅オーバーラップ配分ロジック)
終値に基づく単純な出来高の加算ではなく、各バーの高値・安値レンジと、事前定義された価格帯ビンとの幾何学的な重複を計算し、そのオーバーラップ率に基づいて出来高を複数のビンへ比例配分(プロラタ処理)します。
H > L の場合:Overlap = max(0, min(H, BinTop) - max(L, BinBot)), Ratio = Overl
ap / (H - L), dV = V * Ratio。
H = L の場合:BinIdx = floor((H - LL) / BinSize)。BinIdx が b と等しい場合、dV = V。
2. Bounding Boxスケーリング・アルゴリズム(局所的UIベクタースケーリング)
標準の label.new() は最大サイズが制限されておりチャートの拡大縮小に追従しません。この制限を打破するため、ベクターテキストを box.new() に注入し、Y軸の価格単位(Top = Y + 0.5、Bottom = Y - 0.5)で空間境界を固定。内部レンダリングエンジンを強制オーバーライドし、100pxを超える動的スケーリングを実現します。
3. フローティング相対座標系
静的なインターフェースがローソク足と衝突するのを防ぐため、UIのベースラインを絶対価格から分離する数式:Base_Y = Close + Global_Shift を採用しています。
4. 決定論的疑似乱数による配列シャッフル(LCGの実装)
ティック更新におけるリペイントを防ぐため、剰余演算を用いた線形合同法(LCG)アルゴリズムが配列を並び替えます:Swap_Index = (Seed + i * 7) % (i + 1)。
5. 三角関数を利用したRGBカラーマトリックス生成
サイン波による連続的な位相シフト計算を実装し、RGB値を 2 * PI / 3 ラジアン(120度)ずつオフセットさせ、動的なカラーグラデーションを生成します。
6. モジュール化された状態評価エンジン(AST最適化)
コンパイルタイムアウトを回避するため、スコアリングロジックは4つのカスタムライブラリへと完全に分散(モジュール化)されています。
全入力パラメーターの仕様と注意事項
- UI Mode: Fixed Screen (Table) / Off for Chart-Linked (Label): デフォルトは false。描画モードの切り替え。
- Game Seed: デフォルトは 777。注意事項: 途中で数値を変更すると再シャッフルされ、整合性が破壊されます。
- Declare Riichi: デフォルトは false。リーチ宣言。HUDから1,000点を減算し、アガリ時に+1飜を加算します。
- Turn 1 (t1): 初期値は "14"。インジケーター適用時のエラーを防止するため、デフォルトで14番目の要素(ツモ牌)が選択されています。
- Turn 2 〜 Turn 18 (t2 〜 t18): 初期値は "0"。注意事項: パラメーターは必ず順番通りに入力してください。
- Tsumo / Ron: 和了宣言スイッチ。注意事項: 同時に両方を true に設定しないでください。
- VP Volume Threshold (%) (vp_thresh): デフォルトは 20.0。
【重大な警告】 流動性の低い相場で filter_vp を true にしつつ、vp_thresh を極めて低い値(0.0%〜1.0%等)に設定すると、PulseWireの「500個のBox/Label制限」を瞬時に突破し、描画が完全に消失するクリッピングバグが誘発されます。実戦チャートでは必ず「20.0%」以上に設定してください。
Indicator

Indicator

HTF Levels | 1H 4H DailyHTF Levels | 1H 4H Daily
Plots the current and previous High, Low, and Midpoint for the 1-Hour, 4-Hour, and Daily timeframes directly on your chart — regardless of which timeframe you are trading on.
What makes this original:
Most HTF level tools simply draw static lines from request.security() on every bar, cluttering historical price action. This script draws only on the current bar (barstate.islast), keeping the chart clean. It also includes an automatic level merging algorithm — when levels from different timeframes fall within a configurable percentage threshold of each other, they are averaged into a single line with a combined label (e.g. 4H H | Prv D H), visually identifying high-confluence zones without requiring manual comparison.
Levels plotted:
Current period: High, Midpoint ((H+L)/2), Low — lines extend across the full chart
Previous period: High, Midpoint, Low — lines extend left only for visual separation
Confluence Merging:
When two or more levels are within the merge threshold (default 0.05%), they collapse into one averaged line with a merged label. Adjust the threshold in settings to suit your instrument's tick size.
Alerts:
Every level has its own named alert condition. Use individual alerts (e.g. "4H High", "Prev Daily Low") or the master "Any HTF Level" alert to get notified when price enters proximity of any key zone. The alert buffer % is fully adjustable.
Settings:
Toggle each timeframe independently
Custom color per timeframe
Line width and label size controls
Merge threshold % — how close levels must be to combine
Alert buffer % — how close price must be to trigger
Best used on intraday timeframes (1m–30m) where 1H, 4H, and Daily levels act as key support and resistance. Indicator

Strategy

Strategy

Mean Reversion ZonesMean Reversion Zones is an indicator that helps evaluate how far price has deviated from the balance line.
The indicator builds a dynamic mean-reversion channel around the calculated balance line. The upper red zones show areas where price has deviated above balance. The lower green zones show areas where price has deviated below balance. The central grey area represents the balance zone, where price is closer to its current average value.
This tool is designed to help traders read market context, identify stretched price conditions, and understand where the market is currently located: near balance, above balance, below balance, or inside an extreme deviation zone.
How it works
The script uses endpoint kernel smoothing to calculate a non-repainting balance line. Around this line, it builds several adaptive zones based on the mean absolute deviation of price from balance and current volatility conditions.
The channel can work in two width modes:
Fixed : the channel width is calculated based on the selected multiplier.
Adaptive : the channel expands and contracts depending on the current ATR compared with its average value.
The zones are divided into several areas:
Balance Zone : price is close to its average value.
Upper Risk Zone : price has deviated above balance.
Upper Extreme / Outer Risk Zone : price is strongly stretched to the upside.
Lower Opportunity Zone : price has deviated below balance.
Lower Extreme / Outer Opportunity Zone : price is strongly stretched to the downside.
Extreme dots
Red dots appear only when price reaches the upper extreme area or moves above the outer upper zone.
Green dots appear only when price reaches the lower extreme area or moves below the outer lower zone.
These dots are not trading signals. They are visual markers showing that price has reached a statistically stretched area relative to the current balance line.
Dashboard
The Dashboard briefly shows the current market context:
Zone : the current position of price inside the channel.
Reading : a simple text description of the current deviation.
Trend : EMA-based trend context: Uptrend, Downtrend, or Sideways.
Volatility : current ATR compared with its average value.
Hint : an educational context hint, not a trading recommendation.
How to use
The indicator may be useful for traders who want to answer several questions:
1. Is price close to balance or already far away from it?
2. Has the market deviated upward or downward?
3. Is the current deviation moving with the trend or against it?
4. Is volatility normal, high, or extreme?
5. Is it better to wait for price to return closer to balance before making a decision?
Important limitations
The indicator does not predict future price movement.
Upper zones are not automatic short signals. Lower zones are not automatic long signals. Extreme dots are not entry signals. They only show that price is currently stretched relative to the calculated balance line.
Mean-reversion tools can remain in a stretched condition for a long time during strong trends. Therefore, this indicator should always be used together with market structure analysis, trend analysis, volume, risk management, and your own trading plan.
Alerts
The script includes alerts for the following events:
Price enters the upper risk zone.
Price enters the extreme upper risk zone.
Price moves above the outer upper risk zone.
Price enters the lower opportunity zone.
Price enters the extreme lower opportunity zone.
Price moves below the outer lower opportunity zone.
Price returns to the balance zone.
These alerts are intended only for tracking market context and should not be treated as standalone trading signals.
Indicator

Indicator

Indicator

Indicator

Indicator

Indicator

BNC Market Bias DashboardA multi-timeframe sentiment gauge built on the BullNaked Crypto strategy framework. No signals, no entries — just a clear read of where the market stands right now across 7 timeframes simultaneously.
Scores each timeframe (3min, 9min, 27min, 81min, 3H, Daily, Weekly) across 5 indicators — EMA stack, Naked RSI zones, Stochastic RSI, Ichimoku Cloud, and Keltner Channel — and combines them into a weighted overall bias rating. Higher timeframes carry more weight because the higher the timeframe, the stronger the signal.
Rating scale: Strong Bull → Bull → Lean Bull → Neutral → Lean Bear → Bear → Strong Bear
What each column shows:
EMA stack alignment (9/30/50/100/200)
Naked RSI health zone (36 / 46 / 56 / 65 system)
Stochastic RSI position
Ichimoku Cloud position
Keltner Channel position
Per-timeframe signal suggestion
The overall score is weighted so Daily and Weekly carry 3× the influence of the 3-minute, reflecting the core principle that trend is truth on the higher timeframe. Use this to build your story before placing any trade — if the higher timeframes disagree with your entry timeframe, the story isn't complete yet.
Overlays directly on your chart. Table anchors to the bottom-left corner. All timeframes and indicator settings are fully adjustable in the settings panel.
Not financial advice. For educational and informational purposes only. Indicator

Indicator

Indicator

Indicator

Indicator

MSL Trend FollowMSL Trend Follow is a market-structure trend-following indicator designed to help traders identify when price may be shifting from one directional phase to another, and then follow that phase using an ATR-based trailing stop.
The indicator combines two core ideas:
1. Market structure break logic
2. Adaptive ATR trailing stop management
Instead of plotting a large number of separate signals, MSL Trend Follow focuses on a cleaner workflow: detect a structural trend change, display the direction, and then provide a dynamic trailing stop line that follows the active trend.
How it works
The script identifies confirmed swing highs and swing lows using a pivot-based structure model. When price closes above the most recent confirmed swing high, the indicator marks a potential bullish trend shift. When price closes below the most recent confirmed swing low, it marks a potential bearish trend shift.
After a trend signal appears, the indicator plots an ATR-based trailing stop:
- In an uptrend, the green trailing stop line is plotted below price.
- In a downtrend, the red trailing stop line is plotted above price.
The trailing stop uses a ratchet mechanism. During an uptrend, the stop can only move upward. During a downtrend, the stop can only move downward. This helps the line follow the active trend without constantly moving back and forth with every minor price fluctuation.
What makes it useful
MSL Trend Follow is not designed to predict every candle or call every market turn. Its purpose is to give traders a structured way to read trend direction and manage the active phase after a structural breakout.
The indicator may help traders answer three practical questions:
- Has price shifted above or below an important structural level?
- Is the current trend phase still active?
- How far is price from the current trailing stop?
The chart output is intentionally simple:
- Green Trend signal: bullish structure shift
- Red Trend signal: bearish structure shift
- Green line: bullish trailing stop
- Red line: bearish trailing stop
- Dashboard: current trend state, signal age, and distance to stop
Dashboard
The dashboard gives a compact view of the current state:
Trend
Shows the current directional state:
UP, DOWN, or NEUTRAL.
Signal Age
Shows how many bars have passed since the most recent trend signal. A small number means the signal is relatively fresh. A larger number means the trend phase has already been active for a longer period.
To Stop
Shows the current distance between price and the trailing stop as a percentage. This helps traders understand how much room price has before reaching the active stop line.
How to use it
A bullish scenario appears when the indicator prints a green Trend signal and starts plotting a green trailing stop below price. This means price has broken above the latest confirmed structural high and the indicator has shifted into an upward trend state.
A bearish scenario appears when the indicator prints a red Trend signal and starts plotting a red trailing stop above price. This means price has broken below the latest confirmed structural low and the indicator has shifted into a downward trend state.
The trailing stop can be used as a visual reference for trend continuation or trend invalidation. As long as price respects the active trailing stop, the current trend phase remains structurally intact according to the indicator logic. If price moves through the trailing stop area, the current trend phase may be weakening or ending.
Suggested interpretation
Stronger bullish context:
- Trend state is UP
- Price remains above the green trailing stop
- The green stop line continues to move upward
- The signal is not extremely old
- The broader market context supports upward continuation
Stronger bearish context:
- Trend state is DOWN
- Price remains below the red trailing stop
- The red stop line continues to move downward
- The signal is not extremely old
- The broader market context supports downward continuation
Weaker or more cautious context:
- Price is very close to the trailing stop
- The signal is very old
- Market is moving sideways
- Price repeatedly crosses back and forth around structural levels
- Higher-timeframe direction conflicts with the current signal
Settings
Pivot Length
Controls how major or minor the detected structure points are. Lower values make the indicator more reactive, but may create more noise. Higher values focus on larger structural swings and may produce fewer signals.
Min Bars Between Signals
Adds a minimum bar distance between trend signals. This can help reduce rapid flip-flopping in choppy markets.
ATR Length
Controls the ATR calculation used for the trailing stop.
ATR Multiplier
Controls how far the trailing stop sits from price. A higher multiplier creates a wider stop and fewer stop-outs. A lower multiplier creates a tighter stop and faster reaction.
Signal Offset ATR
Controls how far the signal label is placed from the trailing stop line. This is a visual setting only and does not change the signal logic.
Best use cases
MSL Trend Follow is best suited for traders who want a clean trend-following tool based on market structure and dynamic stop tracking. It can be used on different markets, including stocks, crypto, forex, indices, and commodities, but the settings should be adjusted to the asset and timeframe.
Suggested timeframes:
- H1 for more active trading
- H4 for intraday and short swing context
- D1 for broader swing trend structure
The indicator is not intended to be used as a standalone trading system. It should be combined with broader market context, support and resistance, volatility conditions, risk management, and the trader’s own trading plan.
Important notes
This indicator does not guarantee future performance.
It does not predict the market.
It does not replace risk management.
It is designed for market analysis and educational use.
All signals should be interpreted in context. A trend signal shows that a structural condition has been met according to the indicator logic, not that a trade must be opened automatically.
Markets can remain volatile, choppy, or unpredictable, and any technical tool can produce false signals. Indicator

Indicator

Indicator

Strategy
