PINE LIBRARY

MarketStructure

Atualizado
Library "MarketStructure"
Will draw out the market structure for the disired pivot length. The code is from my indicator "Marker structure" (tradingview.com/script/ud6AQSm2-Market-structure/).

Create(type, length, source, equalPivotsFactor, extendEqualPivotsZones, equalPivotsStyle, equalPivotsColor, alertFrequency)
  Call on each bar. Will create a Structure object.
  Parameters:
    type (int): the type of the Structure to create. 0 = internal, 1 = swing.
    length (int): The lenghts (left and right) for pivots to use.
    source (string): The source to be used for structural changes ('Close', 'High/low (aggresive)' (low in an uptrend) or 'High/low (passive)' (high in an uptrend)).
    equalPivotsFactor (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 (bool): Set to true if you want the equal pivots zones to be extended.
    equalPivotsStyle (string): Set the style of equal pivot zones.
    equalPivotsColor (color): Set the color of equal pivot zones.
    alertFrequency (string)
  Returns: The 'structure' object.

Pivot(structure)
  Sets the pivots in the structure.
  Parameters:
    structure (Structure)
  Returns: The 'structure' object.

PivotLabels(structure)
  Draws labels for the pivots found.
  Parameters:
    structure (Structure)
  Returns: The 'structure' object.

EqualHighOrLow(structure)
  Draws the boxsa for equal highs/lows. Also creates labels for the pivots included.
  Parameters:
    structure (Structure)
  Returns: The 'structure' object.

BreakOfStructure(structure)
  Will create lines when a break of strycture occures.
  Parameters:
    structure (Structure)
  Returns: The 'structure' object.

ChangeOfCharacter(structure)
  Will create lines when a change of character occures.
  Parameters:
    structure (Structure)
  Returns: The 'structure' object.

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).
    ChangeOfCharacterBroken (series bool): Sets to true if a change of character has happened.
    BreakOfStructureBroken (series bool): Sets to true if a break of structure has happened.

Structure
  Holds all the values for the market structure.
  Fields:
    Length (series int): Define the left and right lengths of the pivots used.
    Type (series int): 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.
    Source (series string): Set the source for structural chandeg. Can be 'Close', 'High/low (aggresive)' (low in an uptrend) or 'High/low (passive)' (high in an 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<box>): Holds the boxes for zones that contains equal highs.
    EqualLows (array<box>): Holds the boxes for zones that contains equal lows.
    BreakOfStructures (array<StructureBreak>): Holds all the break of structures within the trend (before a change of character).
    Pivots (array<Pivot>): All the pivots in the current trend, added with the latest first, this is cleared when the trend changes.
    AlertFrequency (series string): set the frequency for alerts.
Notas de Lançamento
v2

- Remove faultly commited 'AlertFrequency'
Notas de Lançamento
v3

- Mitigate error of removal of previous break of structure if a later pivot is not broken.
- Remove unused code
Notas de Lançamento
v4

- Add liquidation

Added:
Liqudity(priceAction)
  Will draw liquidity.
  Parameters:
    priceAction (PriceAction)

PriceAction
  Holds all the values for the general price action in the market structure.
  Fields:
    LiquidityPivotsHigh (array<Pivot>): All high pivots for liquidity.
    LiquidityPivotsLow (array<Pivot>): 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.

Updated:
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).
    ChangeOfCharacterBroken (series bool): Sets to true if a change of character has happened.
    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.
Notas de Lançamento
v5

- Mitigate bug causing old BOS appear when a higher pivot has been broken
Notas de Lançamento
v6

- Add alerts to break of structure and equal high/low
Notas de Lançamento
v7

- Remove 'ChangeOfCharcterBroken'. Pivots are now cleared when a change of character happens. This means that no break of stucture or change of character can happen on a pivot that was befor the change of character.
- To figure out if the current pivot was the latest of its type (high or low) the library now uses the last `bar_index`

Updated:
EqualHighOrLow(structure)
  Draws the boxes for equal highs/lows. Also creates labels for the pivots included.
  Parameters:
    structure (Structure)
  Returns: The 'structure' 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).
    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.
Notas de Lançamento
v8

