PROTECTED SOURCE SCRIPT
OneHolo-TGAPSNR

TGAPSNR: Multi time frame - Trend Gap Stop And Reverse strategy/Study PnL. This script outlines a systematic approach to generating buy and sell signals by combining Fair Value Gaps (FVGs), specific market structures, and three different trend direction methods (Swing, Gravity, and FVG Inverse direction). The strategy incorporates multiple entry modes, such as Hyper Mode, Swiper Mode, and a Custom mode, allowing users to tailor signal conditions, alongside extensive logic for trade management, higher time frame analysis, and various visual indicators for plotting trend, pivots, and profit and loss information.
I. Core Trend Direction Consensus (The Three-Pillar System)
The primary method for determining market bias is a three-pillar consensus model, requiring all directional methods to align before the overall Trend Direction is established (up or down). This ensures high conviction for trend signals.
• Pillar 1: Swing Direction: Determines market direction based on classic price action, specifically checking for continuous higher highs and higher lows for an upward bias, or lower lows and lower highs for a downward bias.
• Pillar 2: Gravity Direction (Peak and Valley): This uses specific market structure pivots. Direction is set based on whether the close price successfully crosses the established recent Peak High (indicating upward momentum) or crosses under the recent Valley Low (indicating downward pressure).
• Pillar 3: FVG Inverse Direction: This relies on Fair Value Gaps (FVGs), defined as a gap between the current bar's price and the price two bars prior. Direction shifts occur when the Close price crosses the midpoint of the last relevant FVG. For instance, crossing above the midpoint of the last FVG Down signals a potential inverse long trade.
II. Flexible Signal Generation Modes
The strategy offers several pre-configured and highly detailed entry modes, plus a powerful Custom Mode:
• Session Open Range Break (ORB) Mode: Uses the high/low of the session's first bar to generate initial signals, then defaults to the Three-Pillar Trend Direction after the ORB session concludes.
• Swiper Mode: Designed to identify continuations, combining a confirmed Trend Direction with a Stop and Reverse signal (SnR) while actively avoiding confirmed pivot breaks.
• Hyper/Aggressive Modes: These modes use broad combinations of signals, allowing for earlier entry based on momentum and structural breaks (like PeakCrossLong, SnRtrapLong, or FVG signals).
• Custom Query Mode (The Seven-Slot Logic): This non-redundant system allows the user to define complex, tailored entry conditions by selecting any combination of 14 core patterns across seven distinct slots.
◦ AND/OR Combination: For each of the seven slots, the user determines if the chosen pattern must be met (AND component) or if it can serve as an alternative trigger (OR component).
◦ The final signal requires that all configured AND conditions are true and then integrates the result of the OR conditions, allowing for highly specific "hook queries" (e.g., "Condition A AND Condition B, OR Condition C").
III. Advanced PnL and Mobile App Diagnostics
A key proprietary element is the implementation of a dual PnL system and customized visualization features:
• Dual PnL Display (Strategy PnL vs. Study PnL): Users can choose to view either the native platform's strategy performance data or the script's internal, proprietary Study PnL. The Study PnL calculates profits/losses based strictly on the close price and tracks performance using Pine Script® arrays, providing a transparent, diagnostic view of performance independent of broker/platform simulation biases.
• Lower Panel Visualization: Both PnL types are displayed on the lower panel using detailed bar plots (style=plot.style_columns), which color according to profitability, and include labels that show current open profit and total net profit.
• Detailed Trade Labels: The script generates detailed, customizable labels on both the chart (above/below bars) and the lower PnL panel, providing historical PnL, number of trades, and real-time profit information for each entry or exit.
IV. Higher Time Frame (HTF) Context and Lookahead Prevention
The strategy integrates multi-time frame analysis using strict methodology to prevent lookahead bias:
• HTF Bias Filtering: When enabled, the strategy uses the position calculated on a user-defined higher time frame (HTF) as a mandatory filter. A long signal on the current chart is only executed if the HTF is also in a long position, and vice-versa.
• Lookahead Prevention: To maintain integrity, all HTF data requests use a mandatory lookback index (often ) to ensure the script only accesses confirmed data from the prior completed bar on the higher timeframe.
• HTF Visual Mode: The user can opt to display key structural elements—such as the Gravity Pivots and the Trend Direction blocks—as calculated on the HTF, overlaying this higher-level context onto the current chart for visual analysis.
The TGAPSNR: Multi time frame - Trend Gap Stop And Reverse strategy/Study PnL script, despite its complexity, intentionally excludes realistic considerations such as fees, slippage, and explicit risk management settings (like fixed stop-loss or take-profit rules) from its primary logic.
Here is an explanation of why these elements are omitted in the strategy's current implementation and why they must be applied by the user for real-world application, drawing on the context of the sources:
1. Absence of Realistic Fees, Commissions, and Slippage
The primary function of the TGAPSNR script is to execute intricate signal generation and diagnostic PnL calculation based on its three-pillar trend system and Custom Mode logic.
However, the strategy's backtesting results, particularly those displayed by the internal Study PnL feature, are based purely on price difference (e.g., (close - lse) * syminfo.pointvalue * IUnits).
• Strategy Result Requirements: TradingView explicitly states that strategies published publicly should strive to use realistic commission AND slippage when calculating backtesting results to avoid misleading traders.
• User Responsibility: Since the script currently focuses on signal integrity and uses a fixed contract size (IUnits = 1) without configurable commission/slippage inputs shown in the source, the user must manually configure these fees within the Pine Script® Strategy Tester settings (Properties tab) to ensure the strategy results are reflective of actual trading costs.
2. Omission of Built-in Risk Management (Stop-Loss and Take-Profit)
The TGAPSNR strategy's core focuses on entry signals and trend confirmation. Exits are primarily governed by:
• Reversal signals (BuyStop or SellStop).
• End-of-Day (EOD) session closures (EODStop).
• HTF bias opposition.
What is Missing: The script does not include explicit, hard-coded risk management parameters for traditional stop-loss (SL) or take-profit (TP) levels (e.g., risk percentage or ATR-based exits).
• Viable Risk: TradingView guidelines stipulate that strategies should generally risk sustainable amounts of equity, usually not exceeding 5-10% on a single trade, and trade size must be appropriate.
• User Application: To ensure the strategy operates within realistic risk boundaries, users must apply their own risk management rules. This includes:
◦ Implementing realistic stops and profit targets, which can be added via Pine Script® code or manually managed during live trading.
◦ Sizing trades to only risk sustainable amounts of equity. The current default unit size (IUnits = 1) is unrealistic for risk assessment unless the symbol is micro-sized.
3. Execution Quality (Fills)
The strategy is set to fill_orders_on_standard_ohlc = true and operates on confirmed bar closes (barstate.isconfirmed).
• Fill Assumption: This suggests the strategy primarily uses close price or the HTF close price (EntryPrice = HTFClose) for execution.
• Real-World Limitation: In volatile markets, obtaining a fill price equal to the close of the bar is rare. The user must be aware that the simulated fill price shown in backtesting may differ significantly from actual execution prices due to market action and chosen order type, reinforcing the importance of applying slippage settings.
In summary, while the script provides highly detailed and unique signal generation and internal PnL diagnostics, users must exercise caution and apply their own realistic parameters for fees, slippage, and explicit risk controls to prevent misleading performance results and ensure viable trading
I. Core Trend Direction Consensus (The Three-Pillar System)
The primary method for determining market bias is a three-pillar consensus model, requiring all directional methods to align before the overall Trend Direction is established (up or down). This ensures high conviction for trend signals.
• Pillar 1: Swing Direction: Determines market direction based on classic price action, specifically checking for continuous higher highs and higher lows for an upward bias, or lower lows and lower highs for a downward bias.
• Pillar 2: Gravity Direction (Peak and Valley): This uses specific market structure pivots. Direction is set based on whether the close price successfully crosses the established recent Peak High (indicating upward momentum) or crosses under the recent Valley Low (indicating downward pressure).
• Pillar 3: FVG Inverse Direction: This relies on Fair Value Gaps (FVGs), defined as a gap between the current bar's price and the price two bars prior. Direction shifts occur when the Close price crosses the midpoint of the last relevant FVG. For instance, crossing above the midpoint of the last FVG Down signals a potential inverse long trade.
II. Flexible Signal Generation Modes
The strategy offers several pre-configured and highly detailed entry modes, plus a powerful Custom Mode:
• Session Open Range Break (ORB) Mode: Uses the high/low of the session's first bar to generate initial signals, then defaults to the Three-Pillar Trend Direction after the ORB session concludes.
• Swiper Mode: Designed to identify continuations, combining a confirmed Trend Direction with a Stop and Reverse signal (SnR) while actively avoiding confirmed pivot breaks.
• Hyper/Aggressive Modes: These modes use broad combinations of signals, allowing for earlier entry based on momentum and structural breaks (like PeakCrossLong, SnRtrapLong, or FVG signals).
• Custom Query Mode (The Seven-Slot Logic): This non-redundant system allows the user to define complex, tailored entry conditions by selecting any combination of 14 core patterns across seven distinct slots.
◦ AND/OR Combination: For each of the seven slots, the user determines if the chosen pattern must be met (AND component) or if it can serve as an alternative trigger (OR component).
◦ The final signal requires that all configured AND conditions are true and then integrates the result of the OR conditions, allowing for highly specific "hook queries" (e.g., "Condition A AND Condition B, OR Condition C").
III. Advanced PnL and Mobile App Diagnostics
A key proprietary element is the implementation of a dual PnL system and customized visualization features:
• Dual PnL Display (Strategy PnL vs. Study PnL): Users can choose to view either the native platform's strategy performance data or the script's internal, proprietary Study PnL. The Study PnL calculates profits/losses based strictly on the close price and tracks performance using Pine Script® arrays, providing a transparent, diagnostic view of performance independent of broker/platform simulation biases.
• Lower Panel Visualization: Both PnL types are displayed on the lower panel using detailed bar plots (style=plot.style_columns), which color according to profitability, and include labels that show current open profit and total net profit.
• Detailed Trade Labels: The script generates detailed, customizable labels on both the chart (above/below bars) and the lower PnL panel, providing historical PnL, number of trades, and real-time profit information for each entry or exit.
IV. Higher Time Frame (HTF) Context and Lookahead Prevention
The strategy integrates multi-time frame analysis using strict methodology to prevent lookahead bias:
• HTF Bias Filtering: When enabled, the strategy uses the position calculated on a user-defined higher time frame (HTF) as a mandatory filter. A long signal on the current chart is only executed if the HTF is also in a long position, and vice-versa.
• Lookahead Prevention: To maintain integrity, all HTF data requests use a mandatory lookback index (often ) to ensure the script only accesses confirmed data from the prior completed bar on the higher timeframe.
• HTF Visual Mode: The user can opt to display key structural elements—such as the Gravity Pivots and the Trend Direction blocks—as calculated on the HTF, overlaying this higher-level context onto the current chart for visual analysis.
The TGAPSNR: Multi time frame - Trend Gap Stop And Reverse strategy/Study PnL script, despite its complexity, intentionally excludes realistic considerations such as fees, slippage, and explicit risk management settings (like fixed stop-loss or take-profit rules) from its primary logic.
Here is an explanation of why these elements are omitted in the strategy's current implementation and why they must be applied by the user for real-world application, drawing on the context of the sources:
1. Absence of Realistic Fees, Commissions, and Slippage
The primary function of the TGAPSNR script is to execute intricate signal generation and diagnostic PnL calculation based on its three-pillar trend system and Custom Mode logic.
However, the strategy's backtesting results, particularly those displayed by the internal Study PnL feature, are based purely on price difference (e.g., (close - lse) * syminfo.pointvalue * IUnits).
• Strategy Result Requirements: TradingView explicitly states that strategies published publicly should strive to use realistic commission AND slippage when calculating backtesting results to avoid misleading traders.
• User Responsibility: Since the script currently focuses on signal integrity and uses a fixed contract size (IUnits = 1) without configurable commission/slippage inputs shown in the source, the user must manually configure these fees within the Pine Script® Strategy Tester settings (Properties tab) to ensure the strategy results are reflective of actual trading costs.
2. Omission of Built-in Risk Management (Stop-Loss and Take-Profit)
The TGAPSNR strategy's core focuses on entry signals and trend confirmation. Exits are primarily governed by:
• Reversal signals (BuyStop or SellStop).
• End-of-Day (EOD) session closures (EODStop).
• HTF bias opposition.
What is Missing: The script does not include explicit, hard-coded risk management parameters for traditional stop-loss (SL) or take-profit (TP) levels (e.g., risk percentage or ATR-based exits).
• Viable Risk: TradingView guidelines stipulate that strategies should generally risk sustainable amounts of equity, usually not exceeding 5-10% on a single trade, and trade size must be appropriate.
• User Application: To ensure the strategy operates within realistic risk boundaries, users must apply their own risk management rules. This includes:
◦ Implementing realistic stops and profit targets, which can be added via Pine Script® code or manually managed during live trading.
◦ Sizing trades to only risk sustainable amounts of equity. The current default unit size (IUnits = 1) is unrealistic for risk assessment unless the symbol is micro-sized.
3. Execution Quality (Fills)
The strategy is set to fill_orders_on_standard_ohlc = true and operates on confirmed bar closes (barstate.isconfirmed).
• Fill Assumption: This suggests the strategy primarily uses close price or the HTF close price (EntryPrice = HTFClose) for execution.
• Real-World Limitation: In volatile markets, obtaining a fill price equal to the close of the bar is rare. The user must be aware that the simulated fill price shown in backtesting may differ significantly from actual execution prices due to market action and chosen order type, reinforcing the importance of applying slippage settings.
In summary, while the script provides highly detailed and unique signal generation and internal PnL diagnostics, users must exercise caution and apply their own realistic parameters for fees, slippage, and explicit risk controls to prevent misleading performance results and ensure viable trading
受保护脚本
此脚本以闭源形式发布。 但是,您可以自由使用它,没有任何限制 — 在此处了解更多信息。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
受保护脚本
此脚本以闭源形式发布。 但是,您可以自由使用它,没有任何限制 — 在此处了解更多信息。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。