PulseHub
OPEN-SOURCE SCRIPT

APB Pair Trade Direct - Cointegration

280
🔰 APB PRO - Cointegration Pair Trading (Fool-Proof)
📌 What is this?
APB stands for "A Prueba de Bolu2" (Spanish for "Fool-Proof" - with all due respect 😉).

This is a professional Pair Trading indicator that does all the heavy lifting for you. It automatically calculates cointegration, correlation, and provides crystal clear BUY and SELL signals directly on your chart.

You don't need to be a mathematician, a statistician, or a coding expert. Just look at the arrows and the background color. The indicator does the rest.

🎯 How Does It Work?
The indicator analyzes the spread of the pair you have open on your chart (e.g., BTC/ETH, SOL/ETH, LINK/BTC, etc.) and calculates:

Historical Mean → Where the pair should normally trade.

Standard Deviations → When the pair is extremely cheap or expensive.

Real-time Cointegration → Whether the pair is behaving stably or erratically.

When the spread moves too far from its mean, the indicator alerts you with a clear arrow signal.

🟢🔴 SIGNALS (Fool-Proof)
Signal Interpretation Recommended Action
🟢 GREEN arrow pointing UP with "BUY" The pair is at the FLOOR (cheap). Spread hit the lower limit. BUY the pair (expecting mean reversion up)
🔴 RED arrow pointing DOWN with "SELL" The pair is at the CEILING (expensive). Spread hit the upper limit. SELL the pair (expecting mean reversion down)
🟩 GREEN background ✅ Cointegration ACTIVE. The pair is stable. SAFE TO TRADE (signals are valid)
🟥 RED background ❌ Cointegration INACTIVE. The pair is erratic or trending. BETTER TO WAIT (indicator will NOT give signals)
⚙️ PARAMETERS (Only 2 to Adjust)
Parameter Recommended Value What It Does
Analysis Period 100 Number of candles for mean and deviation calculation. Higher = more stable but slower.
APB Sensitivity 2.0 Controls signal frequency.
• 1.5 = More signals (aggressive)
• 2.0 = Balanced (recommended)
• 2.5-3.0 = Fewer signals (conservative)
Advanced Filters (Optional)
Parameter Recommended Value What It Does
🔒 Activate Cointegration Filter true Filters signals when the pair is unstable. Keep this ON.
📐 Slope Period 20 How many candles to measure stability. (Default is fine)
📏 Slope Threshold 0.05 Lower = more strict. 0.03 is very strict. (Default is fine)
📊 CONTROL PANEL (Real-Time Info)
The panel in the top-right corner shows you everything you need at a glance:

Data What It Means
Deviation % How far the pair has moved from its mean (in percentage).
🔴 Ceiling (SELL) Upper limit. If spread reaches this → SELL signal.
🟢 Floor (BUY) Lower limit. If spread reaches this → BUY signal.
🔒 Cointegration ✅ ACTIVE = good to trade.
❌ INACTIVE = better to wait.
📐 Slope Close to 0 = stable pair. Far from 0 = trending (cointegration broken).
🚀 Which Pairs Work Best?
This indicator is designed for cryptocurrency pairs with high liquidity and historical correlation:

Pair Recommendation
BTC/ETH ⭐⭐⭐⭐⭐ (Most stable and reliable)
ETH/BTC ⭐⭐⭐⭐⭐ (The inverse, equally good)
SOL/ETH ⭐⭐⭐⭐ (Good, but more volatile)
LINK/BTC ⭐⭐⭐⭐ (Works well in cycles)
MATIC/ETH ⭐⭐⭐ (Adjust sensitivity lower)
BNB/ETH ⭐⭐⭐ (Similar to SOL/ETH)
AVAX/ETH ⭐⭐⭐ (Adjust sensitivity)
⚠️ Does NOT work well on:

Low-liquidity pairs

Highly volatile memecoins (DOGE, SHIB, PEPE)

Pairs with extreme trend movements

🔔 Automatic Alerts
The indicator includes native alerts so you never miss an opportunity:

Alert Message
🟢 APB BUY SIGNAL "🟢 APB BUY: Pair is cheap with active cointegration. Go LONG!"
🔴 APB SELL SIGNAL "🔴 APB SELL: Pair is expensive with active cointegration. Go SHORT!"
To activate: In PulseWire, go to "Alerts" → "Create Alert" → Select the condition → Done.