- Change break of structure behaves. Don't need to check if the pivot is the latest and only delete the ones on the 'wrong side'
Notas de Lançamento
v9

- Keep all the pivots 'within' the pivot (when a CHoCH happens) and the break for CHoCHs, disable all for BOSs
Notas de Lançamento
v10

- Add 'VisualizeCurrent()' that 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 structure somehow).

Added:
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)
Notas de Lançamento
v11

- Introduce the concept of "CHoCH+" also called Change of Character plus. Labels for a change of character can now 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.


Updated:
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: The 'structure' object.
Notas de Lançamento
v12

- Add 'ChangeOfCharacterBreakBarIndex' that sets to 'bar_index' on a change of caracter.

Updated:
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).
    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.
    ChangeOfCharacterBreakBarIndex (series int): Sets to 'bar_index' if a change of character has happened.
Notas de Lançamento
v13

- 'BreakOfSrructure()' and 'ChanfeOfCharacter()' now returns a boolean saying if it happened or not.
- Remove obsolete 'Source', the library now always use close value.
- Remove 'ChanfeOfCharacterBreakBarIndex'

Updated:
Create(type, length, equalPivotsFactor, extendEqualPivotsZones, equalPivotsStyle, equalPivotsColor)
  Call on each bar. Will create a Structure object.
  Parameters:
    type (int): the type of the Structure to create. 0 = internal, 1 = swing.
    length (int): The lenghts (left and right) for pivots to use.
    equalPivotsFactor (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 (bool): Set to true if you want the equal pivots zones to be extended.
    equalPivotsStyle (string): Set the style of equal pivot zones.
    equalPivotsColor (color): Set the color of equal pivot zones.
  Returns: The 'structure' object.

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.

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).
    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.

Structure
  Holds all the values for the market structure.
  Fields:
    Length (series int): Define the left and right lengths of the pivots used.
    Type (series int): 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<box>): Holds the boxes for zones that contains equal highs.
    EqualLows (array<box>): Holds the boxes for zones that contains equal lows.
    BreakOfStructures (array<StructureBreak>): Holds all the break of structures within the trend (before a change of character).
    Pivots (array<Pivot>): All the pivots in the current trend, added with the latest first, this is cleared when the trend changes.
Notas de Lançamento
v14

- Split pivot length into left ang right

Updated:
Create(type, leftLength, rightLength, equalPivotsFactor, extendEqualPivotsZones, equalPivotsStyle, equalPivotsColor)
  Call on each bar. Will create a Structure object.
  Parameters:
    type (int): the type of the Structure to create. 0 = internal, 1 = swing.
    leftLength (int)
    rightLength (int)
    equalPivotsFactor (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 (bool): Set to true if you want the equal pivots zones to be extended.
    equalPivotsStyle (string): Set the style of equal pivot zones.
    equalPivotsColor (color): Set the color of equal pivot zones.
  Returns: The 'structure' object.

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 int): 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<box>): Holds the boxes for zones that contains equal highs.
    EqualLows (array<box>): Holds the boxes for zones that contains equal lows.
    BreakOfStructures (array<StructureBreak>): Holds all the break of structures within the trend (before a change of character).
    Pivots (array<Pivot>): All the pivots in the current trend, added with the latest first, this is cleared when the trend changes.
Notas de Lançamento
v15

- Fix multiple bugs using left pivot length instead of right
Notas de Lançamento
v16

- Reintroduce 'ChangeOfCharacterBroken'
- For a break of structure to happen the trend now needs to be explicitly bullish or bearish

Updated:
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).
    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.
    ChangeOfCharcterBroken (series bool)
Notas de Lançamento
v17

- Fix typo
- Set 'ChangeOfCharacterBroken' on change of character

Updated:
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).
    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.
Notas de Lançamento
v18

- The trend needs to be bullish or bearish to create a "CHoCH+"
Notas de Lançamento
v19

- Set pivots to breakable on a change of character
displaymarketstructurepriceaction

Biblioteca do Pine

De acordo com o verdadeiro espírito do TradingView, o autor publicou esse código Pine como uma biblioteca de código aberto para que outros programadores Pine de nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar essa biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização desse código em uma publicação é regida pelas Regras da Casa.

Aviso legal