Skip to content

Instantly share code, notes, and snippets.

@IamTamheedNazir
Last active October 8, 2026 17:22
Show Gist options
  • Select an option

  • Save IamTamheedNazir/037f8afcb749e911c42af1ea2f526c06 to your computer and use it in GitHub Desktop.

Select an option

Save IamTamheedNazir/037f8afcb749e911c42af1ea2f526c06 to your computer and use it in GitHub Desktop.
Advanced Crypto Pattern Predictor - Multi-Timeframe Trading Indicator for TradingView

Advanced Crypto Pattern Predictor for TradingView

🚀 Features

This comprehensive Pine Script indicator predicts future candle patterns and market direction for crypto trading with:

Core Capabilities

  • Multi-Timeframe Analysis: Predictions for 5min, 15min, 30min, and 60min timeframes
  • Buy/Sell Signals: Strong Buy, Buy, Sell, Strong Sell with visual markers
  • Probability Scores: Shows confidence level (0-100%) for each prediction
  • Target Prices: Displays 3 target levels (T1, T2, T3) and stop-loss
  • Pattern Recognition: Detects 8+ candlestick patterns (engulfing, hammer, shooting star, etc.)

Technical Analysis Components

  1. RSI (Relative Strength Index) - Overbought/oversold conditions
  2. MACD - Trend momentum and crossovers
  3. Bollinger Bands - Volatility and price extremes
  4. Moving Averages - EMA 20, 50, 200 for trend identification
  5. Volume Analysis - Confirms signal strength
  6. ATR (Average True Range) - Calculates realistic targets

Prediction Algorithm

The indicator uses a weighted scoring system (0-100 points):

  • RSI signals: 20 points
  • MACD crossovers: 20 points
  • Bollinger Band position: 15 points
  • Trend alignment: 20 points
  • Candle patterns: 15 points
  • Volume confirmation: 10 points

Signal Thresholds:

  • Strong Buy: ≥75% bullish probability
  • Buy: 60-74% bullish probability
  • Neutral: 40-59%
  • Sell: 60-74% bearish probability
  • Strong Sell: ≥75% bearish probability

📊 How to Use

Installation

  1. Open TradingView
  2. Click on "Pine Editor" at the bottom
  3. Copy the entire code from crypto_pattern_predictor.pine
  4. Click "Add to Chart"
  5. The indicator will appear on your chart

Configuration

Customize settings in the indicator settings panel:

Timeframes:

  • Toggle 5min, 15min, 30min, 60min predictions on/off

Technical Settings:

  • RSI Length (default: 14)
  • MACD Fast/Slow/Signal (default: 12/26/9)
  • Bollinger Bands Length (default: 20)
  • BB Multiplier (default: 2.0)

Display Options:

  • Show/hide prediction labels
  • Show/hide target lines
  • Show/hide probability percentages

Reading the Signals

On Chart:

  • 🟢 Green triangles below candles = Buy signals
  • 🔴 Red triangles above candles = Sell signals
  • Larger triangles = Stronger signals
  • Labels show probability % and target prices

Multi-Timeframe Table (Top Right):

  • Shows predictions for all selected timeframes
  • Color-coded: Green (bullish), Red (bearish), Gray (neutral)
  • Displays signal type and probability for each timeframe

Target Lines:

  • Dashed green lines = Bullish targets (T1, T2, T3)
  • Dashed red lines = Bearish targets (T1, T2, T3)
  • Dotted lines = Stop-loss levels

Setting Up Alerts

  1. Right-click on the chart
  2. Select "Add Alert"
  3. Choose condition: "Strong Buy Signal", "Buy Signal", etc.
  4. Configure notification method (email, SMS, webhook)
  5. Click "Create"

💡 Trading Strategy Tips

For Best Results:

  1. Confirm with Multiple Timeframes: Look for alignment across 15min, 30min, and 60min
  2. Use Stop-Loss: Always set stop-loss at the suggested SL level
  3. Take Profits Gradually: Exit 33% at T1, 33% at T2, 33% at T3
  4. Volume Matters: Stronger signals when volume is above average
  5. Trend is Your Friend: Signals are more reliable when aligned with higher timeframe trend

Risk Management:

  • Never risk more than 2-3% of capital per trade
  • Use the provided stop-loss levels
  • Don't trade against strong trends
  • Wait for probability ≥70% for higher confidence

Best Timeframes for Crypto:

  • Scalping: 5min chart with 15min confirmation
  • Day Trading: 15min chart with 30min/60min confirmation
  • Swing Trading: 60min chart with 4H confirmation (add manually)

⚠️ Important Disclaimers

  1. Not Financial Advice: This indicator is for educational purposes only
  2. No Guarantee: Past performance doesn't guarantee future results
  3. Use at Your Own Risk: Always do your own research
  4. Test First: Use on paper trading before real money
  5. Market Conditions: Works best in trending markets, less reliable in choppy/sideways markets

🔧 Customization Ideas

For Aggressive Traders:

  • Lower signal threshold to 55% (edit line: buy = bullishProbability >= 55)
  • Reduce stop-loss multiplier to 1.0 (edit: bullStopLoss = close - (atr * 1.0))

For Conservative Traders:

  • Increase signal threshold to 80% (edit: strongBuy = bullishProbability >= 80)
  • Widen stop-loss to 2.0 (edit: bullStopLoss = close - (atr * 2.0))

For Scalpers:

  • Focus on 5min timeframe only
  • Reduce target multipliers (edit: bullTarget1 = close + (atr * 0.5))

📈 Performance Optimization

Best Crypto Pairs:

  • BTC/USDT, ETH/USDT (high liquidity)
  • Major altcoins with good volume
  • Avoid low-volume shitcoins

Best Trading Sessions:

  • High volatility periods (US/EU overlap)
  • Avoid low-volume Asian session for some pairs

🐛 Troubleshooting

Issue: No signals appearing

  • Check if you're on a supported timeframe (1min-1D)
  • Ensure "Show Prediction Labels" is enabled
  • Try adjusting technical settings

Issue: Too many signals

  • Increase probability threshold in settings
  • Focus on "Strong Buy/Sell" only
  • Use higher timeframes (30min, 60min)

Issue: Targets not showing

  • Enable "Show Target Lines" in settings
  • Check max_lines_count isn't exceeded

📝 Version History

v1.0 (Current)

  • Multi-timeframe predictions (5/15/30/60min)
  • 8 candlestick pattern recognition
  • Probability-based signals
  • Dynamic target calculation
  • Volume confirmation
  • Alert system

🤝 Support

For questions or improvements:

  • Test thoroughly before live trading
  • Backtest on historical data
  • Combine with other analysis methods
  • Keep a trading journal

📜 License

Free to use and modify for personal trading. Not for commercial redistribution.


Remember: The best indicator is the one you understand and trust. Take time to learn how this works, backtest it, and adapt it to your trading style. Good luck! 🚀

🚀 Crypto Future Candle Predictor - Ultimate Edition

✨ What Makes This Different?

This is NOT just another indicator. This is a complete prediction system that:

✅ Predicts FUTURE candle shapes - Shows you what the next 1-3 candles will likely look like ✅ Ultra-clean interface - No clutter, only high-confidence signals ✅ Multi-timeframe validation - Signals only when multiple timeframes agree ✅ Ghost candle visualization - See predicted candles drawn on your chart ✅ Confidence scoring - Every signal has a probability score (0-100%) ✅ Smart filtering - Only shows signals above your chosen threshold (default 80%)


🎯 Key Features

1. Confidence Score Engine

Analyzes 5 key factors:

  • 📊 Momentum (RSI, Stochastic) - 25 points
  • 📈 Trend (MACD, EMA alignment) - 30 points
  • 💥 Volatility (Bollinger Bands) - 20 points
  • 📦 Volume (Volume ratio) - 15 points
  • 🕯️ Patterns (Engulfing, Hammer, etc.) - 10 points

Total Score: 0-100% → Only signals above your threshold appear!

2. Future Candle Prediction

Shows ghost candles (semi-transparent boxes) representing:

  • Predicted HIGH (top of box)
  • Predicted LOW (bottom of box)
  • Predicted CLOSE (solid line inside)

You can predict 1, 2, or 3 candles ahead!

3. Multi-Timeframe Alignment

Compact table shows status for 4 timeframes:

  • 🟢 BULL - Confidence ≥ 65%
  • 🔴 BEAR - Confidence ≤ 35%
  • ⚪ NEUT - Neutral (35-65%)

Signals only trigger when 2+ timeframes agree (optional).

4. Clean Signals

Only shows:

  • Small "BUY" or "SELL" label on the candle
  • Detailed info box on the LATEST candle only
  • No overlapping, no mess!

📥 Installation

  1. Open TradingView → Pine Editor (bottom)
  2. Copy the code from: https://gist.github.com/IamTamheedNazir/037f8afcb749e911c42af1ea2f526c06
  3. Look for: crypto_predictor_v3_ultimate.pine
  4. Paste and click "Add to Chart"
  5. Done! 🎉

⚙️ Settings Explained

Signal Settings

Setting Default What It Does
Signal Confidence Threshold 80% Only show signals above this confidence
Show Buy Signals ✅ Toggle buy signals on/off
Show Sell Signals ✅ Toggle sell signals on/off
Require MTF Alignment ✅ Signal only when 2+ timeframes agree

Display Settings

Setting Default What It Does
Show Future Candle Projections ✅ Display ghost candles
Number of Projected Candles 3 How many candles to predict (1-3)
Show Multi-Timeframe Table ✅ Display TF status table

Timeframes

Customize which timeframes to analyze:

  • Timeframe 1: 5 min (default)
  • Timeframe 2: 15 min (default)
  • Timeframe 3: 30 min (default)
  • Timeframe 4: 60 min (default)

Colors

  • Bullish Projection Color: Light green (default)
  • Bearish Projection Color: Light red (default)

📖 How to Use

Step 1: Wait for a Signal

The chart stays clean until a high-confidence setup appears.

When conditions are met:

  • Small "BUY" or "SELL" label appears on the candle
  • Ghost candles show predicted future price action
  • Info box shows confidence %, targets, and stop-loss

Step 2: Check Multi-Timeframe Table

Look at the top-right table:

  • Are 2+ timeframes showing the same direction?
  • Higher alignment = stronger signal

Step 3: Read the Signal Details

The info box shows:

🚀 BUY SIGNAL
Confidence: 85%
T1: 6.5200
T2: 6.5800
T3: 6.6400
SL: 6.4100

Step 4: Execute the Trade

  • Entry: Current price
  • Targets: T1, T2, T3 (take profits gradually)
  • Stop-Loss: SL level (always use it!)

Step 5: Watch the Ghost Candles

The semi-transparent boxes show where price is likely to go:

  • If price follows the ghost candles → prediction working ✅
  • If price breaks away → adjust or exit ⚠️

💡 Trading Strategies

Strategy 1: Conservative (Recommended)

  • Threshold: 85%
  • MTF Alignment: Required
  • Projected Candles: 3
  • Risk: 1-2% per trade

When to trade: Only when ALL 4 timeframes show BULL or BEAR.

Strategy 2: Balanced

  • Threshold: 80%
  • MTF Alignment: Required
  • Projected Candles: 2
  • Risk: 2-3% per trade

When to trade: When 2-3 timeframes align.

Strategy 3: Aggressive

  • Threshold: 70%
  • MTF Alignment: Optional
  • Projected Candles: 1
  • Risk: 3-5% per trade

When to trade: Any signal on current timeframe.


🎓 Understanding Ghost Candles

What Are They?

Ghost candles are probabilistic projections of future price action based on:

  • Current momentum (confidence score)
  • Volatility (ATR)
  • Historical patterns

How to Read Them

Bullish Ghost Candles (Green):

   ┌─────┐  ← Predicted HIGH
   │     │
   │  ━  │  ← Predicted CLOSE (green line)
   │     │
   └─────┘  ← Predicted LOW

Bearish Ghost Candles (Red):

   ┌─────┐  ← Predicted HIGH
   │     │
   │  ━  │  ← Predicted CLOSE (red line)
   │     │
   └─────┘  ← Predicted LOW

Accuracy

  • Candle 1: Most accurate (~70-80% directional accuracy)
  • Candle 2: Moderate accuracy (~60-70%)
  • Candle 3: Lower accuracy (~50-60%)

Note: These are PREDICTIONS, not guarantees. Always use stop-loss!


📊 Best Practices

