PROTECTED SOURCE SCRIPT
Telah dikemas kini HTF/CTF High/Low Mitigation with Signals

HTF/CTF High/Low Mitigation with Signals Indicator
Overview
HTF/CTF High/Low Mitigation with Signals (shortened as "H/L Signals+") is an advanced overlay indicator for TradingView, designed to identify and visualize higher timeframe (HTF) and current timeframe (CTF) swing highs/lows, track their mitigation, and generate filtered buy/sell signals using an EMA ribbon trend filter. It incorporates automated trade simulation with risk/reward (RR) visualization, position sizing based on user-defined risk, and a statistics table for performance evaluation. This tool is ideal for multi-timeframe traders focusing on swing trading, breakout strategies, or trend reversals across assets like forex, futures, metals (e.g., XAU/USD, XAG/USD), stocks, or cryptocurrencies.
The "meshup" (mashup) integrates several complementary elements: Multi-timeframe swing level detection (HTF for broader structure, CTF for finer details) with mitigation logic ensures signals align with market structure breaks; an EMA ribbon provides a dynamic trend bias to filter counter-trend trades; risk management automates position sizing and RR calculations for disciplined trading; and built-in backtesting stats offer quick insights into hypothetical performance. This combination reduces noise from isolated indicators—e.g., raw swings can be choppy, EMAs alone lag structure, and manual RR is error-prone—creating a cohesive system for spotting high-probability setups where structure, trend, and risk align. By meshing these, it aims to enhance decision-making in trending or ranging markets, though it's reactive and best used with confirmation. Note: This is a technical tool for educational purposes only; it does not provide financial advice, guarantees of profitability, or trading recommendations. Past performance is not indicative of future results, and users should backtest thoroughly on their specific assets/timeframes, in compliance with TradingView's house rules.
Key Features
• HTF Swing Levels: Detects and draws session highs/lows from a user-selected higher timeframe (e.g., Daily), extends lines until mitigated (by wick or body close), with alerts on mitigation.
• CTF Swing Levels: Identifies local swing highs/lows on the chart timeframe using a pivot candle formation (default 5-candle), with separate limits for unmitigated/mitigated lines.
• EMA Ribbon: A three-EMA system (fast 8, mid 13, slow 21) with gradient fills (green for bullish, red for bearish) to visualize trend strength and filter signals.
• Signal Generation: Buy/sell labels ("BUY"/"SELL") triggered post-mitigation when price aligns with EMA trend (e.g., above slow EMA with stacked bulls for buys).
• Trade Simulation & Risk Management: On signals, calculates stop-loss (SL) from recent extremes, position size based on fixed risk amount (e.g., $100 per trade, adjusted for asset type like futures point value or forex lots), and full take-profit (TP) at user-defined RR level (1-5). Draws RR boxes for visuals.
• Statistics Table: Displays total trades, wins/losses, win rate (%), net R-return, and max consecutive losses in a top-right table.
• Alerts: Customizable alerts for HTF mitigations and new trades (including entry, SL, TP, size).
• Visual Customizations: Toggle lines/ribbon/boxes, adjust colors/styles/widths for unmitigated/mitigated lines (HTF/CTF), min box width.
• Performance Optimization: Automatically cleans up excess lines to stay within max limits (e.g., 15 unmitigated HTF, 5 CTF).
How It Works
• HTF Logic: On new HTF bars (via time(htf_timeframe)), captures session high/low and draws extendable lines. Lines extend rightward until mitigated (high/close > high level for highs, low/close < low level for lows, toggle wick/body). Mitigation sets "waiting" flags for signals and triggers alerts.
• CTF Logic: Scans for pivot highs/lows using a user-defined candle count (e.g., 2 left/right for 5-candle swings). Draws and extends lines similarly, mitigating on wick touches, with separate styles for mitigated (e.g., dotted gray).
• EMA Ribbon Logic: Computes 8/13/21 EMAs; fills mid-slow and fast-mid with bullish green (close > slow EMA) or bearish red gradients.
• Signal Conditions: Post-mitigation (waiting_for_buy/sell true), checks EMA stack—buys require close > slow, fast > mid > slow; sells require close < slow, fast < mid < slow. Signals only on confirmed bars.
• Trade Execution: On signal, sets entry at close, scans back to mitigation bar for tightest SL (lowest low for buys, highest high for sells). Calculates risk points (entry - SL for buys), then position size via helper function (asset-specific: e.g., XAU *100, futures *pointvalue, forex 100000pointvalue). Sets full TP at entry ± (risk * full_tp_level). Draws risk/reward boxes (e.g., long: dark risk below entry, blue reward above) with RR and size text. Alerts with trade details.
• Trade Management: Monitors for SL hit (low <= SL for longs) or TP hit (high >= TP for longs); updates stats (wins if TP, losses if SL, tracks consec losses, net R as +full_tp_level or -1). Places summary label ("Hit TP5 (Win)" or "Stopped Out (Loss)").
• Cleanup: Counts unmitigated/mitigated lines; deletes oldest excess to respect max limits (e.g., max_lines_input=15 for HTF unmitigated, max_mit_lines_ctf=5 for CTF mitigated).
• Why This Meshup?: Standalone tools often fall short—HTF swings ignore local noise, but without CTF, miss entries; EMAs filter trends but overlook structure; manual RR lacks automation. Meshing them creates a "mitigation-to-signal" flow: HTF/CTF provide structural context (e.g., BOS/CHOCH), EMA ensures trend alignment (reducing whipsaws), and RR simulation adds practical risk control with stats for optimization. This holistic approach potentially improves edge in structure-based trading, especially in volatile markets, by combining macro/micro analysis with quantifiable risk—though it may lag in ranges or require tuning.
All logic uses arrays for line management, barstate.isconfirmed for reliability, and syminfo for asset-specific sizing. No repainting, but historical trades simulate based on chart data.
Settings and Customization
Inputs are grouped for usability:
1. Higher Timeframe (HTF) Settings:
o Show HTF Lines: Toggle visibility (default: true).
o Use Wick for Mitigation: True for wick touch, false for body close (default: false; tooltip explains).
o Timeframe: HTF period (default: "D").
o Max Unmitigated HTF Lines: Limit for active lines (default: 15, min 1, max 250).
2. Current Timeframe (CTF) Settings:
o Show CTF Swings: Toggle (default: true).
o CTF Swing Candle Count: Left/right candles for pivot (default: 2, min 1; tooltip: '2' = 5-candle formation).
o Max Unmitigated CTF Lines: (default: 5, min 1, max 250).
o Max Mitigated CTF Lines: (default: 5, min 1, max 250).
3. EMA Settings:
o Show EMA Ribbon: Toggle (default: true).
o Fast/Middle/Slow EMA Length: Defaults 8/13/21.
4. Risk/Reward Settings:
o Risk Amount per Trade ($): Fixed risk (default: 100.0, min 0.1; tooltip: for position sizing).
o Full Take Profit Level (1-5): RR for full win (default: 5; tooltip: counts as win in stats).
o Show Trade Visuals & Stats: Toggle boxes, labels, table (default: true).
5. 🎨 Visuals:
o Draw Risk/Reward Box: Toggle (default: true).
o Minimum Box Width (in bars): (default: 5, min 1).
o Long - Risk/Reward Box Colors: Defaults dark gray (risk), blue (reward).
o Short - Risk/Reward Box Colors: Defaults dark gray (risk), orange (reward).
6. Alert Settings:
o Alert on HTF Level Mitigation: Toggle (default: true).
7. HTF Line Style Settings:
o High (Unmitigated): Color (maroon 20%), width (1).
o High (Mitigated): Color (gray 40%), style (dotted/dashed, default dotted).
o Low (Unmitigated): Color (teal 20%), width (1).
o Low (Mitigated): Color (gray 40%), style (dotted/dashed, default dotted).
8. CTF Line Styles:
o CTF High (Unmitigated): Color (purple #8d198d 25%), width (1), style (Solid/Dotted/Dashed, default Solid).
o CTF High (Mitigated): Color (gray 50%), width (1), style (default Dotted).
o CTF Low (Unmitigated): Color (teal #008080 25%), width (1), style (default Solid).
o CTF Low (Mitigated): Color (gray 50%), width (1), style (default Dotted).
Usage Tips
• Multi-Timeframe Strategy: Use HTF (e.g., D1) for major levels, CTF for entries. Signals post-mitigation with EMA filter—enter on "BUY"/"SELL" labels, use boxes for RR visualization.
• Risk Management: Set risk_amount_per_trade to 1-2% of capital; adjust full_tp_level for strategy (e.g., 3 for conservative). Position size auto-adapts to asset (e.g., smaller for high-vol like XAU).
• Customization: Enable wick mitigation for aggressive setups; increase max lines in trending markets. Tune EMAs for asset (shorter for crypto).
• Alerts Integration: Use for notifications on mitigations or trades; messages include all details for quick action.
• Stats Analysis: Table shows hypothetical results—use for optimization (e.g., aim for >50% win rate, low consec losses). Reset on chart reload.
• Chart Compatibility: Best on candlestick charts; test on lower TFs with higher HTF for confluence.
Limitations
• Reactive Signals: Waits for mitigation + EMA alignment, so may miss early reversals or lag in fast markets.
• Chop in Ranges: Frequent mitigations without trend can generate false signals; EMA helps but not foolproof.
• Simulation Only: Trades are backtested on visible data—no live execution; stats assume full TP or SL hits, ignoring partials or slippage.
• Line Limits: Caps at user max to prevent overload; oldest deleted first.
• Asset Specificity: Position sizing tailored to forex/futures/metals; may need tweaks for others.
• Disclaimer: For informational use only. Trading involves risk of loss; results vary by market, timeframe, and settings. Consult professionals and backtest extensively. No profitability claims per TradingView rules.
Overview
HTF/CTF High/Low Mitigation with Signals (shortened as "H/L Signals+") is an advanced overlay indicator for TradingView, designed to identify and visualize higher timeframe (HTF) and current timeframe (CTF) swing highs/lows, track their mitigation, and generate filtered buy/sell signals using an EMA ribbon trend filter. It incorporates automated trade simulation with risk/reward (RR) visualization, position sizing based on user-defined risk, and a statistics table for performance evaluation. This tool is ideal for multi-timeframe traders focusing on swing trading, breakout strategies, or trend reversals across assets like forex, futures, metals (e.g., XAU/USD, XAG/USD), stocks, or cryptocurrencies.
The "meshup" (mashup) integrates several complementary elements: Multi-timeframe swing level detection (HTF for broader structure, CTF for finer details) with mitigation logic ensures signals align with market structure breaks; an EMA ribbon provides a dynamic trend bias to filter counter-trend trades; risk management automates position sizing and RR calculations for disciplined trading; and built-in backtesting stats offer quick insights into hypothetical performance. This combination reduces noise from isolated indicators—e.g., raw swings can be choppy, EMAs alone lag structure, and manual RR is error-prone—creating a cohesive system for spotting high-probability setups where structure, trend, and risk align. By meshing these, it aims to enhance decision-making in trending or ranging markets, though it's reactive and best used with confirmation. Note: This is a technical tool for educational purposes only; it does not provide financial advice, guarantees of profitability, or trading recommendations. Past performance is not indicative of future results, and users should backtest thoroughly on their specific assets/timeframes, in compliance with TradingView's house rules.
Key Features
• HTF Swing Levels: Detects and draws session highs/lows from a user-selected higher timeframe (e.g., Daily), extends lines until mitigated (by wick or body close), with alerts on mitigation.
• CTF Swing Levels: Identifies local swing highs/lows on the chart timeframe using a pivot candle formation (default 5-candle), with separate limits for unmitigated/mitigated lines.
• EMA Ribbon: A three-EMA system (fast 8, mid 13, slow 21) with gradient fills (green for bullish, red for bearish) to visualize trend strength and filter signals.
• Signal Generation: Buy/sell labels ("BUY"/"SELL") triggered post-mitigation when price aligns with EMA trend (e.g., above slow EMA with stacked bulls for buys).
• Trade Simulation & Risk Management: On signals, calculates stop-loss (SL) from recent extremes, position size based on fixed risk amount (e.g., $100 per trade, adjusted for asset type like futures point value or forex lots), and full take-profit (TP) at user-defined RR level (1-5). Draws RR boxes for visuals.
• Statistics Table: Displays total trades, wins/losses, win rate (%), net R-return, and max consecutive losses in a top-right table.
• Alerts: Customizable alerts for HTF mitigations and new trades (including entry, SL, TP, size).
• Visual Customizations: Toggle lines/ribbon/boxes, adjust colors/styles/widths for unmitigated/mitigated lines (HTF/CTF), min box width.
• Performance Optimization: Automatically cleans up excess lines to stay within max limits (e.g., 15 unmitigated HTF, 5 CTF).
How It Works
• HTF Logic: On new HTF bars (via time(htf_timeframe)), captures session high/low and draws extendable lines. Lines extend rightward until mitigated (high/close > high level for highs, low/close < low level for lows, toggle wick/body). Mitigation sets "waiting" flags for signals and triggers alerts.
• CTF Logic: Scans for pivot highs/lows using a user-defined candle count (e.g., 2 left/right for 5-candle swings). Draws and extends lines similarly, mitigating on wick touches, with separate styles for mitigated (e.g., dotted gray).
• EMA Ribbon Logic: Computes 8/13/21 EMAs; fills mid-slow and fast-mid with bullish green (close > slow EMA) or bearish red gradients.
• Signal Conditions: Post-mitigation (waiting_for_buy/sell true), checks EMA stack—buys require close > slow, fast > mid > slow; sells require close < slow, fast < mid < slow. Signals only on confirmed bars.
• Trade Execution: On signal, sets entry at close, scans back to mitigation bar for tightest SL (lowest low for buys, highest high for sells). Calculates risk points (entry - SL for buys), then position size via helper function (asset-specific: e.g., XAU *100, futures *pointvalue, forex 100000pointvalue). Sets full TP at entry ± (risk * full_tp_level). Draws risk/reward boxes (e.g., long: dark risk below entry, blue reward above) with RR and size text. Alerts with trade details.
• Trade Management: Monitors for SL hit (low <= SL for longs) or TP hit (high >= TP for longs); updates stats (wins if TP, losses if SL, tracks consec losses, net R as +full_tp_level or -1). Places summary label ("Hit TP5 (Win)" or "Stopped Out (Loss)").
• Cleanup: Counts unmitigated/mitigated lines; deletes oldest excess to respect max limits (e.g., max_lines_input=15 for HTF unmitigated, max_mit_lines_ctf=5 for CTF mitigated).
• Why This Meshup?: Standalone tools often fall short—HTF swings ignore local noise, but without CTF, miss entries; EMAs filter trends but overlook structure; manual RR lacks automation. Meshing them creates a "mitigation-to-signal" flow: HTF/CTF provide structural context (e.g., BOS/CHOCH), EMA ensures trend alignment (reducing whipsaws), and RR simulation adds practical risk control with stats for optimization. This holistic approach potentially improves edge in structure-based trading, especially in volatile markets, by combining macro/micro analysis with quantifiable risk—though it may lag in ranges or require tuning.
All logic uses arrays for line management, barstate.isconfirmed for reliability, and syminfo for asset-specific sizing. No repainting, but historical trades simulate based on chart data.
Settings and Customization
Inputs are grouped for usability:
1. Higher Timeframe (HTF) Settings:
o Show HTF Lines: Toggle visibility (default: true).
o Use Wick for Mitigation: True for wick touch, false for body close (default: false; tooltip explains).
o Timeframe: HTF period (default: "D").
o Max Unmitigated HTF Lines: Limit for active lines (default: 15, min 1, max 250).
2. Current Timeframe (CTF) Settings:
o Show CTF Swings: Toggle (default: true).
o CTF Swing Candle Count: Left/right candles for pivot (default: 2, min 1; tooltip: '2' = 5-candle formation).
o Max Unmitigated CTF Lines: (default: 5, min 1, max 250).
o Max Mitigated CTF Lines: (default: 5, min 1, max 250).
3. EMA Settings:
o Show EMA Ribbon: Toggle (default: true).
o Fast/Middle/Slow EMA Length: Defaults 8/13/21.
4. Risk/Reward Settings:
o Risk Amount per Trade ($): Fixed risk (default: 100.0, min 0.1; tooltip: for position sizing).
o Full Take Profit Level (1-5): RR for full win (default: 5; tooltip: counts as win in stats).
o Show Trade Visuals & Stats: Toggle boxes, labels, table (default: true).
5. 🎨 Visuals:
o Draw Risk/Reward Box: Toggle (default: true).
o Minimum Box Width (in bars): (default: 5, min 1).
o Long - Risk/Reward Box Colors: Defaults dark gray (risk), blue (reward).
o Short - Risk/Reward Box Colors: Defaults dark gray (risk), orange (reward).
6. Alert Settings:
o Alert on HTF Level Mitigation: Toggle (default: true).
7. HTF Line Style Settings:
o High (Unmitigated): Color (maroon 20%), width (1).
o High (Mitigated): Color (gray 40%), style (dotted/dashed, default dotted).
o Low (Unmitigated): Color (teal 20%), width (1).
o Low (Mitigated): Color (gray 40%), style (dotted/dashed, default dotted).
8. CTF Line Styles:
o CTF High (Unmitigated): Color (purple #8d198d 25%), width (1), style (Solid/Dotted/Dashed, default Solid).
o CTF High (Mitigated): Color (gray 50%), width (1), style (default Dotted).
o CTF Low (Unmitigated): Color (teal #008080 25%), width (1), style (default Solid).
o CTF Low (Mitigated): Color (gray 50%), width (1), style (default Dotted).
Usage Tips
• Multi-Timeframe Strategy: Use HTF (e.g., D1) for major levels, CTF for entries. Signals post-mitigation with EMA filter—enter on "BUY"/"SELL" labels, use boxes for RR visualization.
• Risk Management: Set risk_amount_per_trade to 1-2% of capital; adjust full_tp_level for strategy (e.g., 3 for conservative). Position size auto-adapts to asset (e.g., smaller for high-vol like XAU).
• Customization: Enable wick mitigation for aggressive setups; increase max lines in trending markets. Tune EMAs for asset (shorter for crypto).
• Alerts Integration: Use for notifications on mitigations or trades; messages include all details for quick action.
• Stats Analysis: Table shows hypothetical results—use for optimization (e.g., aim for >50% win rate, low consec losses). Reset on chart reload.
• Chart Compatibility: Best on candlestick charts; test on lower TFs with higher HTF for confluence.
Limitations
• Reactive Signals: Waits for mitigation + EMA alignment, so may miss early reversals or lag in fast markets.
• Chop in Ranges: Frequent mitigations without trend can generate false signals; EMA helps but not foolproof.
• Simulation Only: Trades are backtested on visible data—no live execution; stats assume full TP or SL hits, ignoring partials or slippage.
• Line Limits: Caps at user max to prevent overload; oldest deleted first.
• Asset Specificity: Position sizing tailored to forex/futures/metals; may need tweaks for others.
• Disclaimer: For informational use only. Trading involves risk of loss; results vary by market, timeframe, and settings. Consult professionals and backtest extensively. No profitability claims per TradingView rules.
Nota Keluaran
/Fixed indicator chart screen.Nota Keluaran
//changed default settings for better load timeSkrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya secara bebas dan tanpa apa-apa had – ketahui lebih di sini.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya secara bebas dan tanpa apa-apa had – ketahui lebih di sini.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.