OPEN-SOURCE SCRIPT
HalfTrend Strategy Advanced

This script is part of our educational blog series “How to Convert a TradingView Indicator into an Algo Strategy”, where we enhance a basic HalfTrend strategy using market-aware filters and optimization logic.
📝 Read the full blog series here →
📈 Basic version available here →
🔍 What This Strategy Does
This advanced strategy builds on the original HalfTrend indicator by:
✅ Filter Logic (Optimized using Genetic Algorithms)
These filters were selected through computer algorithms to maximize performance on the NIFTY 15M chart, producing significantly improved stats:
⚠️ Note
This is a research and educational strategy showcasing how filters can enhance trend-following systems. Not intended for live trading without proper validation and robustness checks.
👉 Follow us for future strategy releases and continue the series in Part 3, where we test strategy robustness and deploy a live strategy portfolio.
📝 Read the full blog series here →
📈 Basic version available here →
🔍 What This Strategy Does
This advanced strategy builds on the original HalfTrend indicator by:
- Detecting trend reversals based on price structure
- Filtering entries using a combination of custom RSI and ROC-based conditions
✅ Filter Logic (Optimized using Genetic Algorithms)
- ROC + RSI behavior for directional confirmation
- RSI on high and close price for multi-angle strength filtering
- Built-in logic to dynamically close losing trades when core signal invalidates the setup
These filters were selected through computer algorithms to maximize performance on the NIFTY 15M chart, producing significantly improved stats:
- Profit Factor > 2
- Win Rate ~ 50%
- Sharpe Ratio > 0.35
⚠️ Note
This is a research and educational strategy showcasing how filters can enhance trend-following systems. Not intended for live trading without proper validation and robustness checks.
👉 Follow us for future strategy releases and continue the series in Part 3, where we test strategy robustness and deploy a live strategy portfolio.
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.