OPEN-SOURCE SCRIPT
Trend Candle Counter

Complete Tutorial: Trend Candle Counter Pine ScriptTable of Contents
Installation Guide
Understanding the Indicator
How It Works
Customization Options
Trading Strategies
Setting Up Alerts
Troubleshooting
1. Installation Guide {#installation}Step-by-Step Installation:Step 1: Open TradingView
Go to tradingview.com
Log in to your account
Step 2: Access Pine Editor
Click on "Pine Editor" tab at the bottom of the chart
Or press Alt + E (Windows) or Option + E (Mac)
Step 3: Create New Indicator
Click "Open" → "New blank indicator"
Delete any default code
Step 4: Paste the Script
Copy the entire Trend Candle Counter script
Paste it into the editor
Step 5: Save and Apply
Click "Save" (or Ctrl + S)
Give it a name: "Trend Candle Counter"
Click "Add to Chart"
✅ Done! The indicator should now appear on your chart.2. Understanding the Indicator {#understanding}What Does It Do?This indicator numbers each candle based on the current trend:[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}Trend TypeNumberingVisualUptrend+1, +2, +3, +4...🟢 Green labelsDowntrend-1, -2, -3, -4...🔴 Red labelsTrend ChangeResets to ±1Label color switchesVisual Components:
Candle Labels - Numbers above each candle
Trend Line (EMA) - Green (up) / Red (down)
Background Shading - Light green/red tint
Info Table - Top-right corner showing:
Current trend direction
Current candle number
Current price
3. How It Works {#how-it-works}Trend Detection Logic:IF Close > EMA → UPTREND (positive counting)
IF Close < EMA → DOWNTREND (negative counting)
Counting Mechanism:Example Uptrend:Candle 1: Close > EMA → Label: +1
Candle 2: Close > EMA → Label: +2
Candle 3: Close > EMA → Label: +3
Candle 4: Close < EMA → Label: -1 (trend changed!)
Example Downtrend:Candle 1: Close < EMA → Label: -1
Candle 2: Close < EMA → Label: -2
Candle 3: Close < EMA → Label: -3
Candle 4: Close > EMA → Label: +1 (trend changed!)
Key Insight:The higher the absolute number, the longer the trend has been running!4. Customization Options {#customization}Accessing Settings:
Click the gear icon ⚙️ next to the indicator name
Go to "Inputs" tab
Available Parameters:[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}ParameterDefaultDescriptionRecommendationTrend Detection Length14EMA period for trend5-10: Scalping<br>14-20: Day trading<br>50-200: Swing tradingShow Candle Numbers✅ YesDisplay labelsDisable for cleaner chartLabel SizeSmallSize of numbersTiny: Multi-timeframe<br>Large: Focus on one chartUptrend ColorGreenPositive number colorCustomize to preferenceDowntrend ColorRedNegative number colorCustomize to preferenceOptimization by Trading Style:For Scalpers (1m - 5m charts):Trend Detection Length: 5-10
Label Size: Tiny
Show Labels: Optional (can be cluttered)
For Day Traders (15m - 1h charts):Trend Detection Length: 14-20
Label Size: Small
Show Labels: Yes
For Swing Traders (4h - Daily charts):Trend Detection Length: 50-100
Label Size: Normal
Show Labels: Yes
5. Trading Strategies {#strategies}Strategy 1: Trend Reversal TradingEntry Signals:
Buy: When counter changes from negative to +1
Sell: When counter changes from positive to -1
Confirmation:
Wait for +2 or -2 to confirm trend strength
Use additional indicators (RSI, MACD) for validation
Example:Candle: -5, -6, -7, -8, +1, +2 ← BUY HERE
Stop Loss: Below the -8 candle low
Target: When counter reaches +8 to +10
Strategy 2: Trend Continuation TradingEntry Signals:
Buy: Enter on pullbacks during uptrend (e.g., at +3, +5, +7)
Sell: Enter on bounces during downtrend (e.g., at -3, -5, -7)
Risk Management:
Avoid entering at high numbers (+15, -15) - trend may be exhausted
Example:Candle: +1, +2, +3 ← Small pullback, BUY
Continue: +4, +5, +6, +7
Exit: When counter resets to -1
Strategy 3: Trend Exhaustion DetectionWarning Signs:
Counter reaches +10 or higher → Uptrend may be overextended
Counter reaches -10 or lower → Downtrend may be overextended
Action:
Tighten stop losses
Take partial profits
Watch for reversal patterns (doji, engulfing)
Strategy 4: Multi-Timeframe AnalysisSetup:
Add indicator to 3 timeframes (e.g., 15m, 1h, 4h)
Look for alignment
Best Trades:15m: +1 (new uptrend)
1h: +5 (established uptrend)
4h: +3 (strong uptrend)
→ HIGH PROBABILITY BUY
6. Setting Up Alerts {#alerts}Built-in Alert Conditions:The script includes 2 automatic alerts:
"Uptrend Started" - Triggers when counter = +1
"Downtrend Started" - Triggers when counter = -1
How to Set Up Alerts:Step 1: Right-click on chart
Select "Add Alert"
Step 2: Configure Alert
Condition: Select "Trend Candle Counter"
Choose: "Uptrend Started" or "Downtrend Started"
Options:
Once per bar close (recommended)
Webhook URL (for automation)
Step 3: Notification Settings
✅ Popup
✅ Send email
✅ Push notification (mobile app)
✅ Play sound
Step 4: Create Alert
Click "Create"
Custom Alert Ideas:Alert for Specific Candle Numbers:
Notify when counter reaches +5 or -5
Notify when counter exceeds +10 or -10 (exhaustion)
7. Troubleshooting {#troubleshooting}Common Issues & Solutions:Issue 1: Labels are too cluttered
Solution:
Disable "Show Candle Numbers" in settings
Use larger timeframe
Reduce label size to "tiny"
Issue 2: Too many false signals
Solution:
Increase "Trend Detection Length" (e.g., 20, 50)
Wait for +2 or -2 confirmation
Combine with other indicators
Issue 3: Trend line doesn't match price action
Solution:
Adjust EMA length to match your trading style
Consider using different trend detection (SMA, HMA)
Issue 4: Indicator not showing on chart
Solution:
Check if it's in a separate pane - move to main chart
Refresh the page
Re-add the indicator
Issue 5: Counter seems delayed
Solution:
This is normal - indicator confirms on candle close
For faster signals, use lower timeframe
Reduce EMA length (but expect more noise)
8. Advanced Tips 💡Combining with Other Indicators:Best Combinations:
RSI + Trend Candle Counter
Buy at +1 when RSI > 50
Sell at -1 when RSI < 50
MACD + Trend Candle Counter
Confirm +1 with MACD bullish crossover
Confirm -1 with MACD bearish crossover
Volume + Trend Candle Counter
Strong trends (+1) should have increasing volume
Low volume at high numbers (+10) = exhaustion
Reading Market Psychology:[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}Counter ValueMarket Psychology+1 to +3Early adopters entering+4 to +7Momentum building+8 to +12FOMO phase+13+Extreme greed - caution!-1 to -3Early sellers-4 to -7Panic building-8 to -12Capitulation-13+Extreme fear - reversal likely9. Real Trading Example 📊Scenario: BTC/USD 1H ChartTime | Counter | Action
--------|---------|----------------------------------
10:00 | -8 | Downtrend established
11:00 | -9 | Still falling
12:00 | -10 | Exhaustion zone - watch closely
13:00 | +1 | ✅ BUY SIGNAL - Trend reversal!
14:00 | +2 | Confirmation - trend valid
15:00 | +3 | Hold position
16:00 | +4 | Add to position (optional)
17:00 | +5 | Move stop loss to breakeven
...
22:00 | +11 | Take partial profits
23:00 | +12 | Tighten stop loss
00:00 | -1 | ❌ EXIT - Trend reversed
Installation Guide
Understanding the Indicator
How It Works
Customization Options
Trading Strategies
Setting Up Alerts
Troubleshooting
1. Installation Guide {#installation}Step-by-Step Installation:Step 1: Open TradingView
Go to tradingview.com
Log in to your account
Step 2: Access Pine Editor
Click on "Pine Editor" tab at the bottom of the chart
Or press Alt + E (Windows) or Option + E (Mac)
Step 3: Create New Indicator
Click "Open" → "New blank indicator"
Delete any default code
Step 4: Paste the Script
Copy the entire Trend Candle Counter script
Paste it into the editor
Step 5: Save and Apply
Click "Save" (or Ctrl + S)
Give it a name: "Trend Candle Counter"
Click "Add to Chart"
✅ Done! The indicator should now appear on your chart.2. Understanding the Indicator {#understanding}What Does It Do?This indicator numbers each candle based on the current trend:[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}Trend TypeNumberingVisualUptrend+1, +2, +3, +4...🟢 Green labelsDowntrend-1, -2, -3, -4...🔴 Red labelsTrend ChangeResets to ±1Label color switchesVisual Components:
Candle Labels - Numbers above each candle
Trend Line (EMA) - Green (up) / Red (down)
Background Shading - Light green/red tint
Info Table - Top-right corner showing:
Current trend direction
Current candle number
Current price
3. How It Works {#how-it-works}Trend Detection Logic:IF Close > EMA → UPTREND (positive counting)
IF Close < EMA → DOWNTREND (negative counting)
Counting Mechanism:Example Uptrend:Candle 1: Close > EMA → Label: +1
Candle 2: Close > EMA → Label: +2
Candle 3: Close > EMA → Label: +3
Candle 4: Close < EMA → Label: -1 (trend changed!)
Example Downtrend:Candle 1: Close < EMA → Label: -1
Candle 2: Close < EMA → Label: -2
Candle 3: Close < EMA → Label: -3
Candle 4: Close > EMA → Label: +1 (trend changed!)
Key Insight:The higher the absolute number, the longer the trend has been running!4. Customization Options {#customization}Accessing Settings:
Click the gear icon ⚙️ next to the indicator name
Go to "Inputs" tab
Available Parameters:[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}ParameterDefaultDescriptionRecommendationTrend Detection Length14EMA period for trend5-10: Scalping<br>14-20: Day trading<br>50-200: Swing tradingShow Candle Numbers✅ YesDisplay labelsDisable for cleaner chartLabel SizeSmallSize of numbersTiny: Multi-timeframe<br>Large: Focus on one chartUptrend ColorGreenPositive number colorCustomize to preferenceDowntrend ColorRedNegative number colorCustomize to preferenceOptimization by Trading Style:For Scalpers (1m - 5m charts):Trend Detection Length: 5-10
Label Size: Tiny
Show Labels: Optional (can be cluttered)
For Day Traders (15m - 1h charts):Trend Detection Length: 14-20
Label Size: Small
Show Labels: Yes
For Swing Traders (4h - Daily charts):Trend Detection Length: 50-100
Label Size: Normal
Show Labels: Yes
5. Trading Strategies {#strategies}Strategy 1: Trend Reversal TradingEntry Signals:
Buy: When counter changes from negative to +1
Sell: When counter changes from positive to -1
Confirmation:
Wait for +2 or -2 to confirm trend strength
Use additional indicators (RSI, MACD) for validation
Example:Candle: -5, -6, -7, -8, +1, +2 ← BUY HERE
Stop Loss: Below the -8 candle low
Target: When counter reaches +8 to +10
Strategy 2: Trend Continuation TradingEntry Signals:
Buy: Enter on pullbacks during uptrend (e.g., at +3, +5, +7)
Sell: Enter on bounces during downtrend (e.g., at -3, -5, -7)
Risk Management:
Avoid entering at high numbers (+15, -15) - trend may be exhausted
Example:Candle: +1, +2, +3 ← Small pullback, BUY
Continue: +4, +5, +6, +7
Exit: When counter resets to -1
Strategy 3: Trend Exhaustion DetectionWarning Signs:
Counter reaches +10 or higher → Uptrend may be overextended
Counter reaches -10 or lower → Downtrend may be overextended
Action:
Tighten stop losses
Take partial profits
Watch for reversal patterns (doji, engulfing)
Strategy 4: Multi-Timeframe AnalysisSetup:
Add indicator to 3 timeframes (e.g., 15m, 1h, 4h)
Look for alignment
Best Trades:15m: +1 (new uptrend)
1h: +5 (established uptrend)
4h: +3 (strong uptrend)
→ HIGH PROBABILITY BUY
6. Setting Up Alerts {#alerts}Built-in Alert Conditions:The script includes 2 automatic alerts:
"Uptrend Started" - Triggers when counter = +1
"Downtrend Started" - Triggers when counter = -1
How to Set Up Alerts:Step 1: Right-click on chart
Select "Add Alert"
Step 2: Configure Alert
Condition: Select "Trend Candle Counter"
Choose: "Uptrend Started" or "Downtrend Started"
Options:
Once per bar close (recommended)
Webhook URL (for automation)
Step 3: Notification Settings
✅ Popup
✅ Send email
✅ Push notification (mobile app)
✅ Play sound
Step 4: Create Alert
Click "Create"
Custom Alert Ideas:Alert for Specific Candle Numbers:
Notify when counter reaches +5 or -5
Notify when counter exceeds +10 or -10 (exhaustion)
7. Troubleshooting {#troubleshooting}Common Issues & Solutions:Issue 1: Labels are too cluttered
Solution:
Disable "Show Candle Numbers" in settings
Use larger timeframe
Reduce label size to "tiny"
Issue 2: Too many false signals
Solution:
Increase "Trend Detection Length" (e.g., 20, 50)
Wait for +2 or -2 confirmation
Combine with other indicators
Issue 3: Trend line doesn't match price action
Solution:
Adjust EMA length to match your trading style
Consider using different trend detection (SMA, HMA)
Issue 4: Indicator not showing on chart
Solution:
Check if it's in a separate pane - move to main chart
Refresh the page
Re-add the indicator
Issue 5: Counter seems delayed
Solution:
This is normal - indicator confirms on candle close
For faster signals, use lower timeframe
Reduce EMA length (but expect more noise)
8. Advanced Tips 💡Combining with Other Indicators:Best Combinations:
RSI + Trend Candle Counter
Buy at +1 when RSI > 50
Sell at -1 when RSI < 50
MACD + Trend Candle Counter
Confirm +1 with MACD bullish crossover
Confirm -1 with MACD bearish crossover
Volume + Trend Candle Counter
Strong trends (+1) should have increasing volume
Low volume at high numbers (+10) = exhaustion
Reading Market Psychology:[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}Counter ValueMarket Psychology+1 to +3Early adopters entering+4 to +7Momentum building+8 to +12FOMO phase+13+Extreme greed - caution!-1 to -3Early sellers-4 to -7Panic building-8 to -12Capitulation-13+Extreme fear - reversal likely9. Real Trading Example 📊Scenario: BTC/USD 1H ChartTime | Counter | Action
--------|---------|----------------------------------
10:00 | -8 | Downtrend established
11:00 | -9 | Still falling
12:00 | -10 | Exhaustion zone - watch closely
13:00 | +1 | ✅ BUY SIGNAL - Trend reversal!
14:00 | +2 | Confirmation - trend valid
15:00 | +3 | Hold position
16:00 | +4 | Add to position (optional)
17:00 | +5 | Move stop loss to breakeven
...
22:00 | +11 | Take partial profits
23:00 | +12 | Tighten stop loss
00:00 | -1 | ❌ EXIT - Trend reversed
Скрипт с открытым кодом
В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения.
Отказ от ответственности
Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.
Скрипт с открытым кодом
В истинном духе TradingView автор этого скрипта опубликовал его с открытым исходным кодом, чтобы трейдеры могли понять, как он работает, и проверить на практике. Вы можете воспользоваться им бесплатно, но повторное использование этого кода в публикации регулируется Правилами поведения.
Отказ от ответственности
Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.