FvgObject█ OVERVIEW
This library provides a suite of methods designed to manage the visual representation and lifecycle of Fair Value Gap (FVG) objects on a Pine Script™ chart. It extends the `fvgObject` User-Defined Type (UDT) by attaching object-oriented functionalities for drawing, updating, and deleting FVG-related graphical elements. The primary goal is to encapsulate complex drawing logic, making the main indicator script cleaner and more focused on FVG detection and state management.
█ CONCEPTS
This library is built around the idea of treating each Fair Value Gap as an "object" with its own visual lifecycle on the chart. This is achieved by defining methods that operate directly on instances of the `fvgObject` UDT.
Object-Oriented Approach for FVGs
Pine Script™ v6 introduced the ability to define methods for User-Defined Types (UDTs). This library leverages this feature by attaching specific drawing and state management functions (methods) directly to the `fvgObject` type. This means that instead of calling global functions with an FVG object as a parameter, you call methods *on* the FVG object itself (e.g., `myFvg.updateDrawings(...)`). This approach promotes better code organization and a more intuitive way to interact with FVG data.
FVG Visual Lifecycle Management
The core purpose of this library is to manage the complete visual journey of an FVG on the chart. This lifecycle includes:
Initial Drawing: Creating the first visual representation of a newly detected FVG, including its main box and optionally its midline and labels.
State Updates & Partial Fills: Modifying the FVG's appearance as it gets partially filled by price. This involves drawing a "mitigated" portion of the box and adjusting the `currentTop` or `currentBottom` of the remaining FVG.
Full Mitigation & Tested State: Handling how an FVG is displayed once fully mitigated. Depending on user settings, it might be hidden, or its box might change color/style to indicate it has been "tested." Mitigation lines can also be managed (kept or deleted).
Midline Interaction: Visually tracking if the price has touched the FVG's 50% equilibrium level (midline).
Visibility Control: Dynamically showing or hiding FVG drawings based on various criteria, such as user settings (e.g., hide mitigated FVGs, timeframe-specific visibility) or external filters (e.g., proximity to current price).
Deletion: Cleaning up all drawing objects associated with an FVG when it's no longer needed or when settings dictate its removal.
Centralized Drawing Logic
By encapsulating all drawing-related operations within the methods of this library, the main indicator script is significantly simplified. The main script can focus on detecting FVGs and managing their state (e.g., in arrays), while delegating the complex task of rendering and updating them on the chart to the methods herein.
Interaction with `fvgObject` and `drawSettings` UDTs
All methods within this library operate on an instance of the `fvgObject` UDT. This `fvgObject` holds not only the FVG's price/time data and state (like `isMitigated`, `currentTop`) but also the IDs of its associated drawing elements (e.g., `boxId`, `midLineId`).
The appearance of these drawings (colors, styles, visibility, etc.) is dictated by a `drawSettings` UDT instance, which is passed as a parameter to most drawing-related methods. This `drawSettings` object is typically populated from user inputs in the main script, allowing for extensive customization.
Stateful Drawing Object Management
The library's methods manage Pine Script™ drawing objects (boxes, lines, labels) by storing their IDs within the `fvgObject` itself (e.g., `fvgObject.boxId`, `fvgObject.mitigatedBoxId`, etc.). Methods like `draw()` create these objects and store their IDs, while methods like `updateDrawings()` modify them, and `deleteDrawings()` removes them using these stored IDs.
Drawing Optimization
The `updateDrawings()` method, which is the most comprehensive drawing management function, incorporates optimization logic. It uses `prev_*` fields within the `fvgObject` (e.g., `prevIsMitigated`, `prevCurrentTop`) to store the FVG's state from the previous bar. By comparing the current state with the previous state, and also considering changes in visibility or relevant drawing settings, it can avoid redundant and performance-intensive drawing operations if nothing visually significant has changed for that FVG.
█ METHOD USAGE AND WORKFLOW
The methods in this library are designed to be called in a logical sequence as an FVG progresses through its lifecycle. A crucial prerequisite for all visual methods in this library is a properly populated `drawSettings` UDT instance, which dictates every aspect of an FVG's appearance, from colors and styles to visibility and labels. This `settings` object must be carefully prepared in the main indicator script, typically based on user inputs, before being passed to these methods.
Here’s a typical workflow within a main indicator script:
1. FVG Instance Creation (External to this library)
An `fvgObject` instance is typically created by functions in another library (e.g., `FvgCalculations`) when a new FVG pattern is identified. This object will have its core properties (top, bottom, startTime, isBullish, tfType) initialized.
2. Initial Drawing (`draw` method)
Once a new `fvgObject` is created and its initial visibility is determined:
Call the `myFvg.draw(settings)` method on the new FVG object.
`settings` is an instance of the `drawSettings` UDT, containing all relevant visual configurations.
This method draws the primary FVG box, its midline (if enabled in `settings`), and any initial labels. It also initializes the `currentTop` and `currentBottom` fields of the `fvgObject` if they are `na`, and stores the IDs of the created drawing objects within the `fvgObject`.
3. Per-Bar State Updates & Interaction Checks
On each subsequent bar, for every active `fvgObject`:
Interaction Check (External Logic): It's common to first use logic (e.g., from `FvgCalculations`' `fvgInteractionCheck` function) to determine if the current bar's price interacts with the FVG.
State Field Updates (External Logic): Before calling the `FvgObjectLib` methods below, ensure that your `fvgObject`'s state fields (such as `isMitigated`, `currentTop`, `currentBottom`, `isMidlineTouched`) are updated using the current bar's price data and relevant functions from other libraries (e.g., `FvgCalculations`' `checkMitigation`, `checkPartialMitigation`, etc.). This library's methods render the FVG based on these pre-updated state fields.
If interaction occurs and the FVG is not yet fully mitigated:
Full Mitigation Update (`updateMitigation` method): Call `myFvg.updateMitigation(high, low)`. This method updates `myFvg.isMitigated` and `myFvg.mitigationTime` if full mitigation occurs, based on the interaction determined by external logic.
Partial Fill Update (`updatePartialFill` method): If not fully mitigated, call `myFvg.updatePartialFill(high, low, settings)`. This method updates `myFvg.currentTop` or `myFvg.currentBottom` and adjusts drawings to show the filled portion, again based on prior interaction checks and fill level calculations.
Midline Touch Check (`checkMidlineTouch` method): Call `myFvg.checkMidlineTouch(high, low)`. This method updates `myFvg.isMidlineTouched` if the price touches the FVG's 50% level.
4. Comprehensive Visual Update (`updateDrawings` method)
After the FVG's state fields have been potentially updated by external logic and the methods in step 3:
Call `myFvg.updateDrawings(isVisibleNow, settings)` on each FVG object.
`isVisibleNow` is a boolean indicating if the FVG should currently be visible.
`settings` is the `drawSettings` UDT instance.
This method synchronizes the FVG's visual appearance with its current state and settings, managing all drawing elements (boxes, lines, labels), their styles, and visibility. It efficiently skips redundant drawing operations if the FVG's state or visibility has not changed, thanks to its internal optimization using `prev_*` fields, which are also updated by this method.
5. Deleting Drawings (`deleteDrawings` method)
When an FVG object is no longer tracked:
Call `myFvg.deleteDrawings(deleteTestedToo)`.
This method removes all drawing objects associated with that `fvgObject`.
This workflow ensures that FVG visuals are accurately maintained throughout their existence on the chart.
█ NOTES
Dependencies: This library relies on `FvgTypes` for `fvgObject` and `drawSettings` definitions, and its methods (`updateMitigation`, `updatePartialFill`) internally call functions from `FvgCalculations`.
Drawing Object Management: Be mindful of TradingView's limits on drawing objects per script. The main script should manage the number of active FVG objects.
Performance and `updateDrawings()`: The `updateDrawings()` method is comprehensive. Its internal optimization (checking `hasStateChanged` based on `prev_*` fields) is crucial for performance. Call it judiciously.
Role of `settings.currentTime`: The `currentTime` field in `drawSettings` is key for positioning time-dependent elements like labels and the right edge of non-extended drawings.
Mutability of `fvgObject` Instances: Methods in this library directly modify the `fvgObject` instance they are called upon (e.g., its state fields and drawing IDs).
Drawing ID Checks: Methods generally check if drawing IDs are `na` before acting on them, preventing runtime errors.
█ EXPORTED FUNCTIONS
method draw(this, settings)
Draws the initial visual representation of the FVG object on the chart. This includes the main FVG box, its midline (if enabled), and a label
(if enabled for the specific timeframe). This method is typically invoked
immediately after an FVG is first detected and its initial properties are set. It uses drawing settings to customize the appearance based on the FVG's timeframe type.
Namespace types: types.fvgObject
Parameters:
this (fvgObject type from no1x/FvgTypes/1) : The FVG object instance to be drawn. Core properties (top, bottom,
startTime, isBullish, tfType) should be pre-initialized. This method will
initialize boxId, midLineId, boxLabelId (if applicable), and
currentTop/currentBottom (if currently na) on this object.
settings (drawSettings type from no1x/FvgTypes/1) : A drawSettings object providing all visual parameters. Reads display settings (colors, styles, visibility for boxes, midlines, labels,
box extension) relevant to this.tfType. settings.currentTime is used for
positioning labels and the right boundary of non-extended boxes.
method updateMitigation(this, highVal, lowVal)
Checks if the FVG has been fully mitigated by the current bar's price action.
Namespace types: types.fvgObject
Parameters:
this (fvgObject type from no1x/FvgTypes/1) : The FVG object instance. Reads this.isMitigated, this.isVisible,
this.isBullish, this.top, this.bottom. Updates this.isMitigated and
this.mitigationTime if full mitigation occurs.
highVal (float) : The high price of the current bar, used for mitigation check.
lowVal (float) : The low price of the current bar, used for mitigation check.
method updatePartialFill(this, highVal, lowVal, settings)
Checks for and processes partial fills of the FVG.
Namespace types: types.fvgObject
Parameters:
this (fvgObject type from no1x/FvgTypes/1) : The FVG object instance. Reads this.isMitigated, this.isVisible,
this.isBullish, this.currentTop, this.currentBottom, original this.top/this.bottom,
this.startTime, this.tfType, this.isLV. Updates this.currentTop or
this.currentBottom, creates/updates this.mitigatedBoxId, and may update this.boxId's
top/bottom to reflect the filled portion.
highVal (float) : The high price of the current bar, used for partial fill check.
lowVal (float) : The low price of the current bar, used for partial fill check.
settings (drawSettings type from no1x/FvgTypes/1) : The drawing settings. Reads timeframe-specific colors for mitigated
boxes (e.g., settings.mitigatedBullBoxColor, settings.mitigatedLvBullColor),
box extension settings (settings.shouldExtendBoxes, settings.shouldExtendMtfBoxes, etc.),
and settings.currentTime to style and position the mitigatedBoxId and potentially adjust the main boxId.
method checkMidlineTouch(this, highVal, lowVal)
Checks if the FVG's midline (50% level or Equilibrium) has been touched.
Namespace types: types.fvgObject
Parameters:
this (fvgObject type from no1x/FvgTypes/1) : The FVG object instance. Reads this.midLineId, this.isMidlineTouched,
this.top, this.bottom. Updates this.isMidlineTouched if a touch occurs.
highVal (float) : The high price of the current bar, used for midline touch check.
lowVal (float) : The low price of the current bar, used for midline touch check.
method deleteDrawings(this, deleteTestedToo)
Deletes all visual drawing objects associated with this FVG object.
Namespace types: types.fvgObject
Parameters:
this (fvgObject type from no1x/FvgTypes/1) : The FVG object instance. Deletes drawings referenced by boxId,
mitigatedBoxId, midLineId, mitLineId, boxLabelId, mitLineLabelId,
and potentially testedBoxId, keptMitLineId. Sets these ID fields to na.
deleteTestedToo (simple bool) : If true, also deletes drawings for "tested" FVGs
(i.e., testedBoxId and keptMitLineId).
method updateDrawings(this, isVisibleNow, settings)
Manages the comprehensive update of all visual elements of an FVG object
based on its current state (e.g., active, mitigated, partially filled) and visibility. It handles the drawing, updating, or deletion of FVG boxes (main and mitigated part),
midlines, mitigation lines, and their associated labels. Visibility is determined by the isVisibleNow parameter and relevant settings
(like settings.shouldHideMitigated or timeframe-specific show flags). This method is central to the FVG's visual lifecycle and includes optimization
to avoid redundant drawing operations if the FVG's relevant state or appearance
settings have not changed since the last bar. It also updates the FVG object's internal prev_* state fields for future optimization checks.
Namespace types: types.fvgObject
Parameters:
this (fvgObject type from no1x/FvgTypes/1) : The FVG object instance to update. Reads most state fields (e.g.,
isMitigated, currentTop, tfType, etc.) and updates all drawing ID fields
(boxId, midLineId, etc.), this.isVisible, and all this.prev_* state fields.
isVisibleNow (bool) : A flag indicating whether the FVG should be currently visible. Typically determined by external logic (e.g., visual range filter). Affects
whether active FVG drawings are created/updated or deleted by this method.
settings (drawSettings type from no1x/FvgTypes/1) : A fully populated drawSettings object. This method extensively
reads its fields (colors, styles, visibility toggles, timeframe strings, etc.)
to render FVG components according to this.tfType and current state. settings.currentTime is critical for positioning elements like labels and extending drawings.
Lifecycle
[TTI] Eric Krull's YTD Market Indexes––––HISTORY & CREDITS 🏦
The Eric Krull's Index and Sector Performance Indicator is a powerful tool designed to provide users with a comprehensive view of the market's health and leading sectors. This innovative indicator analyzes various indexes and sectors, including the Nasdaq Composite, Renaissance IPO ETF, NYSE Composite, DJIA, and SP500, as well as 11 custom (user input) ETFs representing major sectors. By offering a detailed look at these indexes and sectors, users can better understand market trends and make informed trading decisions. Credit for the indicator goes to Eric Krull from the Lifecycle Trade team who has showcased the idea for it.
––––WHAT IT DOES 💡
The Eric Krull's Index and Sector Performance Indicator allows traders to:
👉 Monitor the performance of various market indexes, such as the Nasdaq Composite, Renaissance IPO ETF, NYSE Composite, DJIA, and SP500 and compare them to one another
👉Track the performance of 11 user input tickers or ETFs representing major sectors, providing insights into market trends and sector strength (could also compare stocks or other instruments like bonds, crypto or FOREX)
👉Assess overall market health by analyzing the Year-to-Date (YTD) performance of the selected indexes and input tickers.
👉Calculate where in the year to date range is the ticker/sector currently since the beginning of the year.
––––HOW TO USE IT 🔧
Using the Eric Krull's Index and Sector Performance Indicator is simple:
👉Add the indicator to your TradingView chart by searching for " Eric Krull's YTD Market Indexes" in the indicators list.
👉Customize the indicator by entering your desired symbols for the 11 custom ETFs, representing the major sectors you wish to analyze.
👉Adjust the table position on your chart by selecting from the available options: Top Left, Top Center, Top Right, Middle Left, Middle Center, Middle Right, Bottom Left, Bottom Center, or Bottom Right.
👉Review the table to analyze the YTD performance, percentage change, and range of each index and sector, which will help you identify leading sectors and gauge overall market health. Compare the sectors against one another to see where money are flowing in and also compare the overall performance in the index.
By utilizing the Eric Krull's Index and Sector Performance Indicator, you can make informed trading decisions based on the current market trends and sector performance. Stay ahead of the market by understanding which sectors are leading and use this knowledge to adapt your trading strategy accordingly.
[TTI] Eric Krull's Market Health Indicator📜 ––––HISTORY & CREDITS 🏦
Introducing Eric Krull's Market Health Indicator, an innovative tool specifically designed for monitoring the health of major indices such as the S&P 500, Nasdaq Composite, or Dow Jones Industrial Average. Developed by Eric Krull, an expert in the field of financial markets, this indicator aims to help traders gain a better understanding of the overall market condition and make informed trading decisions. The indicator is a 90% match to what Eric Krull has shared about it.
🎯 ––––WHAT IT DOES 💡
Eric Krull's Market Health Indicator (MHI) provides a quick and easy-to-understand visual representation of the current market health. By calculating the moving averages, determining their slopes, and computing the percentage difference between the index and the 21-day Exponential Moving Average (21DEMA), the MHI generates three different color-coded signals:
👉Green: Indicates a healthy market with a strong uptrend.
👉Red: Indicates a weak market with a strong downtrend.
👉Yellow: Indicates a neutral or sideways market.
This color-coded system allows traders to quickly assess the health of the major indices and make better-informed decisions on their trades.
🛠️ ––––HOW TO USE IT 🔧
To use Eric Krull's Market Health Indicator, follow these simple steps:
1. Load the indicator script into your preferred charting platform.
2. Set the index symbol to either "SPX" for the S&P 500, "COMP" for the Nasdaq Composite, or "DJI" for the Dow Jones Industrial Average.
3. Observe the Market Health Indicator columns plotted at the bottom of your chart.
4. Interpret the color-coded signals as follows:
🟩Green: A healthy market with a strong uptrend. Consider taking long positions or holding onto existing long positions.
🟥Red: A weak market with a strong downtrend. Consider taking short positions or reducing exposure to long positions.
🟨Yellow: A neutral or sideways market. Stay cautious and consider waiting for a clearer signal before entering new trades.
By incorporating Eric Krull's Market Health Indicator into your trading strategy, you can better gauge the overall market health and make more informed decisions on your trades. Always remember to use this tool in conjunction with other indicators and risk management practices to maximize your success.
[TTI] Lifecycle Trade: Sell Rules v2––––HISTORY & CREDITS 🏦
This script is based on the IPO Trading Lifecycle Trade Methodology by Kathy Donnelly and her team. It provides an implementation of their research on effective buy and sell rules for IPOs and Super Growth Stocks. The goal of this script is to help traders identify the best-performing sell rules, such as Ascender, Midterm, 40-Week, and Everest after they buy from IPO base. Henceforth these rules are used for IPO trading.
––––WHAT IT DOES 💡
1. Based on the methodology from the Lifecycle trade book, the script implements the best-performing sell rules (Ascender, Midterm, 40-Week, and Everest) based on profits, drawdowns, and time-in-market.
More details about the rules in section .
• Everest Rule = comprises of 9 conditions for triggering and 3 conditions for exiting
• Ascender Rule = comprises of 3 exit Rules for 3 different exit points
• Midterm Rules = uses 2 different scenarios (rules for trades less than 1 year and those after 1 year)
• 40 week Rules = use price action around the 40 week to determine exit rules
2. There is a table with the performance of these rules (backtested). The table can be positioned where the user wants in the chart and can view the performance of the Sell Rules either by horizontally by Rule or vertically by IPO Chart Pattern (Rocket Ship, Late Boomer, One Hit Wonder, Pump and Dump or Stair Stepper).
––––HOW TO USE IT 🔧
1. Apply the script to your chart and choose your trade start date.
2. Watch for highlighted the sell rules (Ascender, Midterm, 40-Week, and Everest) to exit trades in a disciplined and systematic manner. If an exit rule triggeres it will be displayed on the chart. Buy points are not included in the script!
3. Adjust for your trading style, timeframe, and risk tolerance according to your preferences and the script's output. The rules utilize Short term, Mid Term and Long Term investors.
• Short Term Rules = Everest Rule, Ascender Rule
• Mid Term Rules = Midterm Rule
• Long Term Rules = Everest, 40 Week Rule
––––DETAILS ON THE RULES 📚
These rules use two main criteria to trigger- Price and Volume. Price is interpreted by how much the stock gains or loses in a given time period, wether it is printing consecutive up days or if it is has large gap ups that have not been unclosed.
Some of the techniques implement backtested thresholds like number of unfilled gap up in the last 10 days or when have largest volume or largest dollar gain happened relative to the IPO price. The rules also implement things like how many days have the stock been up for the last 10 days or if there are any large gaps +5% that have not been unfilled. Another signal that is being used is if we have had the largest $ gain since the stocks history in a given period. Volume is used to determine if there has been a significant volume influx since the IPO date of the history if so, this triggers a rule. Some rules are time based and look for specific price action during the history of the stock for instance certain rules are required in the first 252 days of the trading history and certain rules are required after the first 252 days of the price history. We are also employing closing under important moving averages as a guide wether or not a stock should be sold. Another technique is to see how much total gain has the stock moved. THis is important for RocketShip patterns. If it has made +500% moves this would trigger certain sell rules. Price analysis is also being used on higher timeframes. For instance if a stock moves below certain important levels in 2 consecutive weeks then this would trigger a violation of the setup.
The Table of results that can be turned on and off shows the backtesting results of the performance of the different 4 rules across the 5 main IPO trading patterns from the Lifecycle trade mechanism (Rocket Ship, Late Boomer, One Hit Wonder, Pump and Dump or Stair Stepper). The Table shows across the 600 IPOs that have been studies what has been the average Gain (%) for each exit rule for each IPO Pattern and what has been the $ DrawDown for the same rule per IPO Pattern. This information is very useful to have on chart in order to decide which exit rules best match the given IPO pattern that you are looking at.
!!Always use proper risk management and position sizing!!
Please note that this script is intended for educational purposes and should not be considered as financial advice. Past performance is not indicative of future results, and every trader should carefully consider their trading strategy and risk tolerance before entering any trade.