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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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 TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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 TradingView. Read more in the Terms of Use.