OPEN-SOURCE SCRIPT
Updated

20SMA Reversal - Peak/Trough Trendlines

336
Title: 20SMA Reversal with Peak/Trough Trendlines

Description (English): This indicator detects pivot points where the 20-period SMA reverses direction (forming a V-shape or an Arch-shape). Upon detection, it automatically identifies the local peak/trough from a lookback period and connects them with an extended trendline if they show a "Lower High" or "Higher Low" pattern. Useful for identifying trend structural changes and potential breakout levels.

概要(日本語): このインジケーターは、20期間SMAが反転(V字回復や山なり反転)するポイントを検出します。反転確定時に、指定した遡り期間内の高値・安値を自動的に特定し、それらが「高値切り下がり」または「安値切り上がり」の条件を満たす場合に、右側に延長されたトレンドラインを描画します。トレンドの構造変化やブレイクアウトの目安として活用いただけます。
Release Notes
[Update: Enhanced with Trendline Breakout Alerts!] This script identifies V-shape and inverted V-shape reversals based on the 20SMA (Simple Moving Average) and automatically plots trendlines connecting recent swing lows and highs.

New in this version: We have implemented a sophisticated "Alert Function" that triggers when the price breaks out of the plotted trendlines.

Key Features:

Automated Trendlines: Automatically draws and extends trendlines connecting significant pivot points triggered by SMA reversals.

Reliable Alerts: To prevent false signals, alerts are suppressed on the initial bar where the line is formed (2nd point). The notification is triggered only when a subsequent bar closes across the extended line.

Optional Background Highlighting: You can visualize SMA reversal points with background colors via the settings (Disabled by default).

【バージョンアップ:アラート機能を追加!】 このインジケーターは、20SMA(単純移動平均線)の反転(V字・逆V字)を検知し、直近の重要な安値・高値を結んだトレンドラインを自動で描画します。

今回のアップデート内容: トレンドラインを外側にブレイクアウトした際に通知する「アラート機能」を実装しました。

特徴:

自動ライン描画: SMAの反転をトリガーに、直近の押し安値・戻り高値を結ぶラインを延長表示します。

高精度アラート: ラインが確定した瞬間の誤報を防ぐため、2点目が決まった足(反転足)では鳴らず、その後の足で明確にラインを跨いだ(確定足)タイミングで通知されます。

背景色表示(オプション): 設定により、SMAの反転ポイントを背景色で視覚化できます(デフォルトはOFF)。
Release Notes
Overview
This indicator is designed to capture high-precision trend reversal points by combining 20SMA slope changes with market structure (pivots).

Latest Updates
The latest version includes significant improvements for real-world trading:

Confirmed Breakout Alerts: Alerts are now triggered precisely when the price breaks the trendline on a "Confirmed Close" basis.

Breakout Dot Markers: Automatically plots a "●" mark on the breakout bar to clearly visualize entry points.

Key Features
SMA Reversal Detection: Identifies the origin of market structure changes based on V-shaped SMA reversals.

Auto-Trendline Projection: Automatically draws objective trendlines once two pivot points (1, 2) are confirmed.

Flexible Parameters: Highly customizable to suit various styles, from scalping to swing trading.

Trading Strategy
Long: When the price breaks above the red descending trendline and a Blue ● appears.

Short: When the price breaks below the blue ascending trendline and a Red ● appears.

概要
このインジケーターは、20SMAの傾きの変化と価格構造(ピボット)を組み合わせて、精度の高いトレンド転換点を捉えるツールです。

バージョンアップ内容
最新のアップデートにより、実戦での使い勝手が大幅に向上しました。

確定足ブレイクアウト・アラート: トレンドラインを「終値」でブレイクしたタイミングで正確にアラートを鳴らします。

ブレイクアウト・ドット表示: ラインをブレイクした足に「●」マークを自動表示し、エントリーポイントを可視化しました。

主な機能
SMA反転検知: 20SMAがV字・逆V字に反転したポイントを構造の起点として捉えます。

自動トレンドライン: 2つの支点(1, 2)が確定すると、客観的なトレンドラインを自動描写します。

マルチ設定: 設定次第でスキャルピングからスイングまで幅広く対応可能です。

トレード戦略
買い(Long): 赤色の下降トレンドラインを終値で上抜け、**青色の●**が表示された時。

売り(Short): 青色の上昇トレンドラインを終値で下抜け、**赤色の●**が表示された時。
Release Notes
■ Detailed Parameter Guide (Input Settings)
This indicator features a recommended setting guide in the settings header: "(20, 6, 20, 3 or 5, 3, 5, 3)". Use these as a starting point. Below is a detailed breakdown of each input's role.

1. Calculation Logic Settings
This section determines the core sensitivity for detecting trend reversals.

SMA Length

Role: The period for the Simple Moving Average used as the trend baseline.

Detail: Default is "20". Increasing this captures long-term trends, while decreasing it makes the indicator more responsive to short-term scalp setups.

Offset (Sensitivity)

Role: Determines the "turnaround" sensitivity of the SMA slope.

Detail: It compares the current SMA value with the SMA value from 'X' bars ago. A smaller value makes it highly sensitive (more signals, but more noise), while a larger value filters out minor fluctuations for a more confirmed reversal.

Price Lookback

Role: The window used to identify the "Pivot 1" high or low.

