PROTECTED SOURCE SCRIPT
A+ Model - Cave Education

Here is a comprehensive and detailed explanation of the "A+ Model - Cave Education" Pine Script code.
This script is a sophisticated technical analysis tool designed for TradingView. It assists traders in identifying specific institutional time windows, price ranges (sessions), and "Macro" volatility periods based on the ICT (Inner Circle Trader) or similar time-based trading concepts.
Below is the breakdown of how the code functions, organized by its logic sections.
1. General Overview
The script is an overlay indicator (it sits directly on the price chart). Its primary purpose is to:
Highlight a specific trading session (The "A+ Box") and mark its High/Low.
Mark key institutional times (07:00 NY and 09:30 NY Open).
Identify "Macro" windows (specific 20-minute periods where algorithms are active) and draw dynamic ranges around them based on volatility (ATR).
Project future times onto the chart to help the trader prepare for the next day.
2. Settings & Inputs (User Configuration)
The code begins by defining a vast array of user inputs, grouped for better usability:
General Time & Box: Allows the user to define the "A+ Session" time (default 20:00-00:00) and the Time Zone (UTC-5/New York). It also handles the visual style (colors) of the session box.
Visibility: A crucial performance and visual clutter setting. boxDays limits how far back the A+ boxes and time lines are drawn (default 14 days). Macros are strictly limited to the current week to prevent chart lagging.
Line & Text Controls: Every visual element (A+ lines, NY markers, Macros) has toggles (input.bool) to show/hide the lines or the text labels separately.
Macro Settings: Defines the time windows for three separate macros and an ATR Multiplier. The ATR multiplier determines how wide the channel lines are drawn around the macro price action.
3. Logic Breakdown by Section
Section 1: The "A+ Draw" Box (Session Range)
This is the core of the A+ Model.
Logic: The script checks if the current bar is within the user-defined sessionTime.
Box Creation:
When the session starts, it initializes a new Box (box.new).
Throughout the session, it continuously updates the Box's Top (Highest High) and Bottom (Lowest Low) to encompass the full range of that time period.
Extension Lines (Support/Resistance):
Once the session ends, the script draws two horizontal lines: one from the Session High and one from the Session Low.
Smart Break Logic: These lines are active (highActive, lowActive). They extend to the right until the price breaks them (High line is broken by a higher price, Low line by a lower price). This helps traders see if the session range is being respected or broken later in the day.
Section 2: Time Lines (NY Midnight & Open)
This section marks vertical reference points.
It checks for specific times: 07:00 and 09:30 (in the user's timezone).
If the current bar matches these times, it draws a vertical line (line.new) covering the High/Low of that bar and places a label (e.g., "NY." or "09:30") above it.
This helps the trader orient themselves regarding the New York session Open and the "Killzone" start.
Section 3: Macros (Volatility Windows)
This is the most complex calculation in the script.
Definition: Macros are specific time windows (e.g., 09:50–10:10) where price delivery is often accelerated.
Visibility Rule: To keep the script fast, this only runs if isCurrentWeek is true.
ATR Offset: The script calculates the Average True Range (ATR). It uses this to create a "channel" around the price.
Drawing Logic:
When a Macro time starts, the script tracks the Highest High and Lowest Low inside that specific 20-minute window.
It draws parallel horizontal lines above and below these prices.
The Twist: The lines are not drawn at the High/Low. They are offset by ATR * Multiplier. This creates a wider "zone" around the macro price action, visually indicating a volatility range.
Section 4: Future Projection (Tomorrow)
This feature is for planning ahead.
It runs only on the last bar of the chart (barstate.islast).
It calculates the timestamps for the next occurrence of the key times (07:00, 09:30, and all three Macros).
It draws vertical lines into the future (empty space on the right of the chart).
Benefit: The trader can see exactly where 09:30 or the next Macro will occur on the timeline before the candles even print.
4. Helper Functions
The code uses custom functions to keep the logic clean:
f_drawFuture(...): A standardized function to draw the future vertical lines and labels so the code doesn't have to repeat itself for every single time marker.
isStartTime(...) & isInTime(...): Shorthand functions to check if the current candle belongs to a specific session string (like "0950-1010").
Summary of Improvements in this Version
Compared to a standard indicator, this script is highly optimized:
Text Control: You can turn off text labels while keeping the lines (or vice versa).
Performance: It limits historical drawing (only 14 days back for boxes, only this week for macros) to prevent "Maximum Line Count" errors in Pine Script.
Visual Clarity: It uses different colors for different Macros (Blue, Red, Orange) to make them instantly distinguishable.
This script is a sophisticated technical analysis tool designed for TradingView. It assists traders in identifying specific institutional time windows, price ranges (sessions), and "Macro" volatility periods based on the ICT (Inner Circle Trader) or similar time-based trading concepts.
Below is the breakdown of how the code functions, organized by its logic sections.
1. General Overview
The script is an overlay indicator (it sits directly on the price chart). Its primary purpose is to:
Highlight a specific trading session (The "A+ Box") and mark its High/Low.
Mark key institutional times (07:00 NY and 09:30 NY Open).
Identify "Macro" windows (specific 20-minute periods where algorithms are active) and draw dynamic ranges around them based on volatility (ATR).
Project future times onto the chart to help the trader prepare for the next day.
2. Settings & Inputs (User Configuration)
The code begins by defining a vast array of user inputs, grouped for better usability:
General Time & Box: Allows the user to define the "A+ Session" time (default 20:00-00:00) and the Time Zone (UTC-5/New York). It also handles the visual style (colors) of the session box.
Visibility: A crucial performance and visual clutter setting. boxDays limits how far back the A+ boxes and time lines are drawn (default 14 days). Macros are strictly limited to the current week to prevent chart lagging.
Line & Text Controls: Every visual element (A+ lines, NY markers, Macros) has toggles (input.bool) to show/hide the lines or the text labels separately.
Macro Settings: Defines the time windows for three separate macros and an ATR Multiplier. The ATR multiplier determines how wide the channel lines are drawn around the macro price action.
3. Logic Breakdown by Section
Section 1: The "A+ Draw" Box (Session Range)
This is the core of the A+ Model.
Logic: The script checks if the current bar is within the user-defined sessionTime.
Box Creation:
When the session starts, it initializes a new Box (box.new).
Throughout the session, it continuously updates the Box's Top (Highest High) and Bottom (Lowest Low) to encompass the full range of that time period.
Extension Lines (Support/Resistance):
Once the session ends, the script draws two horizontal lines: one from the Session High and one from the Session Low.
Smart Break Logic: These lines are active (highActive, lowActive). They extend to the right until the price breaks them (High line is broken by a higher price, Low line by a lower price). This helps traders see if the session range is being respected or broken later in the day.
Section 2: Time Lines (NY Midnight & Open)
This section marks vertical reference points.
It checks for specific times: 07:00 and 09:30 (in the user's timezone).
If the current bar matches these times, it draws a vertical line (line.new) covering the High/Low of that bar and places a label (e.g., "NY." or "09:30") above it.
This helps the trader orient themselves regarding the New York session Open and the "Killzone" start.
Section 3: Macros (Volatility Windows)
This is the most complex calculation in the script.
Definition: Macros are specific time windows (e.g., 09:50–10:10) where price delivery is often accelerated.
Visibility Rule: To keep the script fast, this only runs if isCurrentWeek is true.
ATR Offset: The script calculates the Average True Range (ATR). It uses this to create a "channel" around the price.
Drawing Logic:
When a Macro time starts, the script tracks the Highest High and Lowest Low inside that specific 20-minute window.
It draws parallel horizontal lines above and below these prices.
The Twist: The lines are not drawn at the High/Low. They are offset by ATR * Multiplier. This creates a wider "zone" around the macro price action, visually indicating a volatility range.
Section 4: Future Projection (Tomorrow)
This feature is for planning ahead.
It runs only on the last bar of the chart (barstate.islast).
It calculates the timestamps for the next occurrence of the key times (07:00, 09:30, and all three Macros).
It draws vertical lines into the future (empty space on the right of the chart).
Benefit: The trader can see exactly where 09:30 or the next Macro will occur on the timeline before the candles even print.
4. Helper Functions
The code uses custom functions to keep the logic clean:
f_drawFuture(...): A standardized function to draw the future vertical lines and labels so the code doesn't have to repeat itself for every single time marker.
isStartTime(...) & isInTime(...): Shorthand functions to check if the current candle belongs to a specific session string (like "0950-1010").
Summary of Improvements in this Version
Compared to a standard indicator, this script is highly optimized:
Text Control: You can turn off text labels while keeping the lines (or vice versa).
Performance: It limits historical drawing (only 14 days back for boxes, only this week for macros) to prevent "Maximum Line Count" errors in Pine Script.
Visual Clarity: It uses different colors for different Macros (Blue, Red, Orange) to make them instantly distinguishable.
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.
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.