OPEN-SOURCE SCRIPT

Anomaly Counter-Trend Strategy

212
A mean-reversion style strategy that automatically spots unusually large price moves over a configurable lookback period and takes the opposite side, with full risk-management, commission and slippage modeling—built in Pine Script® v6.

🔎 Overview
ACTS monitors the percent-change over the past N minutes and, when that move exceeds your chosen threshold, enters a counter-trend position (short on a strong rise; long on a sharp fall). It’s ideal for markets that often “overshoot” and snap back, and can be applied on any symbol or timeframe.

⚙️ Key Features
Anomaly Detection: Detect abnormal price swings based on a user-defined % change over a lookback period.

Counter-Trend Entries: Auto-enter short on rise anomalies, long on fall anomalies (with seamless flat↔reverse transitions).

Risk Management: Configurable stop-loss and take-profit in ticks per trade.

Realistic Modeling: Simulates commissions (0.05 % default), slippage (2 ticks), and percent-of-equity sizing.

Immediate Bar-Close Execution: Orders processed on bar close for faster fills.

Visual Aids: Optional on-chart BUY/SELL triangles and background highlights during anomaly periods.

⚙️ Inputs
Input Default Description
Percentage Threshold (%) 2.00 Min % move over lookback to trigger an anomaly.
Lookback Period (Minutes) 15 Number of minutes over which to measure change.
Stop Loss (Ticks) 100 Distance from entry for stop-loss exit.
Take Profit (Ticks) 200 Distance from entry for take-profit exit.
Plot Trade Signal Shapes (on/off) true Show BUY/SELL triangles on chart.
Highlight Anomaly Background true Shade background during anomaly bars.

📊 How to Use
Add to Chart: Apply the script to any ticker & timeframe.

Tune: Adjust your percentage threshold and lookback to match each instrument’s volatility.

Review Backtest: Check built-in strategy performance (drawdown, Sharpe, etc.) under the Strategy Tester tab.

Go Live: Once optimized, link to alerts or your trade execution system.

⚠️ Disclaimer
This script is provided “as-is” for educational purposes and backtesting only. Past performance does not guarantee future results. Always backtest thoroughly, manage your own risk, and consider market conditions before live trading.

Enjoy experimenting—and may your counter-trend entries catch the next big snapback!

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.