✅ DO:

  1. Wait for 80%+ confidence signals
  2. Check multi-timeframe alignment
  3. Use stop-loss ALWAYS
  4. Take profits at T1, T2, T3 (33% each)
  5. Trade high-volume pairs (BTC/USDT, ETH/USDT)
  6. Backtest on historical data first

❌ DON'T:

  1. Trade every signal (quality > quantity)
  2. Ignore stop-loss levels
  3. Trade against strong trends
  4. Use on low-volume shitcoins
  5. Risk more than 2-3% per trade
  6. Trade during low-liquidity hours

🔧 Customization Tips

For Scalpers:

Threshold: 75%
Projected Candles: 1
Timeframes: 1m, 5m, 15m, 30m
MTF Alignment: Optional

For Day Traders:

Threshold: 80%
Projected Candles: 2
Timeframes: 5m, 15m, 30m, 1h
MTF Alignment: Required

For Swing Traders:

Threshold: 85%
Projected Candles: 3
Timeframes: 1h, 4h, 1D, 1W
MTF Alignment: Required

🐛 Troubleshooting

Q: No signals appearing?

  • Lower the confidence threshold (try 70%)
  • Disable "Require MTF Alignment"
  • Check if you're on a supported timeframe

Q: Too many signals?

  • Increase threshold to 85-90%
  • Enable "Require MTF Alignment"
  • Focus on higher timeframes (30m, 1h)

Q: Ghost candles not showing?

  • Enable "Show Future Candle Projections" in settings
  • Check max_boxes_count isn't exceeded
  • Refresh the chart

Q: Predictions not accurate?

  • Remember: These are probabilities, not certainties
  • Use stop-loss to protect capital
  • Combine with your own analysis

⚠️ Disclaimer

IMPORTANT: This indicator is for educational purposes only.

  • ❌ Not financial advice
  • ❌ No guarantee of profits
  • ❌ Past performance ≠ future results
  • ✅ Always do your own research
  • ✅ Never risk more than you can afford to lose
  • ✅ Test on paper trading first

Crypto trading is risky. Use at your own risk.


📈 Performance Tips

Best Pairs:

  • BTC/USDT, ETH/USDT (highest liquidity)
  • Major altcoins: SOL, BNB, ADA, DOT
  • Avoid: Low-volume tokens, new listings

Best Times:

  • US/EU market overlap (12:00-16:00 UTC)
  • High volatility periods
  • Avoid: Weekends, holidays, Asian low-volume hours

Best Conditions:

  • Trending markets (up or down)
  • High volume days
  • Clear support/resistance levels

🎯 Success Metrics

Track these to improve:

  • Win Rate: Aim for 60%+ on 80% threshold signals
  • Risk/Reward: Minimum 1:2 (risk $100 to make $200)
  • Average Confidence: Higher = better (85%+ ideal)
  • MTF Alignment: Signals with 3-4 TF alignment perform best

🚀 Next Steps

  1. Install the indicator
  2. Backtest on historical data (use TradingView replay feature)
  3. Paper trade for 1-2 weeks
  4. Adjust settings to match your style
  5. Start with small positions
  6. Scale up gradually

📞 Support

For questions:

  • Read this guide thoroughly
  • Test different settings
  • Keep a trading journal
  • Learn from each trade

Remember: The best indicator is the one you understand and trust. Take time to learn how this works!


📝 Version History

v3.0 - Ultimate Edition

  • ✨ Future candle prediction with ghost visualization
  • ✨ Confidence score engine (0-100%)
  • ✨ Multi-timeframe alignment system
  • ✨ Ultra-clean interface
  • ✨ Smart signal filtering
  • ✨ Customizable everything

Good luck and trade safe! 🚀📈

