PriceActionLibrary "PriceAction"
Hi all!
This library will help you to plot the market structure and liquidity. By now, the only part in the price action section is liquidity, but I plan to add more later on. The market structure will be split into two parts, 'Internal' and 'Swing' with separate pivot lengths. For these two trends it will show you:
• Break of structure (BOS)
• Change of character (CHoCH/CHoCH+) (mandatory)
• Equal high/low (EQH/EQL)
It's inspired by "Smart Money Concepts (SMC) " by LuxAlgo.
This library is now the same code as the code in my library 'MarketStructure', but it has evolved into a more price action oriented library than just a market structure library. This is more accurate and I will continue working on this library to keep it growing.
This code does not provide any examples, but you can look at my indicators 'Market structure' () and 'Order blocks' (), where I use the 'MarketStructure' library (which is the same code).
Market structure
Both of these market structures can be enabled/disabled by setting them to 'na'. The pivots lengths can be configured separately. The pivots found will be the 'base' of and will show you when price breaks it. When that happens a break of structure or a change of character will be created. The latest 5 pivots found within the current trends will be kept to take action on. They are cleared on a change of character, so nothing (break of structures or change of characters) can happen on pivots before a trend change. The internal market structure is shown with dashed lines and swing market structure is shown with solid lines.
Labels for a change of character can have either the text 'CHoCH' or 'CHoCH+'. A Change of Character plus is formed when price fails to form a higher high or a lower low before reversing. Note that a pivot that is created after the change of character might have a higher high or a lower low, thus not making the break a 'CHoCH+'. This is not changed after the pivot is found but is kept as is.
A break of structure is removed if an earlier pivot within the same trend is broken, i.e. another break of structure (with a longer distance) is created. Like in the images below, the first pivot (in the first image) is removed when an earlier pivot's higher price within the same trend is broken (the second image):
[image [https://www.tradingview.com/x/PRP6YtPA/
Equal high/lows have a configurable color setting and can be configured to be extended to the right. Equal high/lows are only possible if it's not been broken by price. A factor (percentage of width) of the Average True Length (of length 14) that the pivot must be within to to be considered an Equal high/low. Equal highs/lows can be of 2 pivots or more.
You are able to show the pivots that are used. "HH" (higher high), "HL" (higher low), "LH" (lower high), "LL" (lower low) and "H"/"L" (for pivots (high/low) when the trend has changed) are the labels used. There are also labels for break of structures ('BOS') and change of characters ('CHoCH' or 'CHoCH+'). The size of these texts is set in the 'FontSize' setting.
When programming I focused on simplicity and ease of read. I did not focus on performance, I will do so if it's a problem (haven't noticed it is one yet).
You can set alerts for when a change of character, break of structure or an equal high/low (new or an addition to a previously found) happens. The alerts that are fired are on 'once_per_bar_close' to avoid repainting. This has the drawback to alert you when the bar closes.
Price action
The indicator will create lines and zones for spotted liquidity. It will draw a line (with dotted style) at the price level that was liquidated, but it will also draw a zone from that level to the bar that broke the pivot high or low price. If that zone is large the liquidation is big and might be significant. This can be disabled in the settings. You can also change the confirmation candles (that does not close above or below the pivot level) needed after a liquidation and how many pivots back to look at.
The lines and boxes drawn will look like this if the color is orange:
Hope this is of help!
Will draw out the market structure for the disired pivot length.
Liqudity(liquidity)
Will draw liquidity.
Parameters:
liquidity (Liquidity) : The 'PriceAction.Liquidity' object.
Pivot(structure)
Sets the pivots in the structure.
Parameters:
structure (Structure)
PivotLabels(structure)
Draws labels for the pivots found.
Parameters:
structure (Structure)
EqualHighOrLow(structure)
Draws the boxes for equal highs/lows. Also creates labels for the pivots included.
Parameters:
structure (Structure)
BreakOfStructure(structure)
Will create lines when a break of strycture occures.
Parameters:
structure (Structure)
Returns: A boolean that represents if a break of structure was found or not.
ChangeOfCharacter(structure)
Will create lines when a change of character occures. This line will have a label with "CHoCH" or "CHoCH+".
Parameters:
structure (Structure)
Returns: A boolean that represents if a change of character was found or not.
VisualizeCurrent(structure)
Will create a box with a background for between the latest high and low pivots. This can be used as the current trading range (if the pivots broke strucure somehow).
Parameters:
structure (Structure)
StructureBreak
Holds drawings for a structure break.
Fields:
Line (series line) : The line object.
Label (series label) : The label object.
Pivot
Holds all the values for a found pivot.
Fields:
Price (series float) : The price of the pivot.
BarIndex (series int) : The bar_index where the pivot occured.
Type (series int) : The type of the pivot (-1 = low, 1 = high).
Time (series int) : The time where the pivot occured.
BreakOfStructureBroken (series bool) : Sets to true if a break of structure has happened.
LiquidityBroken (series bool) : Sets to true if a liquidity of the price level has happened.
ChangeOfCharacterBroken (series bool) : Sets to true if a change of character has happened.
Structure
Holds all the values for the market structure.
Fields:
LeftLength (series int) : Define the left length of the pivots used.
RightLength (series int) : Define the right length of the pivots used.
Type (series Type) : Set the type of the market structure. Two types can be used, 'internal' and 'swing' (0 = internal, 1 = swing).
Trend (series int) : This will be set internally and can be -1 = downtrend, 1 = uptrend.
EqualPivotsFactor (series float) : Set how the limits are for an equal pivot. This is a factor of the Average True Length (ATR) of length 14. If a low pivot is considered to be equal if it doesn't break the low pivot (is at a lower value) and is inside the previous low pivot + this limit.
ExtendEqualPivotsZones (series bool) : Set to true if you want the equal pivots zones to be extended.
ExtendEqualPivotsStyle (series string) : Set the style of equal pivot zones.
ExtendEqualPivotsColor (series color) : Set the color of equal pivot zones.
EqualHighs (array) : Holds the boxes for zones that contains equal highs.
EqualLows (array) : Holds the boxes for zones that contains equal lows.
BreakOfStructures (array) : Holds all the break of structures within the trend (before a change of character).
Pivots (array) : All the pivots in the current trend, added with the latest first, this is cleared when the trend changes.
FontSize (series int) : Holds the size of the font displayed.
AlertChangeOfCharacter (series bool) : Holds true or false if a change of character should be alerted or not.
AlertBreakOfStructure (series bool) : Holds true or false if a break of structure should be alerted or not.
AlerEqualPivots (series bool) : Holds true or false if equal highs/lows should be alerted or not.
Liquidity
Holds all the values for liquidity.
Fields:
LiquidityPivotsHigh (array) : All high pivots for liquidity.
LiquidityPivotsLow (array) : All low pivots for liquidity.
LiquidityConfirmationBars (series int) : The number of bars to confirm that a liquidity is valid.
LiquidityPivotsLookback (series int) : A number of pivots to look back for.
FontSize (series int) : Holds the size of the font displayed.
PriceAction
Holds all the values for the general price action and the market structures.
Fields:
Liquidity (Liquidity)
Swing (Structure) : Placeholder for all objects used for the swing market structure.
Internal (Structure) : Placeholder for all objects used for the internal market structure.
Liquidity
Liquidity Finder Library🔵 Introduction
You may intend to utilize the "Liquidity" detection capability in your indicators. Instead of writing it, you can import the "Liquidity Finder" library into your code. One of the advantages of this approach is time-saving and reduction in scripting errors.
🔵 Key Features
Identification of "Statics Liquidity"
Identification of "Dynamics Liquidity"
🔵 How to Use
Firstly, you can add the library to your code as shown in the example below :
import TFlab/LiquidityFinderLibrary/1 as Liq
The parameters of the "LLF" function are as follows :
sPP : A float variable ranging from 0 to 0.4. Increasing this number decreases the sensitivity of the "Statics Liquidity Line Detection" function and increases the number of detected lines. The default value is 0.3.
dPP : A float variable ranging from 0.4 to 1.95. Increasing this number increases the sensitivity of the "Dynamics Liquidity Line Detection" function and decreases the number of detected lines. The default value is 1.
SRs : An int variable. By default, it's set to 8. You can change this number to specify the periodicity of static liquidity pivot lines.
SRd : An int variable. By default, it's set to 3. You can change this number to specify the periodicity of dynamic liquidity pivot lines.
ShowHLLs : A bool variable. You can enable or disable the display of "High Statics Liquidity Line".
ShowLLLs : A bool variable. You can enable or disable the display of "Low Statics Liquidity Line".
ShowHLLd : A bool variable. You can enable or disable the display of "High Dynamics Liquidity Line".
ShowLLd : A bool variable. You can enable or disable the display of "High Dynamics Liquidity Line".
🟣Recommendation
You can use the following code snippet to import Liquidity Finder into your code for time-saving.
//import Library
import TFlab/LiquidityFinderLibrary/1 as Liq
//input
SLLS = input.float(0.30 , 'Statics Liquidity Line Sensitivity', maxval = 0.4 ,minval = 0.0, step = 0.01) // Statics Liquidity Line Sensitivity
DLLS = input.float(1.00 , 'Dynamics Liquidity Line Sensitivity', maxval = 1.95 ,minval = 0.4, step = 0.01) // Dynamics Liquidity Line Sensitivity
SPP = input.int(8 , 'Statics Period Pivot') // Statics Period Pivot
DPP = input.int(3 , 'Dynamics Period Pivot') // Dynamics Period Pivot
ShowSHLL = input.bool(true , 'Show Statics High Liquidity Line')
ShowSLLL = input.bool(true , 'Show Statics Low Liquidity Line')
ShowDHLL = input.bool(true , 'Show Dynamics High Liquidity Line')
ShowDLLL = input.bool(true , 'Show Dynamics Low Liquidity Line')
//call function
Liq.LLF(SPP,DPP,SLLS,DLLS,ShowSHLL,ShowSLLL,ShowDHLL,ShowDLLL)
NetLiquidityLibraryLibrary "NetLiquidityLibrary"
The Net Liquidity Library provides daily values for net liquidity. Net liquidity is measured as Fed Balance Sheet - Treasury General Account - Reverse Repo. Time series for each individual component included too.
get_net_liquidity_for_date(t)
Function takes date in timestamp form and returns the Net Liquidity value for that date. If date is not present, 0 is returned.
Parameters:
t : The timestamp of the date you are requesting the Net Liquidity value for.
Returns: The Net Liquidity value for the specified date.
get_net_liquidity()
Gets the Net Liquidity time series from Dec. 2021 to current. Dates that are not present are represented as 0.
Returns: The Net Liquidity time series.