PINE LIBRARY

MarketStructure

تم تحديثه
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.
ملاحظات الأخبار
v2

- Remove faultly commited 'AlertFrequency'
ملاحظات الأخبار
v3

- Mitigate error of removal of previous break of structure if a later pivot is not broken.
- Remove unused code
ملاحظات الأخبار
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.
ملاحظات الأخبار
v5

- Mitigate bug causing old BOS appear when a higher pivot has been broken
ملاحظات الأخبار
v6

- Add alerts to break of structure and equal high/low
ملاحظات الأخبار
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.
ملاحظات الأخبار
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'
ملاحظات الأخبار
v9

- Keep all the pivots 'within' the pivot (when a CHoCH happens) and the break for CHoCHs, disable all for BOSs
ملاحظات الأخبار
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)
ملاحظات الأخبار
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.
ملاحظات الأخبار
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.
ملاحظات الأخبار
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.
ملاحظات الأخبار
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.
ملاحظات الأخبار
v15

- Fix multiple bugs using left pivot length instead of right
ملاحظات الأخبار
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)
ملاحظات الأخبار
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.
ملاحظات الأخبار
v18

- The trend needs to be bullish or bearish to create a "CHoCH+"
ملاحظات الأخبار
v19

- Set pivots to breakable on a change of character
displaymarketstructurepriceaction

مكتبة باين

كمثال للقيم التي تتبناها TradingView، نشر المؤلف شيفرة باين كمكتبة مفتوحة المصدر بحيث يمكن لمبرمجي باين الآخرين من مجتمعنا استخدامه بحرية. تحياتنا للمؤلف! يمكنك استخدام هذه المكتبة بشكل خاص أو في منشورات أخرى مفتوحة المصدر، ولكن إعادة استخدام هذا الرمز في المنشور تحكمه قوانين الموقع.

إخلاء المسؤولية