//@version=5
indicator("Advanced Crypto Pattern Predictor", overlay=true, max_labels_count=500, max_lines_count=500)
// ============================================
// INPUTS
// ============================================
timeframe5 = input.bool(true, "Show 5min Predictions", group="Timeframes")
timeframe15 = input.bool(true, "Show 15min Predictions", group="Timeframes")
timeframe30 = input.bool(true, "Show 30min Predictions", group="Timeframes")
timeframe60 = input.bool(true, "Show 60min Predictions", group="Timeframes")
rsiLength = input.int(14, "RSI Length", group="Technical Settings")
macdFast = input.int(12, "MACD Fast", group="Technical Settings")
macdSlow = input.int(26, "MACD Slow", group="Technical Settings")
macdSignal = input.int(9, "MACD Signal", group="Technical Settings")
bbLength = input.int(20, "Bollinger Bands Length", group="Technical Settings")
bbMult = input.float(2.0, "BB Multiplier", group="Technical Settings")
showLabels = input.bool(true, "Show Prediction Labels", group="Display")
showTargets = input.bool(true, "Show Target Lines", group="Display")
showProbability = input.bool(true, "Show Probability %", group="Display")
// ============================================
// TECHNICAL INDICATORS
// ============================================
// RSI
rsi = ta.rsi(close, rsiLength)
// MACD
[macdLine, signalLine, histLine] = ta.macd(close, macdFast, macdSlow, macdSignal)
// Bollinger Bands
basis = ta.sma(close, bbLength)
dev = bbMult * ta.stdev(close, bbLength)
upperBB = basis + dev
lowerBB = basis - dev
// Moving Averages
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema200 = ta.ema(close, 200)
// Volume Analysis
volumeMA = ta.sma(volume, 20)
volumeRatio = volume / volumeMA
// ATR for volatility
atr = ta.atr(14)
// ============================================
// CANDLE PATTERN RECOGNITION
// ============================================
// Bullish Patterns
bullishEngulfing = close[1] < open[1] and close > open and close > open[1] and open < close[1]
hammer = (high - low) > 3 * (close - open) and (close - low) / (0.001 + high - low) > 0.6 and (open - low) / (0.001 + high - low) > 0.6
morningstar = close[2] < open[2] and math.abs(close[1] - open[1]) < (high[1] - low[1]) * 0.3 and close > open and close > (open[2] + close[2]) / 2
bullishHarami = close[1] < open[1] and close > open and open > close[1] and close < open[1]
// Bearish Patterns
bearishEngulfing = close[1] > open[1] and close < open and close < open[1] and open > close[1]
shootingStar = (high - low) > 3 * (open - close) and (high - close) / (0.001 + high - low) > 0.6 and (high - open) / (0.001 + high - low) > 0.6
eveningStar = close[2] > open[2] and math.abs(close[1] - open[1]) < (high[1] - low[1]) * 0.3 and close < open and close < (open[2] + close[2]) / 2
bearishHarami = close[1] > open[1] and close < open and open < close[1] and close > open[1]
// ============================================
// TREND ANALYSIS
// ============================================
uptrend = ema20 > ema50 and ema50 > ema200
downtrend = ema20 < ema50 and ema50 < ema200
// ============================================
// PREDICTION ALGORITHM
// ============================================
// Calculate bullish score (0-100)
calcBullishScore() =>
score = 0.0
// RSI signals (20 points)
if rsi < 30
score += 20
else if rsi < 40
score += 15
else if rsi > 70
score -= 10
// MACD signals (20 points)
if ta.crossover(macdLine, signalLine)
score += 20
else if macdLine > signalLine
score += 10
else if ta.crossunder(macdLine, signalLine)
score -= 20
// Bollinger Bands (15 points)
if close < lowerBB
score += 15
else if close > upperBB
score -= 15
// Trend alignment (20 points)
if uptrend
score += 20
else if downtrend
score -= 20
// Candle patterns (15 points)
if bullishEngulfing or hammer or morningstar or bullishHarami
score += 15
if bearishEngulfing or shootingStar or eveningStar or bearishHarami
score -= 15
// Volume confirmation (10 points)
if volumeRatio > 1.5 and close > open
score += 10
else if volumeRatio > 1.5 and close < open
score -= 10
score
bullishScore = calcBullishScore()
bullishProbability = math.min(100, math.max(0, 50 + bullishScore))
bearishProbability = 100 - bullishProbability
// ============================================
// SIGNAL GENERATION
// ============================================
strongBuy = bullishProbability >= 75
buy = bullishProbability >= 60 and bullishProbability < 75
strongSell = bearishProbability >= 75
sell = bearishProbability >= 60 and bearishProbability < 75
neutral = bullishProbability > 40 and bullishProbability < 60
// ============================================
// TARGET CALCULATION
// ============================================
// Calculate targets based on ATR
bullTarget1 = close + (atr * 1.0)
bullTarget2 = close + (atr * 2.0)
bullTarget3 = close + (atr * 3.0)
bullStopLoss = close - (atr * 1.5)
bearTarget1 = close - (atr * 1.0)
bearTarget2 = close - (atr * 2.0)
bearTarget3 = close - (atr * 3.0)
bearStopLoss = close + (atr * 1.5)
// ============================================
// MULTI-TIMEFRAME PREDICTIONS
// ============================================
// Get higher timeframe data
htf5_close = request.security(syminfo.tickerid, "5", close)
htf15_close = request.security(syminfo.tickerid, "15", close)
htf30_close = request.security(syminfo.tickerid, "30", close)
htf60_close = request.security(syminfo.tickerid, "60", close)
htf5_rsi = request.security(syminfo.tickerid, "5", rsi)
htf15_rsi = request.security(syminfo.tickerid, "15", rsi)
htf30_rsi = request.security(syminfo.tickerid, "30", rsi)
htf60_rsi = request.security(syminfo.tickerid, "60", rsi)
// ============================================
// VISUALIZATION
// ============================================
// Plot EMAs
plot(ema20, "EMA 20", color=color.blue, linewidth=1)
plot(ema50, "EMA 50", color=color.orange, linewidth=1)
plot(ema200, "EMA 200", color=color.red, linewidth=2)
// Plot Bollinger Bands
p1 = plot(upperBB, "Upper BB", color=color.new(color.gray, 70))
p2 = plot(lowerBB, "Lower BB", color=color.new(color.gray, 70))
fill(p1, p2, color=color.new(color.gray, 90))
// Buy/Sell Signals
plotshape(strongBuy, "Strong Buy", shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.normal)
plotshape(buy, "Buy", shape.triangleup, location.belowbar, color.new(color.green, 50), size=size.small)
plotshape(strongSell, "Strong Sell", shape.triangledown, location.abovebar, color.new(color.red, 0), size=size.normal)
plotshape(sell, "Sell", shape.triangledown, location.abovebar, color.new(color.red, 50), size=size.small)
// ============================================
// LABELS WITH PREDICTIONS
// ============================================
if showLabels and (strongBuy or buy or strongSell or sell)
labelText = ""
labelColor = color.gray
labelY = low
if strongBuy or buy
labelText := "🚀 " + (strongBuy ? "STRONG BUY" : "BUY") + "\n"
labelText := labelText + "Probability: " + str.tostring(bullishProbability, "#.0") + "%\n"
if showTargets
labelText := labelText + "T1: " + str.tostring(bullTarget1, "#.##") + "\n"
labelText := labelText + "T2: " + str.tostring(bullTarget2, "#.##") + "\n"
labelText := labelText + "T3: " + str.tostring(bullTarget3, "#.##") + "\n"
labelText := labelText + "SL: " + str.tostring(bullStopLoss, "#.##")
labelColor := color.new(color.green, 10)
labelY := low - (atr * 2)
if strongSell or sell
labelText := "⚠️ " + (strongSell ? "STRONG SELL" : "SELL") + "\n"
labelText := labelText + "Probability: " + str.tostring(bearishProbability, "#.0") + "%\n"
if showTargets
labelText := labelText + "T1: " + str.tostring(bearTarget1, "#.##") + "\n"
labelText := labelText + "T2: " + str.tostring(bearTarget2, "#.##") + "\n"
labelText := labelText + "T3: " + str.tostring(bearTarget3, "#.##") + "\n"
labelText := labelText + "SL: " + str.tostring(bearStopLoss, "#.##")
labelColor := color.new(color.red, 10)
labelY := high + (atr * 2)
label.new(bar_index, labelY, labelText, style=label.style_label_up, color=labelColor, textcolor=color.white, size=size.normal)
// ============================================
// TARGET LINES
// ============================================
if showTargets and strongBuy
line.new(bar_index, bullTarget1, bar_index + 10, bullTarget1, color=color.new(color.green, 50), width=1, style=line.style_dashed)
line.new(bar_index, bullTarget2, bar_index + 10, bullTarget2, color=color.new(color.green, 30), width=1, style=line.style_dashed)
line.new(bar_index, bullTarget3, bar_index + 10, bullTarget3, color=color.new(color.green, 10), width=2, style=line.style_dashed)
line.new(bar_index, bullStopLoss, bar_index + 10, bullStopLoss, color=color.new(color.red, 30), width=1, style=line.style_dotted)
if showTargets and strongSell
line.new(bar_index, bearTarget1, bar_index + 10, bearTarget1, color=color.new(color.red, 50), width=1, style=line.style_dashed)
line.new(bar_index, bearTarget2, bar_index + 10, bearTarget2, color=color.new(color.red, 30), width=1, style=line.style_dashed)
line.new(bar_index, bearTarget3, bar_index + 10, bearTarget3, color=color.new(color.red, 10), width=2, style=line.style_dashed)
line.new(bar_index, bearStopLoss, bar_index + 10, bearStopLoss, color=color.new(color.green, 30), width=1, style=line.style_dotted)
// ============================================
// TABLE WITH MULTI-TIMEFRAME ANALYSIS
// ============================================
var table mtfTable = table.new(position.top_right, 3, 6, border_width=2)
if barstate.islast
// Header
table.cell(mtfTable, 0, 0, "Timeframe", bgcolor=color.new(color.gray, 30), text_color=color.white, text_size=size.normal)
table.cell(mtfTable, 1, 0, "Signal", bgcolor=color.new(color.gray, 30), text_color=color.white, text_size=size.normal)
table.cell(mtfTable, 2, 0, "Probability", bgcolor=color.new(color.gray, 30), text_color=color.white, text_size=size.normal)
// Current timeframe
currentSignal = strongBuy ? "🚀 STRONG BUY" : buy ? "📈 BUY" : strongSell ? "⚠️ STRONG SELL" : sell ? "📉 SELL" : "➖ NEUTRAL"
currentColor = strongBuy or buy ? color.new(color.green, 70) : strongSell or sell ? color.new(color.red, 70) : color.new(color.gray, 70)
table.cell(mtfTable, 0, 1, "Current", bgcolor=color.new(color.gray, 80), text_color=color.white)
table.cell(mtfTable, 1, 1, currentSignal, bgcolor=currentColor, text_color=color.white)
table.cell(mtfTable, 2, 1, str.tostring(bullishProbability, "#.0") + "%", bgcolor=currentColor, text_color=color.white)
// 5min
if timeframe5
signal5 = htf5_rsi < 30 ? "📈 BUY" : htf5_rsi > 70 ? "📉 SELL" : "➖ NEUTRAL"
color5 = htf5_rsi < 30 ? color.new(color.green, 70) : htf5_rsi > 70 ? color.new(color.red, 70) : color.new(color.gray, 70)
prob5 = htf5_rsi < 50 ? (50 - htf5_rsi) + 50 : 50 - (htf5_rsi - 50)
table.cell(mtfTable, 0, 2, "5min", bgcolor=color.new(color.gray, 80), text_color=color.white)
table.cell(mtfTable, 1, 2, signal5, bgcolor=color5, text_color=color.white)
table.cell(mtfTable, 2, 2, str.tostring(prob5, "#.0") + "%", bgcolor=color5, text_color=color.white)
// 15min
if timeframe15
signal15 = htf15_rsi < 30 ? "📈 BUY" : htf15_rsi > 70 ? "📉 SELL" : "➖ NEUTRAL"
color15 = htf15_rsi < 30 ? color.new(color.green, 70) : htf15_rsi > 70 ? color.new(color.red, 70) : color.new(color.gray, 70)
prob15 = htf15_rsi < 50 ? (50 - htf15_rsi) + 50 : 50 - (htf15_rsi - 50)
table.cell(mtfTable, 0, 3, "15min", bgcolor=color.new(color.gray, 80), text_color=color.white)
table.cell(mtfTable, 1, 3, signal15, bgcolor=color15, text_color=color.white)
table.cell(mtfTable, 2, 3, str.tostring(prob15, "#.0") + "%", bgcolor=color15, text_color=color.white)
// 30min
if timeframe30
signal30 = htf30_rsi < 30 ? "📈 BUY" : htf30_rsi > 70 ? "📉 SELL" : "➖ NEUTRAL"
color30 = htf30_rsi < 30 ? color.new(color.green, 70) : htf30_rsi > 70 ? color.new(color.red, 70) : color.new(color.gray, 70)
prob30 = htf30_rsi < 50 ? (50 - htf30_rsi) + 50 : 50 - (htf30_rsi - 50)
table.cell(mtfTable, 0, 4, "30min", bgcolor=color.new(color.gray, 80), text_color=color.white)
table.cell(mtfTable, 1, 4, signal30, bgcolor=color30, text_color=color.white)
table.cell(mtfTable, 2, 4, str.tostring(prob30, "#.0") + "%", bgcolor=color30, text_color=color.white)
// 60min
if timeframe60
signal60 = htf60_rsi < 30 ? "📈 BUY" : htf60_rsi > 70 ? "📉 SELL" : "➖ NEUTRAL"
color60 = htf60_rsi < 30 ? color.new(color.green, 70) : htf60_rsi > 70 ? color.new(color.red, 70) : color.new(color.gray, 70)
prob60 = htf60_rsi < 50 ? (50 - htf60_rsi) + 50 : 50 - (htf60_rsi - 50)
table.cell(mtfTable, 0, 5, "60min", bgcolor=color.new(color.gray, 80), text_color=color.white)
table.cell(mtfTable, 1, 5, signal60, bgcolor=color60, text_color=color.white)
table.cell(mtfTable, 2, 5, str.tostring(prob60, "#.0") + "%", bgcolor=color60, text_color=color.white)
// ============================================
// ALERTS
// ============================================
alertcondition(strongBuy, "Strong Buy Signal", "🚀 STRONG BUY - Probability: {{plot_0}}%")
alertcondition(buy, "Buy Signal", "📈 BUY - Probability: {{plot_0}}%")
alertcondition(strongSell, "Strong Sell Signal", "⚠️ STRONG SELL - Probability: {{plot_1}}%")
alertcondition(sell, "Sell Signal", "📉 SELL - Probability: {{plot_1}}%")
//@version=5
indicator("Crypto Pattern Predictor - Clean", overlay=true, max_labels_count=50, max_lines_count=50)
// ============================================
// INPUTS - SIMPLIFIED
// ============================================
signalStrength = input.string("Strong Only", "Signal Filter", options=["All Signals", "Strong Only", "Medium+"], group="Settings")
showTable = input.bool(true, "Show Multi-Timeframe Table", group="Display")
showTargets = input.bool(false, "Show Target Lines", group="Display", tooltip="Enable to see T1, T2, T3 target lines")
showLabels = input.bool(true, "Show Signal Labels", group="Display")
minProbability = input.int(70, "Minimum Probability %", minval=50, maxval=95, group="Settings", tooltip="Only show signals above this probability")
// ============================================
// TECHNICAL INDICATORS
// ============================================
rsi = ta.rsi(close, 14)
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
// Bollinger Bands
basis = ta.sma(close, 20)
dev = 2.0 * ta.stdev(close, 20)
upperBB = basis + dev
lowerBB = basis - dev
// Moving Averages
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema200 = ta.ema(close, 200)
// Volume
volumeMA = ta.sma(volume, 20)
volumeRatio = volume / volumeMA
// ATR
atr = ta.atr(14)
// ============================================
// PATTERN RECOGNITION - SIMPLIFIED
// ============================================
bullishEngulfing = close[1] < open[1] and close > open and close > open[1] and open < close[1]
hammer = (high - low) > 3 * (close - open) and (close - low) / (0.001 + high - low) > 0.6
bearishEngulfing = close[1] > open[1] and close < open and close < open[1] and open > close[1]
shootingStar = (high - low) > 3 * (open - close) and (high - close) / (0.001 + high - low) > 0.6
// ============================================
// TREND
// ============================================
uptrend = ema20 > ema50 and ema50 > ema200
downtrend = ema20 < ema50 and ema50 < ema200
// ============================================
// PREDICTION SCORE
// ============================================
calcScore() =>
score = 50.0 // Start neutral
// RSI (±20)
if rsi < 30
score += 20
else if rsi < 40
score += 10
else if rsi > 70
score -= 20
else if rsi > 60
score -= 10
// MACD (±20)
if ta.crossover(macdLine, signalLine)
score += 20
else if macdLine > signalLine and histLine > histLine[1]
score += 10
else if ta.crossunder(macdLine, signalLine)
score -= 20
else if macdLine < signalLine and histLine < histLine[1]
score -= 10
// Bollinger Bands (±15)
if close < lowerBB
score += 15
else if close > upperBB
score -= 15
// Trend (±20)
if uptrend
score += 20
else if downtrend
score -= 20
// Patterns (±15)
if bullishEngulfing or hammer
score += 15
if bearishEngulfing or shootingStar
score -= 15
// Volume (±10)
if volumeRatio > 1.5 and close > open
score += 10
else if volumeRatio > 1.5 and close < open
score -= 10
math.min(100, math.max(0, score))
probability = calcScore()
isBullish = probability >= 50
isBearish = probability < 50
// Signal strength
strongBuy = probability >= 75
buy = probability >= 60 and probability < 75
strongSell = probability <= 25
sell = probability > 25 and probability <= 40
// Apply filters
showStrongBuy = strongBuy and probability >= minProbability
showBuy = buy and probability >= minProbability and signalStrength != "Strong Only"
showStrongSell = strongSell and (100 - probability) >= minProbability
showSell = sell and (100 - probability) >= minProbability and signalStrength != "Strong Only"
// ============================================
// TARGETS
// ============================================
bullTarget1 = close + (atr * 1.0)
bullTarget2 = close + (atr * 2.0)
bullTarget3 = close + (atr * 3.0)
bullStopLoss = close - (atr * 1.5)
bearTarget1 = close - (atr * 1.0)
bearTarget2 = close - (atr * 2.0)
bearTarget3 = close - (atr * 3.0)
bearStopLoss = close + (atr * 1.5)
// ============================================
// VISUALIZATION - CLEAN
// ============================================
// Plot EMAs (subtle)
plot(ema20, "EMA 20", color=color.new(color.blue, 70), linewidth=1)
plot(ema50, "EMA 50", color=color.new(color.orange, 70), linewidth=1)
plot(ema200, "EMA 200", color=color.new(color.red, 70), linewidth=1)
// Signals - ONLY STRONG ONES BY DEFAULT
plotshape(showStrongBuy, "Strong Buy", shape.triangleup, location.belowbar, color.new(color.green, 0), size=size.small)
plotshape(showBuy, "Buy", shape.triangleup, location.belowbar, color.new(color.green, 50), size=size.tiny)
plotshape(showStrongSell, "Strong Sell", shape.triangledown, location.abovebar, color.new(color.red, 0), size=size.small)
plotshape(showSell, "Sell", shape.triangledown, location.abovebar, color.new(color.red, 50), size=size.tiny)
// ============================================
// LABELS - CLEAN & MINIMAL
// ============================================
if showLabels and barstate.islast
if showStrongBuy or showBuy
labelText = (showStrongBuy ? "🚀 STRONG BUY" : "📈 BUY") + "\n" + str.tostring(probability, "#") + "%"
if showTargets
labelText := labelText + "\nT1: " + str.tostring(bullTarget1, "#.##") + " | T2: " + str.tostring(bullTarget2, "#.##") + " | T3: " + str.tostring(bullTarget3, "#.##")
labelText := labelText + "\nSL: " + str.tostring(bullStopLoss, "#.##")
label.new(bar_index, low - atr, labelText, style=label.style_label_up, color=color.new(color.green, 20), textcolor=color.white, size=size.normal)
if showStrongSell or showSell
labelText = (showStrongSell ? "⚠️ STRONG SELL" : "📉 SELL") + "\n" + str.tostring(100 - probability, "#") + "%"
if showTargets
labelText := labelText + "\nT1: " + str.tostring(bearTarget1, "#.##") + " | T2: " + str.tostring(bearTarget2, "#.##") + " | T3: " + str.tostring(bearTarget3, "#.##")
labelText := labelText + "\nSL: " + str.tostring(bearStopLoss, "#.##")
label.new(bar_index, high + atr, labelText, style=label.style_label_down, color=color.new(color.red, 20), textcolor=color.white, size=size.normal)
// ============================================
// MULTI-TIMEFRAME TABLE - COMPACT
// ============================================
if showTable
var table mtfTable = table.new(position.top_right, 3, 5, border_width=1)
if barstate.islast
// Header
table.cell(mtfTable, 0, 0, "TF", bgcolor=color.new(color.gray, 20), text_color=color.white, text_size=size.small)
table.cell(mtfTable, 1, 0, "Signal", bgcolor=color.new(color.gray, 20), text_color=color.white, text_size=size.small)
table.cell(mtfTable, 2, 0, "Prob", bgcolor=color.new(color.gray, 20), text_color=color.white, text_size=size.small)
// Current
currentSignal = strongBuy ? "🚀 S.BUY" : buy ? "📈 BUY" : strongSell ? "⚠️ S.SELL" : sell ? "📉 SELL" : "➖ NEUT"
currentColor = (strongBuy or buy) ? color.new(color.green, 70) : (strongSell or sell) ? color.new(color.red, 70) : color.new(color.gray, 70)
table.cell(mtfTable, 0, 1, "Now", bgcolor=color.new(color.gray, 80), text_color=color.white, text_size=size.small)
table.cell(mtfTable, 1, 1, currentSignal, bgcolor=currentColor, text_color=color.white, text_size=size.small)
table.cell(mtfTable, 2, 1, str.tostring(probability, "#") + "%", bgcolor=currentColor, text_color=color.white, text_size=size.small)
// 15min
htf15_rsi = request.security(syminfo.tickerid, "15", rsi)
signal15 = htf15_rsi < 30 ? "📈 BUY" : htf15_rsi > 70 ? "📉 SELL" : "➖ NEUT"
color15 = htf15_rsi < 30 ? color.new(color.green, 70) : htf15_rsi > 70 ? color.new(color.red, 70) : color.new(color.gray, 70)
prob15 = htf15_rsi < 50 ? 50 + (50 - htf15_rsi) : 50 - (htf15_rsi - 50)
table.cell(mtfTable, 0, 2, "15m", bgcolor=color.new(color.gray, 80), text_color=color.white, text_size=size.small)
table.cell(mtfTable, 1, 2, signal15, bgcolor=color15, text_color=color.white, text_size=size.small)
table.cell(mtfTable, 2, 2, str.tostring(prob15, "#") + "%", bgcolor=color15, text_color=color.white, text_size=size.small)
// 30min
htf30_rsi = request.security(syminfo.tickerid, "30", rsi)
signal30 = htf30_rsi < 30 ? "📈 BUY" : htf30_rsi > 70 ? "📉 SELL" : "➖ NEUT"
color30 = htf30_rsi < 30 ? color.new(color.green, 70) : htf30_rsi > 70 ? color.new(color.red, 70) : color.new(color.gray, 70)
prob30 = htf30_rsi < 50 ? 50 + (50 - htf30_rsi) : 50 - (htf30_rsi - 50)
table.cell(mtfTable, 0, 3, "30m", bgcolor=color.new(color.gray, 80), text_color=color.white, text_size=size.small)
table.cell(mtfTable, 1, 3, signal30, bgcolor=color30, text_color=color.white, text_size=size.small)
table.cell(mtfTable, 2, 3, str.tostring(prob30, "#") + "%", bgcolor=color30, text_color=color.white, text_size=size.small)
// 60min
htf60_rsi = request.security(syminfo.tickerid, "60", rsi)
signal60 = htf60_rsi < 30 ? "📈 BUY" : htf60_rsi > 70 ? "📉 SELL" : "➖ NEUT"
color60 = htf60_rsi < 30 ? color.new(color.green, 70) : htf60_rsi > 70 ? color.new(color.red, 70) : color.new(color.gray, 70)
prob60 = htf60_rsi < 50 ? 50 + (50 - htf60_rsi) : 50 - (htf60_rsi - 50)
table.cell(mtfTable, 0, 4, "60m", bgcolor=color.new(color.gray, 80), text_color=color.white, text_size=size.small)
table.cell(mtfTable, 1, 4, signal60, bgcolor=color60, text_color=color.white, text_size=size.small)
table.cell(mtfTable, 2, 4, str.tostring(prob60, "#") + "%", bgcolor=color60, text_color=color.white, text_size=size.small)
// ============================================
// ALERTS
// ============================================
alertcondition(strongBuy, "Strong Buy", "🚀 STRONG BUY - {{ticker}} - Probability: " + str.tostring(probability, "#") + "%")
alertcondition(strongSell, "Strong Sell", "⚠️ STRONG SELL - {{ticker}} - Probability: " + str.tostring(100-probability, "#") + "%")
//@version=5
indicator("Crypto Future Candle Predictor", overlay=true, max_boxes_count=50, max_labels_count=20, max_lines_count=30)
// ============================================
// USER INPUTS - FULL CONTROL
// ============================================
confidenceThreshold = input.int(80, "Signal Confidence Threshold (%)", minval=60, maxval=95, group="Signal Settings", tooltip="Only show signals above this confidence level")
showProjections = input.bool(true, "Show Future Candle Projections", group="Display", tooltip="Display predicted ghost candles")
numProjectedCandles = input.int(3, "Number of Projected Candles", minval=1, maxval=3, group="Display")
showMTFTable = input.bool(true, "Show Multi-Timeframe Table", group="Display")
showBuySignals = input.bool(true, "Show Buy Signals", group="Signal Settings")
showSellSignals = input.bool(true, "Show Sell Signals", group="Signal Settings")
requireMTFAlignment = input.bool(true, "Require Multi-Timeframe Alignment", group="Signal Settings", tooltip="Signal only when 2+ timeframes agree")
// Timeframe Selection
tf1 = input.timeframe("5", "Timeframe 1", group="Timeframes")
tf2 = input.timeframe("15", "Timeframe 2", group="Timeframes")
tf3 = input.timeframe("30", "Timeframe 3", group="Timeframes")
tf4 = input.timeframe("60", "Timeframe 4", group="Timeframes")
// Visual Settings
bullColor = input.color(color.new(color.green, 70), "Bullish Projection Color", group="Colors")
bearColor = input.color(color.new(color.red, 70), "Bearish Projection Color", group="Colors")
// ============================================
// CONFIDENCE SCORE ENGINE
// ============================================
// Technical Indicators
rsi = ta.rsi(close, 14)
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
stoch = ta.stoch(close, high, low, 14)
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema200 = ta.ema(close, 200)
basis = ta.sma(close, 20)
dev = 2.0 * ta.stdev(close, 20)
upperBB = basis + dev
lowerBB = basis - dev
atr = ta.atr(14)
volumeMA = ta.sma(volume, 20)
volumeRatio = volume / volumeMA
// Calculate Confidence Score (0-100)
calcConfidenceScore() =>
score = 0.0
// MOMENTUM (25 points)
// RSI
if rsi < 25
score += 15
else if rsi < 35
score += 10
else if rsi > 75
score -= 15
else if rsi > 65
score -= 10
// Stochastic
if stoch < 20
score += 10
else if stoch > 80
score -= 10
// TREND (30 points)
// MACD
if ta.crossover(macdLine, signalLine)
score += 15
else if macdLine > signalLine and histLine > histLine[1]
score += 10
else if ta.crossunder(macdLine, signalLine)
score -= 15
else if macdLine < signalLine and histLine < histLine[1]
score -= 10
// EMA Alignment
if close > ema20 and ema20 > ema50 and ema50 > ema200
score += 15
else if close < ema20 and ema20 < ema50 and ema50 < ema200
score -= 15
// VOLATILITY (20 points)
// Bollinger Bands
bbPosition = (close - lowerBB) / (upperBB - lowerBB)
if bbPosition < 0.1
score += 20
else if bbPosition > 0.9
score -= 20
else if bbPosition < 0.3
score += 10
else if bbPosition > 0.7
score -= 10
// VOLUME (15 points)
if volumeRatio > 2.0 and close > open
score += 15
else if volumeRatio > 2.0 and close < open
score -= 15
else if volumeRatio > 1.5 and close > open
score += 10
else if volumeRatio > 1.5 and close < open
score -= 10
// PATTERN RECOGNITION (10 points)
bullishEngulfing = close[1] < open[1] and close > open and close > open[1] and open < close[1]
bearishEngulfing = close[1] > open[1] and close < open and close < open[1] and open > close[1]
hammer = (high - low) > 3 * math.abs(close - open) and (close - low) / (0.001 + high - low) > 0.6
shootingStar = (high - low) > 3 * math.abs(open - close) and (high - close) / (0.001 + high - low) > 0.6
if bullishEngulfing or hammer
score += 10
if bearishEngulfing or shootingStar
score -= 10
// Normalize to 0-100
normalizedScore = 50 + score
math.min(100, math.max(0, normalizedScore))
confidenceScore = calcConfidenceScore()
isBullish = confidenceScore >= 50
isBearish = confidenceScore < 50
// ============================================
// MULTI-TIMEFRAME ANALYSIS
// ============================================
getTFScore(tf) =>
request.security(syminfo.tickerid, tf, calcConfidenceScore())
tf1Score = getTFScore(tf1)
tf2Score = getTFScore(tf2)
tf3Score = getTFScore(tf3)
tf4Score = getTFScore(tf4)
// Determine TF Status
getStatus(score) =>
score >= 65 ? "BULL" : score <= 35 ? "BEAR" : "NEUT"
tf1Status = getStatus(tf1Score)
tf2Status = getStatus(tf2Score)
tf3Status = getStatus(tf3Score)
tf4Status = getStatus(tf4Score)
// Count alignment
bullishTFs = (tf1Status == "BULL" ? 1 : 0) + (tf2Status == "BULL" ? 1 : 0) + (tf3Status == "BULL" ? 1 : 0) + (tf4Status == "BULL" ? 1 : 0)
bearishTFs = (tf1Status == "BEAR" ? 1 : 0) + (tf2Status == "BEAR" ? 1 : 0) + (tf3Status == "BEAR" ? 1 : 0) + (tf4Status == "BEAR" ? 1 : 0)
hasBullishAlignment = bullishTFs >= 2
hasBearishAlignment = bearishTFs >= 2
// ============================================
// SIGNAL GENERATION
// ============================================
// Master signal conditions
validBuySignal = showBuySignals and confidenceScore >= confidenceThreshold and isBullish and (not requireMTFAlignment or hasBullishAlignment)
validSellSignal = showSellSignals and (100 - confidenceScore) >= confidenceThreshold and isBearish and (not requireMTFAlignment or hasBearishAlignment)
// ============================================
// FUTURE CANDLE PREDICTION
// ============================================
// Predict next candles based on ATR and momentum
predictFutureCandles() =>
var array<float> predictedHighs = array.new<float>()
var array<float> predictedLows = array.new<float>()
var array<float> predictedCloses = array.new<float>()
array.clear(predictedHighs)
array.clear(predictedLows)
array.clear(predictedCloses)
// Base prediction on current momentum and volatility
momentum = (confidenceScore - 50) / 50 // -1 to +1
currentPrice = close
for i = 1 to numProjectedCandles
// Each candle moves based on ATR and momentum
priceMove = atr * momentum * (1.0 - (i - 1) * 0.2) // Diminishing momentum
predictedClose = currentPrice + priceMove
predictedHigh = predictedClose + (atr * 0.5)
predictedLow = predictedClose - (atr * 0.5)
// Adjust for bullish/bearish
if isBullish
predictedHigh := math.max(predictedClose, predictedHigh)
predictedLow := math.min(currentPrice, predictedLow)
else
predictedHigh := math.max(currentPrice, predictedHigh)
predictedLow := math.min(predictedClose, predictedLow)
array.push(predictedHighs, predictedHigh)
array.push(predictedLows, predictedLow)
array.push(predictedCloses, predictedClose)
currentPrice := predictedClose
[predictedHighs, predictedLows, predictedCloses]
// ============================================
// VISUALIZATION - GHOST CANDLES
// ============================================
if showProjections and (validBuySignal or validSellSignal)
[predHighs, predLows, predCloses] = predictFutureCandles()
for i = 0 to array.size(predHighs) - 1
boxLeft = bar_index + i + 1
boxRight = bar_index + i + 2
boxTop = array.get(predHighs, i)
boxBottom = array.get(predLows, i)
boxColor = isBullish ? bullColor : bearColor
// Draw ghost candle box
box.new(boxLeft, boxTop, boxRight, boxBottom,
border_color=boxColor,
bgcolor=boxColor,
border_width=1,
border_style=line.style_dashed)
// Draw predicted close line
predClose = array.get(predCloses, i)
line.new(boxLeft, predClose, boxRight, predClose,
color=isBullish ? color.green : color.red,
width=2,
style=line.style_solid)
// ============================================
// SIGNAL MARKERS - MINIMAL
// ============================================
plotshape(validBuySignal, "Buy Signal", shape.labelup, location.belowbar,
color=color.new(color.green, 0), text="BUY", textcolor=color.white, size=size.small)
plotshape(validSellSignal, "Sell Signal", shape.labeldown, location.abovebar,
color=color.new(color.red, 0), text="SELL", textcolor=color.white, size=size.small)
// ============================================
// SIGNAL LABELS WITH DETAILS
// ============================================
if validBuySignal and barstate.islast
[predHighs, predLows, predCloses] = predictFutureCandles()
target1 = array.get(predHighs, 0)
target2 = array.size(predHighs) > 1 ? array.get(predHighs, 1) : target1
target3 = array.size(predHighs) > 2 ? array.get(predHighs, 2) : target2
stopLoss = close - (atr * 1.5)
labelText = "🚀 BUY SIGNAL\n"
labelText := labelText + "Confidence: " + str.tostring(confidenceScore, "#") + "%\n"
labelText := labelText + "T1: " + str.tostring(target1, "#.####") + "\n"
labelText := labelText + "T2: " + str.tostring(target2, "#.####") + "\n"
labelText := labelText + "T3: " + str.tostring(target3, "#.####") + "\n"
labelText := labelText + "SL: " + str.tostring(stopLoss, "#.####")
label.new(bar_index, low - atr * 2, labelText,
style=label.style_label_up,
color=color.new(color.green, 10),
textcolor=color.white,
size=size.normal)
if validSellSignal and barstate.islast
[predHighs, predLows, predCloses] = predictFutureCandles()
target1 = array.get(predLows, 0)
target2 = array.size(predLows) > 1 ? array.get(predLows, 1) : target1
target3 = array.size(predLows) > 2 ? array.get(predLows, 2) : target2
stopLoss = close + (atr * 1.5)
labelText = "⚠️ SELL SIGNAL\n"
labelText := labelText + "Confidence: " + str.tostring(100 - confidenceScore, "#") + "%\n"
labelText := labelText + "T1: " + str.tostring(target1, "#.####") + "\n"
labelText := labelText + "T2: " + str.tostring(target2, "#.####") + "\n"
labelText := labelText + "T3: " + str.tostring(target3, "#.####") + "\n"
labelText := labelText + "SL: " + str.tostring(stopLoss, "#.####")
label.new(bar_index, high + atr * 2, labelText,
style=label.style_label_down,
color=color.new(color.red, 10),
textcolor=color.white,
size=size.normal)
// ============================================
// MULTI-TIMEFRAME TABLE - COMPACT
// ============================================
if showMTFTable
var table mtfTable = table.new(position.top_right, 2, 5, border_width=1)
if barstate.islast
// Header
table.cell(mtfTable, 0, 0, "TF", bgcolor=color.new(color.gray, 20), text_color=color.white, text_size=size.small)
table.cell(mtfTable, 1, 0, "Status", bgcolor=color.new(color.gray, 20), text_color=color.white, text_size=size.small)
// TF1
color1 = tf1Status == "BULL" ? color.new(color.green, 60) : tf1Status == "BEAR" ? color.new(color.red, 60) : color.new(color.gray, 60)
table.cell(mtfTable, 0, 1, tf1, bgcolor=color.new(color.gray, 80), text_color=color.white, text_size=size.tiny)
table.cell(mtfTable, 1, 1, tf1Status, bgcolor=color1, text_color=color.white, text_size=size.tiny)
// TF2
color2 = tf2Status == "BULL" ? color.new(color.green, 60) : tf2Status == "BEAR" ? color.new(color.red, 60) : color.new(color.gray, 60)
table.cell(mtfTable, 0, 2, tf2, bgcolor=color.new(color.gray, 80), text_color=color.white, text_size=size.tiny)
table.cell(mtfTable, 1, 2, tf2Status, bgcolor=color2, text_color=color.white, text_size=size.tiny)
// TF3
color3 = tf3Status == "BULL" ? color.new(color.green, 60) : tf3Status == "BEAR" ? color.new(color.red, 60) : color.new(color.gray, 60)
table.cell(mtfTable, 0, 3, tf3, bgcolor=color.new(color.gray, 80), text_color=color.white, text_size=size.tiny)
table.cell(mtfTable, 1, 3, tf3Status, bgcolor=color3, text_color=color.white, text_size=size.tiny)
// TF4
color4 = tf4Status == "BULL" ? color.new(color.green, 60) : tf4Status == "BEAR" ? color.new(color.red, 60) : color.new(color.gray, 60)
table.cell(mtfTable, 0, 4, tf4, bgcolor=color.new(color.gray, 80), text_color=color.white, text_size=size.tiny)
table.cell(mtfTable, 1, 4, tf4Status, bgcolor=color4, text_color=color.white, text_size=size.tiny)
// ============================================
// PLOT EMAS - SUBTLE
// ============================================
plot(ema20, "EMA 20", color=color.new(color.blue, 80), linewidth=1)
plot(ema50, "EMA 50", color=color.new(color.orange, 80), linewidth=1)
plot(ema200, "EMA 200", color=color.new(color.red, 80), linewidth=1)
// ============================================
// ALERTS
// ============================================
alertcondition(validBuySignal, "Buy Signal", "🚀 BUY - {{ticker}} - Confidence: " + str.tostring(confidenceScore) + "%")
alertcondition(validSellSignal, "Sell Signal", "⚠️ SELL - {{ticker}} - Confidence: " + str.tostring(100-confidenceScore) + "%")
//@version=5
indicator("Future Candle Predictor - CLEAN", overlay=true, max_boxes_count=10, max_labels_count=5, max_lines_count=10)
// ============================================
// SIMPLE SETTINGS
// ============================================
minConfidence = input.int(75, "Minimum Confidence %", minval=60, maxval=95, tooltip="Only show signals above this")
showGhostCandles = input.bool(true, "Show Future Candles", tooltip="Show predicted candles ahead")
showTable = input.bool(true, "Show Timeframe Table")
// ============================================
// CORE INDICATORS
// ============================================
rsi = ta.rsi(close, 14)
[macd, signal, hist] = ta.macd(close, 12, 26, 9)
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
atr = ta.atr(14)
// Bollinger Bands
basis = ta.sma(close, 20)
dev = 2.0 * ta.stdev(close, 20)
upper = basis + dev
lower = basis - dev
// Volume
volAvg = ta.sma(volume, 20)
volRatio = volume / volAvg
// ============================================
// CONFIDENCE CALCULATION (0-100)
// ============================================
calcConfidence() =>
score = 50.0 // Start neutral
// RSI (±20)
if rsi < 30
score += 20
else if rsi > 70
score -= 20
else if rsi < 40
score += 10
else if rsi > 60
score -= 10
// MACD (±20)
if ta.crossover(macd, signal)
score += 20
else if ta.crossunder(macd, signal)
score -= 20
else if macd > signal and hist > hist[1]
score += 10
else if macd < signal and hist < hist[1]
score -= 10
// Trend (±20)
if close > ema20 and ema20 > ema50
score += 20
else if close < ema20 and ema20 < ema50
score -= 20
// Bollinger (±20)
if close < lower
score += 20
else if close > upper
score -= 20
// Volume (±20)
if volRatio > 1.5 and close > open
score += 20
else if volRatio > 1.5 and close < open
score -= 20
math.min(100, math.max(0, score))
confidence = calcConfidence()
// ============================================
// MULTI-TIMEFRAME CHECK
// ============================================
tf5 = request.security(syminfo.tickerid, "5", calcConfidence())
tf15 = request.security(syminfo.tickerid, "15", calcConfidence())
tf30 = request.security(syminfo.tickerid, "30", calcConfidence())
tf60 = request.security(syminfo.tickerid, "60", calcConfidence())
// Status
getStatus(c) => c >= 65 ? "🟢" : c <= 35 ? "🔴" : "⚪"
// ============================================
// SIGNAL LOGIC - ONLY CURRENT CANDLE
// ============================================
isBullish = confidence >= minConfidence
isBearish = (100 - confidence) >= minConfidence
// Count aligned timeframes
bullCount = (tf5 >= 65 ? 1 : 0) + (tf15 >= 65 ? 1 : 0) + (tf30 >= 65 ? 1 : 0) + (tf60 >= 65 ? 1 : 0)
bearCount = (tf5 <= 35 ? 1 : 0) + (tf15 <= 35 ? 1 : 0) + (tf30 <= 35 ? 1 : 0) + (tf60 <= 35 ? 1 : 0)
// Valid signal = high confidence + at least 2 TFs aligned
validBuy = isBullish and bullCount >= 2
validSell = isBearish and bearCount >= 2
// ============================================
// PREDICT FUTURE CANDLES - FORWARD ONLY
// ============================================
var box[] ghostBoxes = array.new<box>()
var line[] ghostLines = array.new<line>()
// Clear old ghosts
if array.size(ghostBoxes) > 0
for i = 0 to array.size(ghostBoxes) - 1
box.delete(array.get(ghostBoxes, i))
array.clear(ghostBoxes)
if array.size(ghostLines) > 0
for i = 0 to array.size(ghostLines) - 1
line.delete(array.get(ghostLines, i))
array.clear(ghostLines)
// Draw future candles ONLY on latest bar
if barstate.islast and showGhostCandles and (validBuy or validSell)
momentum = (confidence - 50) / 50 // -1 to +1
for i = 1 to 3
// Calculate future candle position
futureBar = bar_index + i
// Predict price movement
moveSize = atr * momentum * (1.2 - (i - 1) * 0.3)
predictedClose = close + moveSize
// Declare variables first
float candleHigh = na
float candleLow = na
// Candle high/low
if isBullish
candleHigh := predictedClose + (atr * 0.4)
candleLow := close + (moveSize * 0.3)
else
candleHigh := close + (moveSize * 0.3)
candleLow := predictedClose - (atr * 0.4)
// Draw ghost box
ghostBox = box.new(
left=futureBar,
top=candleHigh,
right=futureBar + 1,
bottom=candleLow,
border_color=isBullish ? color.new(color.green, 30) : color.new(color.red, 30),
bgcolor=isBullish ? color.new(color.green, 85) : color.new(color.red, 85),
border_width=1,
border_style=line.style_dashed
)
array.push(ghostBoxes, ghostBox)
// Draw close line
closeLine = line.new(
x1=futureBar,
y1=predictedClose,
x2=futureBar + 1,
y2=predictedClose,
color=isBullish ? color.new(color.green, 0) : color.new(color.red, 0),
width=2
)
array.push(ghostLines, closeLine)
// ============================================
// SIGNAL MARKER - ONLY LATEST BAR
// ============================================
plotshape(
barstate.islast and validBuy,
"Buy",
shape.triangleup,
location.belowbar,
color.new(color.green, 0),
text="BUY",
textcolor=color.white,
size=size.normal
)
plotshape(
barstate.islast and validSell,
"Sell",
shape.triangledown,
location.abovebar,
color.new(color.red, 0),
text="SELL",
textcolor=color.white,
size=size.normal
)
// ============================================
// INFO LABEL - ONLY LATEST BAR
// ============================================
if barstate.islast and (validBuy or validSell)
labelText = (validBuy ? "🚀 BUY" : "⚠️ SELL") + "\n"
labelText := labelText + "Confidence: " + str.tostring(validBuy ? confidence : 100 - confidence, "#") + "%\n"
labelText := labelText + "Aligned TFs: " + str.tostring(validBuy ? bullCount : bearCount) + "/4\n"
// Calculate targets from ghost candles
if showGhostCandles
momentum = (confidence - 50) / 50
t1 = close + (atr * momentum * 1.2)
t2 = close + (atr * momentum * 2.0)
t3 = close + (atr * momentum * 2.8)
sl = close - (atr * 1.5 * (validBuy ? 1 : -1))
labelText := labelText + "T1: " + str.tostring(t1, "#.####") + "\n"
labelText := labelText + "T2: " + str.tostring(t2, "#.####") + "\n"
labelText := labelText + "T3: " + str.tostring(t3, "#.####") + "\n"
labelText := labelText + "SL: " + str.tostring(sl, "#.####")
label.new(
x=bar_index,
y=validBuy ? low - atr : high + atr,
text=labelText,
style=validBuy ? label.style_label_up : label.style_label_down,
color=validBuy ? color.new(color.green, 20) : color.new(color.red, 20),
textcolor=color.white,
size=size.normal
)
// ============================================
// TIMEFRAME TABLE - COMPACT
// ============================================
if showTable
var table t = table.new(position.top_right, 3, 5, border_width=1)
if barstate.islast
// Header
table.cell(t, 0, 0, "TF", bgcolor=color.gray, text_color=color.white, text_size=size.small)
table.cell(t, 1, 0, "Conf", bgcolor=color.gray, text_color=color.white, text_size=size.small)
table.cell(t, 2, 0, "📊", bgcolor=color.gray, text_color=color.white, text_size=size.small)
// Current
table.cell(t, 0, 1, "Now", text_size=size.tiny)
table.cell(t, 1, 1, str.tostring(confidence, "#") + "%", text_size=size.tiny)
table.cell(t, 2, 1, getStatus(confidence), text_size=size.small)
// 5m
table.cell(t, 0, 2, "5m", text_size=size.tiny)
table.cell(t, 1, 2, str.tostring(tf5, "#") + "%", text_size=size.tiny)
table.cell(t, 2, 2, getStatus(tf5), text_size=size.small)
// 15m
table.cell(t, 0, 3, "15m", text_size=size.tiny)
table.cell(t, 1, 3, str.tostring(tf15, "#") + "%", text_size=size.tiny)
table.cell(t, 2, 3, getStatus(tf15), text_size=size.small)
// 30m
table.cell(t, 0, 4, "30m", text_size=size.tiny)
table.cell(t, 1, 4, str.tostring(tf30, "#") + "%", text_size=size.tiny)
table.cell(t, 2, 4, getStatus(tf30), text_size=size.small)
// ============================================
// PLOT EMAS - VERY SUBTLE
// ============================================
plot(ema20, "EMA20", color.new(color.blue, 90), 1)
plot(ema50, "EMA50", color.new(color.orange, 90), 1)
// ============================================
// BACKGROUND COLOR - SUBTLE HINT
// ============================================
bgColor = validBuy ? color.new(color.green, 97) : validSell ? color.new(color.red, 97) : na
bgcolor(bgColor, title="Signal Background")
// ============================================
// ALERTS
// ============================================
alertcondition(validBuy, "Buy Signal", "🚀 BUY {{ticker}} - Confidence: {{plot_0}}%")
alertcondition(validSell, "Sell Signal", "⚠️ SELL {{ticker}} - Confidence: {{plot_0}}%")
//@version=5
indicator("Pro Crypto Predictor - Clean & Accurate", overlay=true, max_boxes_count=10, max_labels_count=5)
// ============================================
// SETTINGS
// ============================================
minConfidence = input.int(70, "Minimum Confidence %", minval=60, maxval=90)
showPrediction = input.bool(true, "Show Future Candles")
showLevels = input.bool(true, "Show TP/SL Levels")
// ============================================
// CORE INDICATORS
// ============================================
// MACD
[macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9)
macdBullish = ta.crossover(macdLine, signalLine)
macdBearish = ta.crossunder(macdLine, signalLine)
// RSI
rsi = ta.rsi(close, 14)
rsiOversold = rsi < 30
rsiOverbought = rsi > 70
// EMAs
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)
ema50 = ta.ema(close, 50)
emaBullish = ema9 > ema21 and ema21 > ema50
emaBearish = ema9 < ema21 and ema21 < ema50
// Volume
volAvg = ta.sma(volume, 20)
volSpike = volume > volAvg * 1.5
// ATR for stop-loss/take-profit
atr = ta.atr(14)
// Bollinger Bands for support/resistance
basis = ta.sma(close, 20)
dev = 2 * ta.stdev(close, 20)
upper = basis + dev
lower = basis - dev
atSupport = close <= lower
atResistance = close >= upper
// ============================================
// SIGNAL LOGIC - MULTI-CONFIRMATION
// ============================================
// LONG SIGNAL (need 4+ confirmations)
longScore = 0
if macdBullish
longScore += 25
if rsiOversold
longScore += 25
if emaBullish or ta.crossover(ema9, ema21)
longScore += 25
if volSpike and close > open
longScore += 15
if atSupport
longScore += 10
validLong = longScore >= minConfidence and barstate.islast
// SHORT SIGNAL (need 4+ confirmations)
shortScore = 0
if macdBearish
shortScore += 25
if rsiOverbought
shortScore += 25
if emaBearish or ta.crossunder(ema9, ema21)
shortScore += 25
if volSpike and close < open
shortScore += 15
if atResistance
shortScore += 10
validShort = shortScore >= minConfidence and barstate.islast
// ============================================
// PRICE PROJECTION - LINEAR REGRESSION
// ============================================
var box[] predictionBoxes = array.new<box>()
var line[] predictionLines = array.new<line>()
var line[] tpLines = array.new<line>()
var line[] slLines = array.new<line>()
// Clear old drawings
if array.size(predictionBoxes) > 0
for i = 0 to array.size(predictionBoxes) - 1
box.delete(array.get(predictionBoxes, i))
array.clear(predictionBoxes)
if array.size(predictionLines) > 0
for i = 0 to array.size(predictionLines) - 1
line.delete(array.get(predictionLines, i))
array.clear(predictionLines)
if array.size(tpLines) > 0
for i = 0 to array.size(tpLines) - 1
line.delete(array.get(tpLines, i))
array.clear(tpLines)
if array.size(slLines) > 0
for i = 0 to array.size(slLines) - 1
line.delete(array.get(slLines, i))
array.clear(slLines)
// Draw prediction ONLY on current bar with signal
if barstate.islast and showPrediction and (validLong or validShort)
// Calculate momentum using linear regression
linreg = ta.linreg(close, 20, 0)
slope = (linreg - linreg[1])
// Adjust slope based on signal strength
momentum = slope * (validLong ? longScore : shortScore) / 50
// Project 3 candles forward
for i = 1 to 3
futureBar = bar_index + i
// Calculate predicted price
predictedMove = momentum * i * (1.2 - (i - 1) * 0.15)
predictedClose = close + predictedMove
// Calculate high/low based on ATR
predictedHigh = predictedClose + (atr * 0.5)
predictedLow = predictedClose - (atr * 0.5)
// Adjust for direction
if validLong
predictedHigh := predictedClose + (atr * 0.6)
predictedLow := close + (predictedMove * 0.4)
else
predictedHigh := close + (predictedMove * 0.4)
predictedLow := predictedClose - (atr * 0.6)
// Draw prediction box
boxColor = validLong ? color.new(color.green, 80) : color.new(color.red, 80)
borderColor = validLong ? color.new(color.green, 40) : color.new(color.red, 40)
predBox = box.new(
left=futureBar,
top=predictedHigh,
right=futureBar + 1,
bottom=predictedLow,
border_color=borderColor,
bgcolor=boxColor,
border_width=2,
border_style=line.style_dashed
)
array.push(predictionBoxes, predBox)
// Draw predicted close line
closeLine = line.new(
x1=futureBar,
y1=predictedClose,
x2=futureBar + 1,
y2=predictedClose,
color=validLong ? color.new(color.green, 20) : color.new(color.red, 20),
width=3
)
array.push(predictionLines, closeLine)
// ============================================
// TP/SL LEVELS
// ============================================
if barstate.islast and showLevels and (validLong or validShort)
if validLong
// Take Profit levels (1:2 risk-reward)
tp1 = close + (atr * 1.5)
tp2 = close + (atr * 3.0)
tp3 = close + (atr * 4.5)
sl = close - (atr * 1.5)
// Draw TP lines
tp1Line = line.new(bar_index, tp1, bar_index + 5, tp1, color=color.new(color.green, 30), width=1, style=line.style_dotted)
tp2Line = line.new(bar_index, tp2, bar_index + 5, tp2, color=color.new(color.green, 30), width=1, style=line.style_dotted)
tp3Line = line.new(bar_index, tp3, bar_index + 5, tp3, color=color.new(color.green, 30), width=1, style=line.style_dotted)
slLine = line.new(bar_index, sl, bar_index + 5, sl, color=color.new(color.red, 30), width=2, style=line.style_solid)
array.push(tpLines, tp1Line)
array.push(tpLines, tp2Line)
array.push(tpLines, tp3Line)
array.push(slLines, slLine)
else if validShort
// Take Profit levels
tp1 = close - (atr * 1.5)
tp2 = close - (atr * 3.0)
tp3 = close - (atr * 4.5)
sl = close + (atr * 1.5)
// Draw TP lines
tp1Line = line.new(bar_index, tp1, bar_index + 5, tp1, color=color.new(color.red, 30), width=1, style=line.style_dotted)
tp2Line = line.new(bar_index, tp2, bar_index + 5, tp2, color=color.new(color.red, 30), width=1, style=line.style_dotted)
tp3Line = line.new(bar_index, tp3, bar_index + 5, tp3, color=color.new(color.red, 30), width=1, style=line.style_dotted)
slLine = line.new(bar_index, sl, bar_index + 5, sl, color=color.new(color.green, 30), width=2, style=line.style_solid)
array.push(tpLines, tp1Line)
array.push(tpLines, tp2Line)
array.push(tpLines, tp3Line)
array.push(slLines, slLine)
// ============================================
// ENTRY SIGNALS - ONLY CURRENT CANDLE
// ============================================
plotshape(
validLong,
"LONG",
shape.triangleup,
location.belowbar,
color.new(color.green, 0),
text="LONG",
textcolor=color.white,
size=size.large
)
plotshape(
validShort,
"SHORT",
shape.triangledown,
location.abovebar,
color.new(color.red, 0),
text="SHORT",
textcolor=color.white,
size=size.large
)
// ============================================
// INFO LABEL
// ============================================
if barstate.islast and (validLong or validShort)
score = validLong ? longScore : shortScore
direction = validLong ? "🚀 LONG ENTRY" : "🔻 SHORT ENTRY"
// Calculate TP/SL
tp1 = validLong ? close + (atr * 1.5) : close - (atr * 1.5)
tp2 = validLong ? close + (atr * 3.0) : close - (atr * 3.0)
tp3 = validLong ? close + (atr * 4.5) : close - (atr * 4.5)
sl = validLong ? close - (atr * 1.5) : close + (atr * 1.5)
labelText = direction + "\n"
labelText := labelText + "Confidence: " + str.tostring(score, "#") + "%\n\n"
labelText := labelText + "Entry: " + str.tostring(close, "#.#####") + "\n"
labelText := labelText + "TP1: " + str.tostring(tp1, "#.#####") + "\n"
labelText := labelText + "TP2: " + str.tostring(tp2, "#.#####") + "\n"
labelText := labelText + "TP3: " + str.tostring(tp3, "#.#####") + "\n"
labelText := labelText + "SL: " + str.tostring(sl, "#.#####") + "\n\n"
labelText := labelText + "R:R = 1:2"
label.new(
x=bar_index,
y=validLong ? low - atr * 2 : high + atr * 2,
text=labelText,
style=validLong ? label.style_label_up : label.style_label_down,
color=validLong ? color.new(color.green, 10) : color.new(color.red, 10),
textcolor=color.white,
size=size.normal,
textalign=text.align_left
)
// ============================================
// PLOT EMAs - SUBTLE
// ============================================
plot(ema9, "EMA 9", color.new(color.blue, 85), 1)
plot(ema21, "EMA 21", color.new(color.orange, 85), 1)
plot(ema50, "EMA 50", color.new(color.red, 85), 1)
// ============================================
// BACKGROUND - SUBTLE HINT
// ============================================
bgColor = validLong ? color.new(color.green, 95) : validShort ? color.new(color.red, 95) : na
bgcolor(bgColor)
// ============================================
// ALERTS
// ============================================
alertcondition(validLong, "Long Entry", "🚀 LONG {{ticker}} @ {{close}} | Confidence: {{plot_0}}%")
alertcondition(validShort, "Short Entry", "🔻 SHORT {{ticker}} @ {{close}} | Confidence: {{plot_0}}%")
//@version=5
indicator("Smart Crypto Signals - V6", overlay=true, max_boxes_count=10, max_labels_count=5)
// ============================================
// SETTINGS
// ============================================
sensitivity = input.string("Medium", "Signal Sensitivity", options=["Low", "Medium", "High"])
showPrediction = input.bool(true, "Show Future Candles")
showLevels = input.bool(true, "Show TP/SL Levels")
// Convert sensitivity to threshold
minConfidence = sensitivity == "High" ? 55 : sensitivity == "Medium" ? 65 : 75
// ============================================
// CORE INDICATORS
// ============================================
// MACD
[macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9)
macdBullish = macdLine > signalLine and hist > hist[1]
macdBearish = macdLine < signalLine and hist < hist[1]
macdCrossUp = ta.crossover(macdLine, signalLine)
macdCrossDown = ta.crossunder(macdLine, signalLine)
// RSI
rsi = ta.rsi(close, 14)
rsiOversold = rsi < 35
rsiOverbought = rsi > 65
rsiRising = rsi > rsi[1] and rsi > rsi[2]
rsiFalling = rsi < rsi[1] and rsi < rsi[2]
// EMAs
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)
ema50 = ta.ema(close, 50)
emaBullish = ema9 > ema21
emaBearish = ema9 < ema21
emaCrossUp = ta.crossover(ema9, ema21)
emaCrossDown = ta.crossunder(ema9, ema21)
// Volume
volAvg = ta.sma(volume, 20)
volSpike = volume > volAvg * 1.3 // More sensitive
volRising = volume > volume[1]
// ATR
atr = ta.atr(14)
// Price momentum
priceUp = close > open and close > close[1]
priceDown = close < open and close < close[1]
strongBullCandle = (close - open) > atr * 0.3
strongBearCandle = (open - close) > atr * 0.3
// Trend strength
trend = ta.ema(close, 50)
bullTrend = close > trend
bearTrend = close < trend
// ============================================
// SIGNAL LOGIC - WEIGHTED SCORING
// ============================================
// LONG SIGNAL
longScore = 0
// MACD signals (30 points)
if macdCrossUp
longScore += 30
else if macdBullish
longScore += 20
// RSI signals (25 points)
if rsiOversold and rsiRising
longScore += 25
else if rsiRising
longScore += 15
// EMA signals (25 points)
if emaCrossUp
longScore += 25
else if emaBullish
longScore += 15
// Volume confirmation (15 points)
if volSpike and priceUp
longScore += 15
else if volRising and priceUp
longScore += 10
// Price action (10 points)
if strongBullCandle
longScore += 10
else if priceUp
longScore += 5
// Trend alignment (5 points)
if bullTrend
longScore += 5
validLong = longScore >= minConfidence and barstate.islast
// SHORT SIGNAL
shortScore = 0
// MACD signals (30 points)
if macdCrossDown
shortScore += 30
else if macdBearish
shortScore += 20
// RSI signals (25 points)
if rsiOverbought and rsiFalling
shortScore += 25
else if rsiFalling
shortScore += 15
// EMA signals (25 points)
if emaCrossDown
shortScore += 25
else if emaBearish
shortScore += 15
// Volume confirmation (15 points)
if volSpike and priceDown
shortScore += 15
else if volRising and priceDown
shortScore += 10
// Price action (10 points)
if strongBearCandle
shortScore += 10
else if priceDown
shortScore += 5
// Trend alignment (5 points)
if bearTrend
shortScore += 5
validShort = shortScore >= minConfidence and barstate.islast
// ============================================
// PRICE PROJECTION
// ============================================
var box[] predictionBoxes = array.new<box>()
var line[] predictionLines = array.new<line>()
var line[] tpLines = array.new<line>()
var line[] slLines = array.new<line>()
// Clear old drawings
if array.size(predictionBoxes) > 0
for i = 0 to array.size(predictionBoxes) - 1
box.delete(array.get(predictionBoxes, i))
array.clear(predictionBoxes)
if array.size(predictionLines) > 0
for i = 0 to array.size(predictionLines) - 1
line.delete(array.get(predictionLines, i))
array.clear(predictionLines)
if array.size(tpLines) > 0
for i = 0 to array.size(tpLines) - 1
line.delete(array.get(tpLines, i))
array.clear(tpLines)
if array.size(slLines) > 0
for i = 0 to array.size(slLines) - 1
line.delete(array.get(slLines, i))
array.clear(slLines)
// Draw prediction
if barstate.islast and showPrediction and (validLong or validShort)
// Calculate momentum
linreg = ta.linreg(close, 20, 0)
slope = (linreg - linreg[1])
// Adjust based on signal strength
score = validLong ? longScore : shortScore
momentum = slope * (score / 50) * 1.5
// Project 3 candles
for i = 1 to 3
futureBar = bar_index + i
// Predicted price
predictedMove = momentum * i * (1.3 - (i - 1) * 0.2)
predictedClose = close + predictedMove
// High/Low based on ATR
if validLong
predictedHigh = predictedClose + (atr * 0.7)
predictedLow = close + (predictedMove * 0.3)
else
predictedHigh = close + (predictedMove * 0.3)
predictedLow = predictedClose - (atr * 0.7)
// Draw box
boxColor = validLong ? color.new(color.green, 85) : color.new(color.red, 85)
borderColor = validLong ? color.new(color.green, 50) : color.new(color.red, 50)
predBox = box.new(
left=futureBar,
top=predictedHigh,
right=futureBar + 1,
bottom=predictedLow,
border_color=borderColor,
bgcolor=boxColor,
border_width=2,
border_style=line.style_dashed
)
array.push(predictionBoxes, predBox)
// Draw close line
closeLine = line.new(
x1=futureBar,
y1=predictedClose,
x2=futureBar + 1,
y2=predictedClose,
color=validLong ? color.new(color.green, 30) : color.new(color.red, 30),
width=3
)
array.push(predictionLines, closeLine)
// ============================================
// TP/SL LEVELS
// ============================================
if barstate.islast and showLevels and (validLong or validShort)
if validLong
tp1 = close + (atr * 1.5)
tp2 = close + (atr * 3.0)
tp3 = close + (atr * 4.5)
sl = close - (atr * 1.5)
tp1Line = line.new(bar_index, tp1, bar_index + 6, tp1, color=color.new(color.green, 40), width=1, style=line.style_dotted)
tp2Line = line.new(bar_index, tp2, bar_index + 6, tp2, color=color.new(color.green, 40), width=1, style=line.style_dotted)
tp3Line = line.new(bar_index, tp3, bar_index + 6, tp3, color=color.new(color.green, 40), width=1, style=line.style_dotted)
slLine = line.new(bar_index, sl, bar_index + 6, sl, color=color.new(color.red, 40), width=2, style=line.style_solid)
array.push(tpLines, tp1Line)
array.push(tpLines, tp2Line)
array.push(tpLines, tp3Line)
array.push(slLines, slLine)
else if validShort
tp1 = close - (atr * 1.5)
tp2 = close - (atr * 3.0)
tp3 = close - (atr * 4.5)
sl = close + (atr * 1.5)
tp1Line = line.new(bar_index, tp1, bar_index + 6, tp1, color=color.new(color.red, 40), width=1, style=line.style_dotted)
tp2Line = line.new(bar_index, tp2, bar_index + 6, tp2, color=color.new(color.red, 40), width=1, style=line.style_dotted)
tp3Line = line.new(bar_index, tp3, bar_index + 6, tp3, color=color.new(color.red, 40), width=1, style=line.style_dotted)
slLine = line.new(bar_index, sl, bar_index + 6, sl, color=color.new(color.green, 40), width=2, style=line.style_solid)
array.push(tpLines, tp1Line)
array.push(tpLines, tp2Line)
array.push(tpLines, tp3Line)
array.push(slLines, slLine)
// ============================================
// ENTRY SIGNALS
// ============================================
plotshape(
validLong,
"LONG",
shape.triangleup,
location.belowbar,
color.new(color.green, 0),
text="LONG",
textcolor=color.white,
size=size.large
)
plotshape(
validShort,
"SHORT",
shape.triangledown,
location.abovebar,
color.new(color.red, 0),
text="SHORT",
textcolor=color.white,
size=size.large
)
// ============================================
// INFO LABEL
// ============================================
if barstate.islast and (validLong or validShort)
score = validLong ? longScore : shortScore
direction = validLong ? "🚀 LONG ENTRY" : "🔻 SHORT ENTRY"
tp1 = validLong ? close + (atr * 1.5) : close - (atr * 1.5)
tp2 = validLong ? close + (atr * 3.0) : close - (atr * 3.0)
tp3 = validLong ? close + (atr * 4.5) : close - (atr * 4.5)
sl = validLong ? close - (atr * 1.5) : close + (atr * 1.5)
labelText = direction + "\n"
labelText := labelText + "Confidence: " + str.tostring(score, "#") + "%\n\n"
labelText := labelText + "Entry: " + str.tostring(close, "#.#####") + "\n"
labelText := labelText + "TP1: " + str.tostring(tp1, "#.#####") + "\n"
labelText := labelText + "TP2: " + str.tostring(tp2, "#.#####") + "\n"
labelText := labelText + "TP3: " + str.tostring(tp3, "#.#####") + "\n"
labelText := labelText + "SL: " + str.tostring(sl, "#.#####") + "\n\n"
labelText := labelText + "Risk:Reward = 1:2"
label.new(
x=bar_index,
y=validLong ? low - atr * 2 : high + atr * 2,
text=labelText,
style=validLong ? label.style_label_up : label.style_label_down,
color=validLong ? color.new(color.green, 10) : color.new(color.red, 10),
textcolor=color.white,
size=size.normal,
textalign=text.align_left
)
// ============================================
// PLOT EMAs
// ============================================
plot(ema9, "EMA 9", color.new(color.blue, 90), 1)
plot(ema21, "EMA 21", color.new(color.orange, 90), 1)
plot(ema50, "EMA 50", color.new(color.red, 90), 1)
// ============================================
// BACKGROUND
// ============================================
bgColor = validLong ? color.new(color.green, 96) : validShort ? color.new(color.red, 96) : na
bgcolor(bgColor)
// ============================================
// ALERTS
// ============================================
alertcondition(validLong, "Long Entry", "🚀 LONG {{ticker}} @ {{close}} | Confidence: " + str.tostring(longScore) + "%")
alertcondition(validShort, "Short Entry", "🔻 SHORT {{ticker}} @ {{close}} | Confidence: " + str.tostring(shortScore) + "%")
//@version=5
indicator("Live Market Scanner - V7", overlay=true, max_boxes_count=10, max_labels_count=20, max_lines_count=50)
// ============================================
// SETTINGS
// ============================================
sensitivity = input.string("Medium", "Signal Sensitivity", options=["Low", "Medium", "High"])
showPrediction = input.bool(true, "Show Future Candles")
showLevels = input.bool(true, "Show TP/SL Levels")
showDashboard = input.bool(true, "Show Live Dashboard")
// Convert sensitivity to threshold
minConfidence = sensitivity == "High" ? 55 : sensitivity == "Medium" ? 65 : 75
// ============================================
// CORE INDICATORS
// ============================================
// MACD
[macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9)
macdBullish = macdLine > signalLine and hist > hist[1]
macdBearish = macdLine < signalLine and hist < hist[1]
macdCrossUp = ta.crossover(macdLine, signalLine)
macdCrossDown = ta.crossunder(macdLine, signalLine)
// RSI
rsi = ta.rsi(close, 14)
rsiOversold = rsi < 35
rsiOverbought = rsi > 65
rsiRising = rsi > rsi[1] and rsi > rsi[2]
rsiFalling = rsi < rsi[1] and rsi < rsi[2]
// EMAs
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)
ema50 = ta.ema(close, 50)
emaBullish = ema9 > ema21
emaBearish = ema9 < ema21
emaCrossUp = ta.crossover(ema9, ema21)
emaCrossDown = ta.crossunder(ema9, ema21)
// Volume
volAvg = ta.sma(volume, 20)
volSpike = volume > volAvg * 1.3
volRising = volume > volume[1]
// ATR
atr = ta.atr(14)
// Price momentum
priceUp = close > open and close > close[1]
priceDown = close < open and close < close[1]
strongBullCandle = (close - open) > atr * 0.3
strongBearCandle = (open - close) > atr * 0.3
// Trend
trend = ta.ema(close, 50)
bullTrend = close > trend
bearTrend = close < trend
// Linear regression (calculate always)
linreg = ta.linreg(close, 20, 0)
slope = linreg - linreg[1]
// ============================================
// CONTINUOUS SIGNAL CALCULATION
// ============================================
// LONG SCORE (calculated every bar)
longScore = 0
if macdCrossUp
longScore += 30
else if macdBullish
longScore += 20
if rsiOversold and rsiRising
longScore += 25
else if rsiRising
longScore += 15
if emaCrossUp
longScore += 25
else if emaBullish
longScore += 15
if volSpike and priceUp
longScore += 15
else if volRising and priceUp
longScore += 10
if strongBullCandle
longScore += 10
else if priceUp
longScore += 5
if bullTrend
longScore += 5
// SHORT SCORE (calculated every bar)
shortScore = 0
if macdCrossDown
shortScore += 30
else if macdBearish
shortScore += 20
if rsiOverbought and rsiFalling
shortScore += 25
else if rsiFalling
shortScore += 15
if emaCrossDown
shortScore += 25
else if emaBearish
shortScore += 15
if volSpike and priceDown
shortScore += 15
else if volRising and priceDown
shortScore += 10
if strongBearCandle
shortScore += 10
else if priceDown
shortScore += 5
if bearTrend
shortScore += 5
// Determine current signal
validLong = longScore >= minConfidence
validShort = shortScore >= minConfidence
// Market status
marketStatus = validLong ? "LONG" : validShort ? "SHORT" : longScore > shortScore ? "WAIT (Bullish)" : shortScore > longScore ? "WAIT (Bearish)" : "NEUTRAL"
marketColor = validLong ? color.green : validShort ? color.red : longScore > shortScore ? color.new(color.green, 50) : shortScore > longScore ? color.new(color.red, 50) : color.gray
// ============================================
// LIVE DASHBOARD - TOP RIGHT
// ============================================
var table dashboard = table.new(position.top_right, 2, 12, border_width=2, border_color=color.new(color.gray, 50), bgcolor=color.new(color.black, 10))
if barstate.islast and showDashboard
// Header
table.cell(dashboard, 0, 0, "📊 LIVE MARKET SCANNER", text_color=color.white, bgcolor=color.new(color.blue, 30), text_size=size.normal)
table.merge_cells(dashboard, 0, 0, 1, 0)
// Current Signal
signalBg = validLong ? color.new(color.green, 70) : validShort ? color.new(color.red, 70) : color.new(color.gray, 80)
signalText = validLong ? "🚀 ENTER LONG NOW" : validShort ? "🔻 ENTER SHORT NOW" : "⏳ WAIT FOR SIGNAL"
table.cell(dashboard, 0, 1, signalText, text_color=color.white, bgcolor=signalBg, text_size=size.large)
table.merge_cells(dashboard, 0, 1, 1, 1)
// Confidence Scores
table.cell(dashboard, 0, 2, "Long Confidence", text_color=color.white, bgcolor=color.new(color.gray, 80), text_size=size.small)
longConfColor = longScore >= minConfidence ? color.new(color.green, 50) : color.new(color.gray, 70)
table.cell(dashboard, 1, 2, str.tostring(longScore) + "%", text_color=color.white, bgcolor=longConfColor, text_size=size.normal)
table.cell(dashboard, 0, 3, "Short Confidence", text_color=color.white, bgcolor=color.new(color.gray, 80), text_size=size.small)
shortConfColor = shortScore >= minConfidence ? color.new(color.red, 50) : color.new(color.gray, 70)
table.cell(dashboard, 1, 3, str.tostring(shortScore) + "%", text_color=color.white, bgcolor=shortConfColor, text_size=size.normal)
// Separator
table.cell(dashboard, 0, 4, "════════════════", text_color=color.gray, bgcolor=color.new(color.black, 10), text_size=size.small)
table.merge_cells(dashboard, 0, 4, 1, 4)
// Entry/Exit Levels
if validLong or validShort
table.cell(dashboard, 0, 5, "📍 ENTRY PRICE", text_color=color.white, bgcolor=color.new(color.blue, 70), text_size=size.small)
table.cell(dashboard, 1, 5, str.tostring(close, "#.#####"), text_color=color.yellow, bgcolor=color.new(color.blue, 70), text_size=size.normal)
// Calculate levels
tp1 = validLong ? close + (atr * 1.5) : close - (atr * 1.5)
tp2 = validLong ? close + (atr * 3.0) : close - (atr * 3.0)
tp3 = validLong ? close + (atr * 4.5) : close - (atr * 4.5)
sl = validLong ? close - (atr * 1.5) : close + (atr * 1.5)
table.cell(dashboard, 0, 6, "🎯 TP1 (1.5R)", text_color=color.white, bgcolor=color.new(color.green, 80), text_size=size.small)
table.cell(dashboard, 1, 6, str.tostring(tp1, "#.#####"), text_color=color.lime, bgcolor=color.new(color.green, 80), text_size=size.small)
table.cell(dashboard, 0, 7, "🎯 TP2 (3.0R)", text_color=color.white, bgcolor=color.new(color.green, 80), text_size=size.small)
table.cell(dashboard, 1, 7, str.tostring(tp2, "#.#####"), text_color=color.lime, bgcolor=color.new(color.green, 80), text_size=size.small)
table.cell(dashboard, 0, 8, "🎯 TP3 (4.5R)", text_color=color.white, bgcolor=color.new(color.green, 80), text_size=size.small)
table.cell(dashboard, 1, 8, str.tostring(tp3, "#.#####"), text_color=color.lime, bgcolor=color.new(color.green, 80), text_size=size.small)
table.cell(dashboard, 0, 9, "🛑 STOP LOSS", text_color=color.white, bgcolor=color.new(color.red, 70), text_size=size.small)
table.cell(dashboard, 1, 9, str.tostring(sl, "#.#####"), text_color=color.orange, bgcolor=color.new(color.red, 70), text_size=size.normal)
else
table.cell(dashboard, 0, 5, "⏳ Waiting for Setup...", text_color=color.gray, bgcolor=color.new(color.black, 10), text_size=size.small)
table.merge_cells(dashboard, 0, 5, 1, 5)
table.cell(dashboard, 0, 6, "Long Score: " + str.tostring(longScore) + "% (Need " + str.tostring(minConfidence) + "%)", text_color=color.white, bgcolor=color.new(color.gray, 80), text_size=size.small)
table.merge_cells(dashboard, 0, 6, 1, 6)
table.cell(dashboard, 0, 7, "Short Score: " + str.tostring(shortScore) + "% (Need " + str.tostring(minConfidence) + "%)", text_color=color.white, bgcolor=color.new(color.gray, 80), text_size=size.small)
table.merge_cells(dashboard, 0, 7, 1, 7)
// Separator
table.cell(dashboard, 0, 10, "════════════════", text_color=color.gray, bgcolor=color.new(color.black, 10), text_size=size.small)
table.merge_cells(dashboard, 0, 10, 1, 10)
// Market Indicators
rsiColor = rsi > 65 ? color.new(color.red, 50) : rsi < 35 ? color.new(color.green, 50) : color.new(color.gray, 70)
table.cell(dashboard, 0, 11, "RSI: " + str.tostring(rsi, "#.#"), text_color=color.white, bgcolor=rsiColor, text_size=size.small)
macdColor = macdBullish ? color.new(color.green, 70) : macdBearish ? color.new(color.red, 70) : color.new(color.gray, 80)
macdText = macdBullish ? "MACD: Bullish" : macdBearish ? "MACD: Bearish" : "MACD: Neutral"
table.cell(dashboard, 1, 11, macdText, text_color=color.white, bgcolor=macdColor, text_size=size.small)
// ============================================
// PRICE PROJECTION - FIXED SPACING
// ============================================
var box[] predictionBoxes = array.new<box>()
var line[] predictionLines = array.new<line>()
var line[] tpLines = array.new<line>()
var line[] slLines = array.new<line>()
// Clear old drawings
if array.size(predictionBoxes) > 0
for i = 0 to array.size(predictionBoxes) - 1
box.delete(array.get(predictionBoxes, i))
array.clear(predictionBoxes)
if array.size(predictionLines) > 0
for i = 0 to array.size(predictionLines) - 1
line.delete(array.get(predictionLines, i))
array.clear(predictionLines)
if array.size(tpLines) > 0
for i = 0 to array.size(tpLines) - 1
line.delete(array.get(tpLines, i))
array.clear(tpLines)
if array.size(slLines) > 0
for i = 0 to array.size(slLines) - 1
line.delete(array.get(slLines, i))
array.clear(slLines)
// Draw prediction with proper spacing
if barstate.islast and showPrediction and (validLong or validShort)
score = validLong ? longScore : shortScore
momentum = slope * (score / 50) * 1.5
// Draw 3 separate prediction boxes with spacing
for i = 1 to 3
// Each box starts 2 bars apart: bar 1-2, bar 3-4, bar 5-6
futureBarStart = bar_index + (i * 2) - 1
futureBarEnd = bar_index + (i * 2)
predictedMove = momentum * i * (1.3 - (i - 1) * 0.2)
predictedClose = close + predictedMove
// Calculate high/low for prediction box
float predHigh = na
float predLow = na
if validLong
predHigh := predictedClose + (atr * 0.7)
predLow := close + (predictedMove * 0.3)
else
predHigh := close + (predictedMove * 0.3)
predLow := predictedClose - (atr * 0.7)
boxColor = validLong ? color.new(color.green, 85) : color.new(color.red, 85)
borderColor = validLong ? color.new(color.green, 50) : color.new(color.red, 50)
predBox = box.new(
left=futureBarStart,
top=predHigh,
right=futureBarEnd,
bottom=predLow,
border_color=borderColor,
bgcolor=boxColor,
border_width=2,
border_style=line.style_dashed
)
array.push(predictionBoxes, predBox)
closeLine = line.new(
x1=futureBarStart,
y1=predictedClose,
x2=futureBarEnd,
y2=predictedClose,
color=validLong ? color.new(color.green, 30) : color.new(color.red, 30),
width=3
)
array.push(predictionLines, closeLine)
// ============================================
// TP/SL LEVELS ON CHART
// ============================================
if barstate.islast and showLevels and (validLong or validShort)
if validLong
tp1 = close + (atr * 1.5)
tp2 = close + (atr * 3.0)
tp3 = close + (atr * 4.5)
sl = close - (atr * 1.5)
tp1Line = line.new(bar_index, tp1, bar_index + 8, tp1, color=color.new(color.green, 40), width=1, style=line.style_dotted)
tp2Line = line.new(bar_index, tp2, bar_index + 8, tp2, color=color.new(color.green, 40), width=1, style=line.style_dotted)
tp3Line = line.new(bar_index, tp3, bar_index + 8, tp3, color=color.new(color.green, 40), width=1, style=line.style_dotted)
slLine = line.new(bar_index, sl, bar_index + 8, sl, color=color.new(color.red, 40), width=2, style=line.style_solid)
array.push(tpLines, tp1Line)
array.push(tpLines, tp2Line)
array.push(tpLines, tp3Line)
array.push(slLines, slLine)
else if validShort
tp1 = close - (atr * 1.5)
tp2 = close - (atr * 3.0)
tp3 = close - (atr * 4.5)
sl = close + (atr * 1.5)
tp1Line = line.new(bar_index, tp1, bar_index + 8, tp1, color=color.new(color.red, 40), width=1, style=line.style_dotted)
tp2Line = line.new(bar_index, tp2, bar_index + 8, tp2, color=color.new(color.red, 40), width=1, style=line.style_dotted)
tp3Line = line.new(bar_index, tp3, bar_index + 8, tp3, color=color.new(color.red, 40), width=1, style=line.style_dotted)
slLine = line.new(bar_index, sl, bar_index + 8, sl, color=color.new(color.green, 40), width=2, style=line.style_solid)
array.push(tpLines, tp1Line)
array.push(tpLines, tp2Line)
array.push(tpLines, tp3Line)
array.push(slLines, slLine)
// ============================================
// ENTRY SIGNALS ON CHART
// ============================================
plotshape(
validLong and barstate.islast,
"LONG",
shape.triangleup,
location.belowbar,
color.new(color.green, 0),
text="LONG",
textcolor=color.white,
size=size.huge
)
plotshape(
validShort and barstate.islast,
"SHORT",
shape.triangledown,
location.abovebar,
color.new(color.red, 0),
text="SHORT",
textcolor=color.white,
size=size.huge
)
// ============================================
// PLOT EMAs
// ============================================
plot(ema9, "EMA 9", color.new(color.blue, 90), 1)
plot(ema21, "EMA 21", color.new(color.orange, 90), 1)
plot(ema50, "EMA 50", color.new(color.red, 90), 1)
// ============================================
// BACKGROUND
// ============================================
bgColor = validLong ? color.new(color.green, 96) : validShort ? color.new(color.red, 96) : na
bgcolor(bgColor)
// ============================================
// ALERTS
// ============================================
alertcondition(validLong, "Long Entry", "LONG Entry Signal")
alertcondition(validShort, "Short Entry", "SHORT Entry Signal")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment