OPEN-SOURCE SCRIPT

N-Consecutive Candle Marker (SMA Filter & Consolidated Alert)

46
Certainly, here is the English version of the Pine Script description for posting on TradingView.

---

## 📈 N-Consecutive Candle Marker (SMA Filter & Consolidated Alert)

### 📝 Overview

This indicator automatically displays a **signal mark** on the chart when a user-defined number ($N$) of **consecutive bullish or bearish candles** occurs.

It includes an optional **SMA (Simple Moving Average) filter** to restrict signals to conditions favoring a **short-term counter-trend (reversal) trade**. It also consolidates both bullish and bearish signals into a **single alert mechanism** for simplified management.

### ⚙️ Key Features

#### 1. N-Consecutive Candle Detection
* **Consecutive Count (N)**: The indicator detects continuous candles of the same color based on the `Consecutive Candle Count (N)` input setting.
* **Bullish Signal (Red Marker)**: A mark is placed above the high of the closing candle after the bullish sequence is complete.
* **Bearish Signal (Blue Marker)**: A mark is placed below the low of the closing candle after the bearish sequence is complete.

#### 2. SMA Filter (Counter-Trend Logic)
When **`Use SMA Filter`** is enabled, the signal conditions are filtered against the SMA, which focuses on potential **short-term bounces or pullbacks** against the broader trend.

* **Bullish Signal Condition**: The consecutive bullish candles must close **below** the SMA (`close < sma_value`). This typically targets a bounce in a downtrend.
* **Bearish Signal Condition**: The consecutive bearish candles must close **above** the SMA (`close > sma_value`). This typically targets a pullback/dip in an uptrend.

#### 3. Performance & Alert Consolidation
* **Display Limit**: Enabling **`Use Display Limit`** restricts the plotted marks to the **last N bars** defined by `Limit Display to Last N Bars`. This automatically deletes old labels, helping to **maintain chart performance**.
* **Consolidated Alert**: Both bullish and bearish signals trigger the same **single `alert()` function**, simplifying the process of setting up notifications in TradingView.

### 💡 How to Use

1. Add the indicator to your chart.
2. Set the **`Consecutive Candle Count (N)`** to your desired number of consecutive bars (e.g., 3, 4, etc.).
3. If you want to use the reversal filter, switch **`Use SMA Filter (On/Off)`** to **On**. Adjust the `SMA Period` as needed.
4. In the TradingView alert creation menu, select this indicator and choose **"Any function call"** or **"N-Consecutive Candle Marker (SMA Filter & Consolidated Alert)"** to set up your consolidated alert.

> ⚠️ **Disclaimer**: This indicator detects specific candle patterns. Always combine this signal with other forms of technical analysis and context for making trading decisions.

ご要望いただいたTradingViewに投稿する際のインジケーターの説明文として、機能、使い方、フィルターロジックに焦点を当てた文章を作成しました。

この説明文は、Pine Scriptの公開ライブラリの投稿テンプレートに合わせて、**概要、使い方、主要機能**を明確に伝える構造にしています。

---

## 📈 N-Consecutive Candle Marker (SMA Filter & Consolidated Alert)

### 📝 概要 (Overview)

このインジケーターは、設定した本数($N$)の**連続した陽線または陰線**が出現した際に、チャート上に**サイン(マーク)**を自動で表示します。

オプションで**SMA(単純移動平均線)フィルター**を適用することができ、トレンドの状況に応じた**短期的な逆張りサイン**に限定することが可能です。また、陽線サインと陰線サインを**一つのアラート**で統合して通知できるため、管理が容易です。

### ⚙️ 主要機能 (Key Features)

#### 1. N連続ローソク足の検出
* **連続本数の設定 (N)**: `Consecutive Candle Count (N)` の設定値に基づき、連続した同色ローソク足を検出します。
* **陽線サイン (Red Marker)**: 連続陽線が完了した足の高値の上にマークを表示します。
* **陰線サイン (Blue Marker)**: 連続陰線が完了した足の安値の下にマークを表示します。

#### 2. SMAフィルター (逆張りロジック)
`Use SMA Filter` を **オン** にすることで、サインの出現条件にトレンドフィルターを追加します。これは、トレンド方向に対する**一時的な反発・押し目**を狙う、**逆張り的なロジック**を採用しています。

* **陽線サインの出現条件**: 終値がSMAの**下**にある状態で、連続陽線が出現した場合。
* **陰線サインの出現条件**: 終値がSMAの**上**にある状態で、連続陰線が出現した場合。

#### 3. パフォーマンス最適化とアラート統合
* **表示制限**: `Use Display Limit` をオンにすると、描画されるマークの数を**直近のN本**に制限し、古いマークを自動で削除することで、チャート描画の**パフォーマンスを維持**します。
* **統合アラート**: 陽線・陰線どちらのサインが出た場合でも、**単一の `alert()` 関数**でメッセージを出し分けます。これにより、アラート設定をシンプルに保てます。

### 💡 使い方 (How to Use)

1. インジケーターをチャートに追加します。
2. **`Consecutive Candle Count (N)`** を希望する連続本数に設定します(例: 3本連続、4本連続など)。
3. トレンドフィルターを使用したい場合は、**`Use SMA Filter (On/Off)`** をオンに切り替えます。
4. TradingViewのアラート設定画面で、このインジケーターを選択し、**「どんな関数呼び出しでも」**または**「N-Consecutive Candle Marker (SMA Filter & Consolidated Alert)」**を選んでアラートを設定してください。

> ⚠️ **注意点**: このインジケーターは、連続足という特定のパターンのみを検出するものです。トレード判断を行う際は、他のテクニカル分析や環境認識と組み合わせてご利用ください。

Exención de responsabilidad

La información y las publicaciones no constituyen, ni deben considerarse como asesoramiento o recomendaciones financieras, de inversión, de trading o de otro tipo proporcionadas o respaldadas por TradingView. Más información en Condiciones de uso.