💡 Pro Tips for Best Results
1. Only Trade When Background is GREEN
If the background is red, the indicator won't give signals. This is a protection mechanism. Don't force trades when cointegration is broken.

2. Don't Trade Every Signal
Wait for the arrow to appear on a green background with decent volume. The best setups are when the spread touches the limit and the market is calm.

3. Use the Right Timeframe
Timeframe Best For
1h - 4h Swing trading (days to weeks)
15m - 30m Day trading (hours)
1m - 5m ❌ Too much noise. Avoid.
4. Adjust Sensitivity Per Pair
Pair Recommended Sensitivity
BTC/ETH 2.0 (perfect)
SOL/ETH 2.2 - 2.5 (avoid false signals)
LINK/BTC 2.0 - 2.2
Volatile pairs 2.5+ (more selective)
5. Watch the Slope
If you see the slope spiking (far from 0), it means the pair is in a strong trend and cointegration is breaking. Wait for it to stabilize before trading.

🧠 How Is It Calculated? (For the Curious)
Normalization → Price is divided by its moving average to put it on a percentage scale.

Spread → The percentage deviation of the price from its mean.

Limits → Mean ± (Sensitivity × Standard Deviation).

Cointegration → Measured by the spread's slope over a short period. If the slope is close to 0, the pair is stable.

Signals → Triggered when the spread crosses the limits AND cointegration is active.

📜 Technical Details
Aspect Details
Version 2.0 (Direct Pair)
Pine Script v6 (Compatible with PulseWire)
Author APB Community
Recommended Timeframes 1h, 4h, 1D
Recommended Cryptos BTC, ETH, SOL, LINK, MATIC, BNB, AVAX
Overlay Yes (shows directly on price chart)
❓ Frequently Asked Questions
Q: Can I use this on stocks or forex?
A: Technically yes, but it's optimized for cryptocurrencies due to their higher volatility and correlation patterns.

Q: Why are there no signals even when the spread hits the limits?
A: Because the cointegration filter is active and the pair isn't stable. This is a safety feature to protect you from false signals.

Q: What does "Slope" mean in the panel?
A: It measures the speed of the spread movement. Close to 0 = stable (cointegrated). Far from 0 = trending (cointegration broken).

Q: Can I disable the cointegration filter?
A: Yes, set "Activate Cointegration Filter" to false in the advanced parameters. But I don't recommend it unless you're an experienced trader.

Q: Why is the background red/ green?
A:

🟩 GREEN = Cointegration ACTIVE → Valid signals.

🟥 RED = Cointegration INACTIVE → No signals (wait).

⭐ Rating
Aspect Score
Ease of Use ⭐⭐⭐⭐⭐ (Fool-Proof)
Accuracy on BTC/ETH ⭐⭐⭐⭐⭐
Accuracy on Altcoins ⭐⭐⭐⭐ (Adjust sensitivity)
Signal Clarity ⭐⭐⭐⭐⭐
Beginner Friendly ⭐⭐⭐⭐⭐
Professional Quality ⭐⭐⭐⭐
⚠️ DISCLAIMER (Important!)
This indicator is a TOOL for analysis, NOT a guarantee of profits.

Pair Trading reduces risk but does not eliminate it.

Cryptocurrencies are extremely volatile and can break cointegration during extreme events (news, hacks, regulations, black swan events).

Always use proper risk management:

Set stop-losses

Use appropriate position sizing

Never risk more than you can afford to lose

Test the indicator in PAPER TRADING before using real money.

Past performance does not guarantee future results. Trade responsibly.

🙏 Acknowledgments
Thank you for using APB PRO - Cointegration Pair Trading!

Remember the golden rule: The best trades are the ones you DON'T take when the market isn't clear. The red background is your friend - it tells you to wait.

May the spread always return to its mean! 🚀📊

💬 Feedback & Community
If you find this indicator useful:

⭐ Leave a like on the publication

💬 Share your experience in the comments

🔄 Repost to help other traders

Questions or suggestions? Drop a comment and I'll get back to you!

🏷️ Tags
Pair Trading Cointegration Spread Mean Reversion BTC/ETH Cryptocurrencies Trading Signals APB Fool-Proof Statistical Arbitrage Crypto Trading Swing Trading Day Trading Pine Script v6 Algorithmic Trading

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by PulseWire. Read more in the Terms of Use.