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

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)ใ**ใ้ธใใงใขใฉใผใใ่จญๅฎใใฆใใ ใใใ
> โ ๏ธ **ๆณจๆ็น**: ใใฎใคใณใธใฑใผใฟใผใฏใ้ฃ็ถ่ถณใจใใ็นๅฎใฎใใฟใผใณใฎใฟใๆคๅบใใใใฎใงใใใใฌใผใๅคๆญใ่กใ้ใฏใไปใฎใใฏใใซใซๅๆใ็ฐๅข่ช่ญใจ็ตใฟๅใใใฆใๅฉ็จใใ ใใใ
---
## ๐ 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)ใ**ใ้ธใใงใขใฉใผใใ่จญๅฎใใฆใใ ใใใ
> โ ๏ธ **ๆณจๆ็น**: ใใฎใคใณใธใฑใผใฟใผใฏใ้ฃ็ถ่ถณใจใใ็นๅฎใฎใใฟใผใณใฎใฟใๆคๅบใใใใฎใงใใใใฌใผใๅคๆญใ่กใ้ใฏใไปใฎใใฏใใซใซๅๆใ็ฐๅข่ช่ญใจ็ตใฟๅใใใฆใๅฉ็จใใ ใใใ
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.