OPEN-SOURCE SCRIPT
EMA Slope First Flip Signal

1. EMA Calculation:
It calculates 4 Exponential Moving Averages:
EMA 5 – very fast (captures short-term moves)
EMA 9 – fast
EMA 21 – medium
EMA 50 – long-term trend
2. Slope Calculation:
It finds the slope of each EMA using:
pinescript
Copy
Edit
slopeX = emaX - emaX[1]
This checks if the EMA is rising (slope > 0) or falling (slope < 0).
3. Trend Condition:
Buy condition: All 4 EMA slopes must be positive
Sell condition: All 4 EMA slopes must be negative
4. First Signal Logic:
It only flashes a signal when the direction changes.
For example:
If EMAs were not all rising before, but now all are → BUY
If EMAs were not all falling before, but now all are → SELL
Prevents repeated signals during the same trend.
5. Safe Boolean Handling:
Uses bool(condition[1]) to access previous state without error
Avoids using nz() or na() on booleans (which causes errors)
📈 What You See on Chart:
✅ Green "BUY" label below candle when all EMA slopes turn positive for the first time
❌ Red "SELL" label above candle when all EMA slopes turn negative for the first time
🔄 No duplicate signals in the same direction — only on reversal
It calculates 4 Exponential Moving Averages:
EMA 5 – very fast (captures short-term moves)
EMA 9 – fast
EMA 21 – medium
EMA 50 – long-term trend
2. Slope Calculation:
It finds the slope of each EMA using:
pinescript
Copy
Edit
slopeX = emaX - emaX[1]
This checks if the EMA is rising (slope > 0) or falling (slope < 0).
3. Trend Condition:
Buy condition: All 4 EMA slopes must be positive
Sell condition: All 4 EMA slopes must be negative
4. First Signal Logic:
It only flashes a signal when the direction changes.
For example:
If EMAs were not all rising before, but now all are → BUY
If EMAs were not all falling before, but now all are → SELL
Prevents repeated signals during the same trend.
5. Safe Boolean Handling:
Uses bool(condition[1]) to access previous state without error
Avoids using nz() or na() on booleans (which causes errors)
📈 What You See on Chart:
✅ Green "BUY" label below candle when all EMA slopes turn positive for the first time
❌ Red "SELL" label above candle when all EMA slopes turn negative for the first time
🔄 No duplicate signals in the same direction — only on reversal
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.