Detail: Once an SMA reversal is detected, the indicator looks back through this number of bars to find the absolute highest or lowest price point to set as the first pivot.

2. Background Visibility
Show Background Color

Role: Visualizes the exact moment an SMA reversal signal is confirmed.

Detail: When enabled, the background highlights in Blue for a bullish reversal and Red for a bearish reversal on the signal bar.

3. Display Limits
These settings manage chart cleanliness and optimize performance by limiting the number of active objects.

Max Pivot Labels

Role: Limits the number of "1, 2, 3..." pivot label sets displayed on the chart.

Detail: Adjust this based on how much historical market structure you want to keep visible.

Max Breakout Labels (●)

Role: Limits the maximum number of "●" symbols that mark trendline breakouts.

Max Total Breakout Lines

Role: Limits the number of horizontal "BREAK" lines and labels displayed when Pivot 1 levels are breached.

4. Visual Toggles (Appearance Only)
Customize your chart's look without affecting alert logic.

Show Price Pivot Labels: Toggle the "1, 2, 3..." numbering on/off.

Show Breakout Labels (●): Toggle the breakout dots on/off.

Show Breakout Lines: Toggle the horizontal dashed lines and "BREAK" text.

Show Channel Line: Toggle the parallel channel (the projected copy of the trendline).

5. Alert Activation Settings
Five independent alert triggers. All alerts are calculated based on Bar Confirmation (Close) to prevent repainting or false signals.

Pivot 1 Confirmed: Triggers when a new potential trend origin is identified.

Trendline (1-2) Confirmed: Triggers once two pivots are connected, forming a valid trendline.

Channel Formed: Triggers when a complete parallel channel is projected based on the first three pivots.

Line Breakout confirmed: Triggers when price closes across the diagonal trendline (marked by ●).

Pivot(1) Price Breakout confirmed: Triggers when the most critical horizontal support/resistance level (Pivot 1) is broken by a closing bar.


■ 設定項目の詳細解説(パラメーターガイド)
本インジケーターは、設定画面のトップに**「(20, 6, 20, 3 または 5, 3, 5, 3)」**という推奨数値をガイドとして表示しています。これに基づき、各項目の役割を説明します。

1. 計算ロジック設定 (Calculation Logic)
トレンドの「転換」をどこで検知するかを決める最重要セクションです。

SMA Length(SMA期間)

役割: 反転判定のベースとなる移動平均線の期間です。

詳細: デフォルトは「20」です。この数値を大きくすると長期的なトレンド転換を、小さくすると短期的なスキャルピング向けの転換を捉えます。

Offset (Sensitivity)(判定幅)

役割: SMAの「曲がり角」を判定するための感度です。

詳細: 現在の足と、この設定分だけ過去の足のSMA値を比較します。数値が小さいほど敏感に反応しますが、ダマシが増えます。数値が大きいほど確実な反転を捉えますが、サインは遅れます。

Price Lookback(遡る本数)

役割: 支点(ラベル「1」)となる最高値・最安値を探しに行く範囲です。

詳細: SMAが反転した場所から、過去何本分のローソク足の中で一番高い(低い)ところを支点とするかを決めます。

2. 背景色設定 (Background Visibility)
Show Background Color(背景色を表示)

役割: SMAの反転(シグナル発生)をチャート全体で視覚化します。

詳細: チェックを入れると、上昇反転時に「青」、下落反転時に「赤」の背景色が1本表示されます。エントリー準備の合図として機能します。

3. 表示数・上限設定 (Display Limits)
チャートがラインやラベルで埋め尽くされるのを防ぎ、動作を軽くするための管理項目です。

Max Pivot Labels(支点ラベル最大表示数)

役割: チャート上に残す「1, 2, 3...」という支点ラベルのセット数です。

詳細: 過去の波の構造をどの程度まで遡って確認したいかに合わせて調整します。

Max Breakout Labels(●)(ブレイクラベル表示数)

役割: トレンドラインをブレイクした際に出る「●」マークの保持数です。

Max Total Breakout Lines(ブレイクライン総表示数)

役割: ラベル「1」の水平値をブレイクした際に引かれる「BREAK」ラインの最大表示数です。

4. 表示設定 (Visual Toggles)
アラートの計算には影響せず、見た目だけをカスタマイズします。

Show Price Pivot Labels: 支点ラベル(1, 2...)自体の表示/非表示。

Show Breakout Labels (●): ラインブレイク時の「●」マークの表示/非表示。

Show Breakout Lines: 水平レジサポを破った際の「BREAK」ラインと文字の表示/非表示。

Show Channel Line: 平行チャネル(トレンドラインのコピー)の表示/非表示。

5. アラート有効化設定 (Alert Activation)
通知が欲しいタイミングを個別に選べます。すべて**「確定足」**で判定されるため、通知が鳴った後にサインが消えることはありません。

最新の支点(1)確定時: 新しい波の起点が決まった瞬間に通知します。

トレンドライン(1-2)確定時: 2つの支点が揃い、ラインが引けた瞬間に通知します。

チャネルライン完成時: 対極の支点も含め、平行チャネルが完成したことを通知します。

ラインブレイク(●)確定時: 斜めのトレンドラインを実体で抜けた瞬間に通知します。

ラベル1の高値安値ブレイク時: 最も重要な水平レジサポ(ラベル1の価格)を突破した瞬間に通知します。

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.