OPEN-SOURCE SCRIPT

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

36
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)ใ€**ใ‚’้ธใ‚“ใงใ‚ขใƒฉใƒผใƒˆใ‚’่จญๅฎšใ—ใฆใใ ใ•ใ„ใ€‚

> โš ๏ธ **ๆณจๆ„็‚น**: ใ“ใฎใ‚คใƒณใ‚ธใ‚ฑใƒผใ‚ฟใƒผใฏใ€้€ฃ็ถš่ถณใจใ„ใ†็‰นๅฎšใฎใƒ‘ใ‚ฟใƒผใƒณใฎใฟใ‚’ๆคœๅ‡บใ™ใ‚‹ใ‚‚ใฎใงใ™ใ€‚ใƒˆใƒฌใƒผใƒ‰ๅˆคๆ–ญใ‚’่กŒใ†้š›ใฏใ€ไป–ใฎใƒ†ใ‚ฏใƒ‹ใ‚ซใƒซๅˆ†ๆžใ‚„็’ฐๅขƒ่ช่ญ˜ใจ็ต„ใฟๅˆใ‚ใ›ใฆใ”ๅˆฉ็”จใใ ใ•ใ„ใ€‚

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.