OPEN-SOURCE SCRIPT
Trend Score with Dynamic Stop Loss HTF

How the Trend Score System Works
This indicator uses a Trend Score (TS) to measure price momentum over time. It tracks whether price is breaking higher or lower, then sums these moves into a cumulative score to define trend direction.
⸻
1. Trend Score (+1 / -1 Mechanism)
On each new bar:
• +1 point: if the current bar breaks the previous bar’s high.
• −1 point: if the current bar breaks the previous bar’s low.
• If both happen in the same bar, they cancel each other out.
• If neither happens, the score does not change.
This creates a simple running measure of bullish vs bearish pressure.
⸻
2. Cumulative Trend Score
The Trend Score is cumulative, meaning each new +1 or -1 is added to the total score, building a continuous count.
• Rising scores = buyers are consistently pushing price to higher highs.
• Falling scores = sellers are consistently pushing price to lower lows.
This smooths out noise and helps identify persistent momentum rather than single-bar spikes.
⸻
3. Trend Flip Trigger (default = 3)
A trend flip occurs when the cumulative Trend Score changes by 3 points (default setting) in the opposite direction of the current trend.
• Bullish Flip:
• Cumulative TS rises 3 points from its most recent low pivot.
• Marks a potential start of a new uptrend.
• A bullish stop-loss (SL) is set at the most recent swing low.
• Bearish Flip:
• Cumulative TS falls 3 points from its most recent high pivot.
• Marks a potential start of a new downtrend.
• A bearish SL is set at the most recent swing high.
Example:
• TS is at -2, then climbs to +1.
• That’s a +3 change, triggering a bullish flip.
⸻
4. Visual Summary
• Green background: Active bullish trend.
• Red background: Active bearish trend.
• ▲ Triangle Up: A bullish flip occurred this bar.
• Stop Loss Line: Shows the structural low used for risk management.
⸻
Why This Matters
The Trend Score measures trend pressure simply and objectively:
• +1 / -1 mechanics track real price behavior (breakouts of highs and lows).
• Cumulative changes of 3 points act like a momentum filter, ignoring small reversals.
• This helps you see true regime shifts on higher timeframes, which is especially useful for swing trades and investing decisions.
⸻
Key Takeaways
• Only flips after meaningful swings: prevents overreacting to single-bar noise.
• SL shows invalidation point: helps you know where a trend thesis fails.
• Works best on Daily or Weekly charts: for smoother, more reliable signals. Using Trend Score for Long-Term Investing
This indicator is designed to support decision-making for higher timeframe investing, such as swing trades, multi-month positions, or even multi-year holds.
It helps you:
• Identify major bullish regimes.
• Decide when to add to winning positions (DCA up).
• Know when to pause buying or consider trimming during weak periods.
• Stay disciplined while holding long-term winners.
Important Note:
These are suggestions for context. Always combine them with your own analysis, portfolio allocation rules, and risk tolerance.
⸻
1. Start With the Higher Timeframe
• Use Weekly charts for a broad investing view.
• Use Daily charts only for fine-tuning entry points or deciding when to add.
• A Bullish Flip on Weekly suggests the market may be entering a major uptrend.
• If Weekly is bullish and Daily also turns bullish, it’s extra confirmation of strength.
⸻
2. Building a Position with DCA
Goal: Grow your position gradually during strong bullish regimes while staying aware of risk.
A. Initial Buy
• Start with a small initial allocation when a Bullish Flip appears on Weekly or Daily.
• This is just a starter position to get exposure while the new trend develops.
B. Adding Through Strength (DCA Up)
• Consider adding during pullbacks, as long as price stays above the active SL line.
• Each add should be smaller or equal to your first buy.
• Spread out adds over time or price levels, instead of going all-in at once.
C. Pause Buying When:
• Price approaches or touches the SL level (trend invalidation).
• A Bearish Flip appears on Weekly or Daily — this signals potential weakness.
• Your total position size reaches your maximum allocation limit for that asset.
⸻
3. Holding Winners
When a position grows in profit:
• Stay in the trend as long as the Weekly regime remains bullish.
• The indicator’s green background acts as a reminder to hold, not panic sell.
• Use the SL bubble to monitor where the trend could potentially break.
• Avoid selling just because of small pullbacks — focus on big-picture trend health.
⸻
4. Taking Partial Profits
While this tool is designed to help hold long-term winners, there may be times to lighten risk:
• After large, rapid moves far above the SL, consider trimming a small portion of your position.
• When MFE (Maximum Favorable Excursion) in the table reaches unusually high levels, it may signal overextension.
• If the Weekly chart turns Neutral or Bearish, you can gradually reduce exposure while waiting for the next Bullish Flip.
⸻
5. Using the Stop Loss Line for Awareness
The Dynamic SL line represents a structural level that, if broken, may suggest the bullish trend is weakening.
How to think about it:
• Above SL: Market remains structurally healthy — continue holding or adding gradually.
• Close to SL: Pause adds. Be cautious and consider tightening your risk.
• Below SL: Treat this as a potential signal to reassess your position, especially if the break is confirmed on Weekly.
The SL is not a hard stop — it’s a visual guide to help you manage expectations.
⸻
6. Example Use Case
Imagine you are investing in a growth stock:
• Weekly Bullish Flip: You open a small starter position.
• Price pulls back slightly but stays above SL: You add a second, smaller tranche.
• Trend continues up for months: You hold and stop adding once your desired allocation is reached.
• Price doubles: You trim 10–20% to lock some profits, but continue holding the majority.
• Price later dips below SL: You slow down, reassess, and decide whether to reduce exposure.
This keeps you:
• Participating in major uptrends.
• Avoiding overcommitment during weak phases.
• Making adjustments gradually, not emotionally.
⸻
7. Suggested Workflow
1. Check Weekly chart → is it Bullish?
2. If yes, review Daily chart to fine-tune entry or adds.
3. Build exposure gradually while Weekly remains bullish.
4. Watch SL bubbles as awareness points for risk management.
5. Use partial trims during big rallies, but avoid exiting entirely too soon.
6. Reassess if Weekly turns Neutral or Bearish.
⸻
Key Takeaways
• Use this as a compass, not a command system.
• Weekly flips = big picture direction.
• Daily flips = timing and precision.
• Add gradually (DCA) while above SL, pause near SL, reassess below SL.
• Hold winners as long as Weekly remains bullish.
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。