OPEN-SOURCE SCRIPT
Butterworth LPF Flip + AutoTune (PF)

Butterworth LPF Flip + AutoTune (PF)
This strategy trades price trend flips using two Butterworth low-pass filters (a FAST filter and a SLOW filter). A trade is taken when the FAST filter crosses the SLOW filter. Optionally, the script can auto-tune the filter lengths by simulating many Fast/Slow combinations and selecting the pair with the best Profit Factor (PF).
What the Script Does
- Computes two 2‑pole Butterworth low‑pass filters on price.
- Enters LONG when FAST crosses above SLOW.
- Enters SHORT when FAST crosses below SLOW.
- Optionally simulates many Fast/Slow length combinations internally.
- Chooses the Fast/Slow pair with the highest Profit Factor.
- Trades only the selected best pair.
Manual Mode (Default)
1. Leave Auto‑Tune OFF.
2. Set:
- FAST cutoff period (bars)
- SLOW cutoff period (bars)
3. The strategy will trade using only these values.
Use this mode for normal trading or live deployment.
Auto‑Tune Mode
1. Enable Auto‑Tune.
2. Define Fast and Slow ranges:
- FAST min / max / step
- SLOW min / max / step
3. The script simulates ALL Fast × Slow combinations bar‑by‑bar.
4. Each combination tracks:
- Gross Profit
- Gross Loss
- Closed trades
- Profit Factor (PF = GP / GL)
5. At the end of the chart, the best PF pair is selected and used for trading.
Interpreting the End Box
The status label at the end of the chart reports:
- Whether Auto‑Tune is enabled
- Number of candidate pairs tested
- Best FAST period
- Best SLOW period
- Profit Factor of the best pair
- Win Rate (wins ÷ closed trades)
If PF is near 1.0 or trades are very low, expand the range or length of the test.
Best Practices
- Use Auto‑Tune ONLY for research and optimization.
- After finding good parameters, disable Auto‑Tune and trade manually.
- Keep Fast < Slow (logical separation).
- Longer charts produce more reliable PF results.
- Avoid very small step sizes (performance + noise).
Known Limitations
- Pine Script runs bar‑by‑bar; tuning is approximate, not vectorized.
- Large grids increase execution time.
- Results are historical and NOT predictive.
- Not suitable for live auto‑optimization.
Summary
This script is best viewed as a *research tool first, strategy second*. Use it to discover stable Fast/Slow regimes, then lock them in for simple, repeatable trading.
This strategy trades price trend flips using two Butterworth low-pass filters (a FAST filter and a SLOW filter). A trade is taken when the FAST filter crosses the SLOW filter. Optionally, the script can auto-tune the filter lengths by simulating many Fast/Slow combinations and selecting the pair with the best Profit Factor (PF).
What the Script Does
- Computes two 2‑pole Butterworth low‑pass filters on price.
- Enters LONG when FAST crosses above SLOW.
- Enters SHORT when FAST crosses below SLOW.
- Optionally simulates many Fast/Slow length combinations internally.
- Chooses the Fast/Slow pair with the highest Profit Factor.
- Trades only the selected best pair.
Manual Mode (Default)
1. Leave Auto‑Tune OFF.
2. Set:
- FAST cutoff period (bars)
- SLOW cutoff period (bars)
3. The strategy will trade using only these values.
Use this mode for normal trading or live deployment.
Auto‑Tune Mode
1. Enable Auto‑Tune.
2. Define Fast and Slow ranges:
- FAST min / max / step
- SLOW min / max / step
3. The script simulates ALL Fast × Slow combinations bar‑by‑bar.
4. Each combination tracks:
- Gross Profit
- Gross Loss
- Closed trades
- Profit Factor (PF = GP / GL)
5. At the end of the chart, the best PF pair is selected and used for trading.
Interpreting the End Box
The status label at the end of the chart reports:
- Whether Auto‑Tune is enabled
- Number of candidate pairs tested
- Best FAST period
- Best SLOW period
- Profit Factor of the best pair
- Win Rate (wins ÷ closed trades)
If PF is near 1.0 or trades are very low, expand the range or length of the test.
Best Practices
- Use Auto‑Tune ONLY for research and optimization.
- After finding good parameters, disable Auto‑Tune and trade manually.
- Keep Fast < Slow (logical separation).
- Longer charts produce more reliable PF results.
- Avoid very small step sizes (performance + noise).
Known Limitations
- Pine Script runs bar‑by‑bar; tuning is approximate, not vectorized.
- Large grids increase execution time.
- Results are historical and NOT predictive.
- Not suitable for live auto‑optimization.
Summary
This script is best viewed as a *research tool first, strategy second*. Use it to discover stable Fast/Slow regimes, then lock them in for simple, repeatable trading.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.