PINE LIBRARY
更新済 OrderBlocks

Library "OrderBlocks"
This is a library I created that creates order blocks. It's originated from my indicator "Order blocks" (tradingview.com/script/gBnqr4b2-Order-blocks/). It will return a Zone object that can be used to draw an order block. If you want to see how that is done you can check out my indicar that uses the same logic.
Create(settings)
Creates an order block if one is found according to the settings parameter.
Parameters:
settings (Settings): set all values in this parameter to define the settings for the order block creation.
Returns: a Zone object if an order block is found, na otherwise
Zone
Fields:
Time (series int)
TimeClose (series int)
High (series float)
Low (series float)
ReactionLimit (series float)
TouchedZone (Zone type from mickes/Touched/14)
Type (series int)
Zones
Fields:
Index (series int)
Maximum (series int)
Zones (array<Zone>)
Remove (Zone)
Settings
Fields:
TakeOut (series bool)
ReactionFactor (series float)
Type (series string)
ConsecutiveRisingOrFalling (series bool)
FairValueGap (series bool)
This is a library I created that creates order blocks. It's originated from my indicator "Order blocks" (tradingview.com/script/gBnqr4b2-Order-blocks/). It will return a Zone object that can be used to draw an order block. If you want to see how that is done you can check out my indicar that uses the same logic.
Create(settings)
Creates an order block if one is found according to the settings parameter.
Parameters:
settings (Settings): set all values in this parameter to define the settings for the order block creation.
Returns: a Zone object if an order block is found, na otherwise
Zone
Fields:
Time (series int)
TimeClose (series int)
High (series float)
Low (series float)
ReactionLimit (series float)
TouchedZone (Zone type from mickes/Touched/14)
Type (series int)
Zones
Fields:
Index (series int)
Maximum (series int)
Zones (array<Zone>)
Remove (Zone)
Settings
Fields:
TakeOut (series bool)
ReactionFactor (series float)
Type (series string)
ConsecutiveRisingOrFalling (series bool)
FairValueGap (series bool)
リリースノート
Add "Visual" object that can be used for displaying order blocks.Added:
Visual
Fields:
Boxes (array<box>)
Lines (array<line>)
Labels (array<label>)
Updated:
Zone
Fields:
Time (series int)
TimeClose (series int)
High (series float)
Low (series float)
ReactionLimit (series float)
TouchedZone (Zone type from mickes/Touched/14)
Visual (Visual)
Type (series int)
リリースノート
- Remove faultly commuted 'box.new()'リリースノート
v4- Add all the visual creation/modification methods from my indicator "Order blocks" (tradingview.com/script/gBnqr4b2-Order-blocks/)
Added:
method Replace(zones, zone, settings)
Replaces a zone in the 'Zones' field in the 'Zones' type.
Namespace types: Zones
Parameters:
zones (Zones): The bucket of the zones created.
zone (Zone): The current zone.
settings (Settings): Set all values in this parameter to define the settings for the order blocks.
Returns: The 'zone' obkject.
method Remove(zones, settings)
Removes the zone in 'zones.Remove' and its visuals. The visuals will be replaced if 'settings.KeepHistoryZones' is true.
Namespace types: Zones
Parameters:
zones (Zones): The current zone.
settings (Settings): Set all values in this parameter to define the settings for the order blocks.
Returns: The 'zone' obkject.
method Draw(zone, settings)
Draws all the required visuals for the 'zone' according to the 'settings'.
Namespace types: Zone
Parameters:
zone (Zone)
settings (Settings): set all values in this parameter to define the settings for the order block creation.
Returns: The 'zone' obkject.
method Interactions(zones, settings)
Creates an order block if one is found according to the settings parameter.
Namespace types: Zones
Parameters:
zones (Zones)
settings (Settings): set all values in this parameter to define the settings for the order block creation.
Updated:
Settings
Fields:
TakeOut (series bool)
ReactionFactor (series float)
Type (series string)
ConsecutiveRisingOrFalling (series bool)
FairValueGap (series bool)
MaximumZones (series int)
KeepHistoryZones (series bool)
NewZonesColor (series color)
ReplacedZonesColor (series color)
BrokenZonesColor (series color)
ShowReaction (series bool)
RemoveBrokenZones (series bool)
CreateCreationZone (series bool)
リリースノート
v5- set descriptions
- add alerts
Updated:
Visual
Holds the visual elements or the zone.
Fields:
Boxes (array<box>): All the visual boxes.
Lines (array<line>): All the visual lines.
Labels (array<label>): All the visual labels.
Zone
Holds the values for visuals for the zone and to handle interactions (retests, false breakouts and breakouts).
Fields:
Time (series int): The start time of the zone creation.
TimeClose (series int): The end time of zone creation.
High (series float): The maximimum price of the zone.
Low (series float): The minimum price of the zone.
ReactionLimit (series float): Set a factor (%) of the Average True Range (of length 14) that the total reaction must have.
TouchedZone (Zone type from mickes/Touched/14): Zone object that will be created and sent to the library 'Touched'.
Visual (Visual): An object that holds the visual elements for the zone.
Type (series int): Defines if the found zone is bullish (1) or bearish (-1).
Zones
Holds the values for the charts zones.
Fields:
Index (series int): The current index to use when a new zone appears. This is changed when a new zone appears.
Maximum (series int): The maximum number of zones to show.
Zones (array<Zone>): The currently active zones.
Remove (Zone): Reprsents the zone that will be replaced.
Settings
The settings for the creation of order blocks. You will need to set all the containing values in here.
Fields:
TakeOut (series bool): Set to true if you want the base candle of the order block to have to be highet or lower (take out) then the previous candle.
ReactionFactor (series float): Set the factor (%) of the Average True Range (of length 14) that the total reaction must have.
Type (series string): The type of the order block. Can be "Both", "Bullish" or "Bearish".
ConsecutiveRisingOrFalling (series bool): Set to true if you want the 3 candles in the reaction to be consecutivly rising or falling.
FairValueGap (series bool): Set to true if the last and the 3rd (base) candles wicks to don't overlap and create a so called fair value gap or an imbalance.
MaximumZones (series int): Define the maximum of active order blocks.
KeepHistoryZones (series bool): Set to true if you want removed (replaced or broken) zones to be drawn.
NewZonesColor (series color): The color of new order blocks.
ReplacedZonesColor (series color): The color of replaced order blocks.
BrokenZonesColor (series color): The color of broken order blocks.
ShowReaction (series bool): Set if a line should be drawn at the reaction limit.
RemoveBrokenZones (series bool): Enable to remove broken order blocks.
CreateCreationZone (series bool): Set to true if you want a box with a border to be drawn at the creation of the zone. This is usefull when the order blocks come from a higher timeframe, but not from a lower.
AlertRetests (series bool): Enable if you want alerts to fire when the 'Touched' library signals that a retest of the order block has occured.
AlertFalseBreakouts (series bool): Enable if you want alerts to fire when the 'Touched' library signals that a false breakout of the order block has occured.
AlertBreakouts (series bool): Enable if you want alerts to fire when the 'Touched' library signals that a breakout of the order block has occured.
AlertMessageFormat (series string): Set the format of the fired alert uppon 'Touched' library signals. Need to be in the format of '{0} on order block from ...' where '{0}' is replaced with 'retest', 'false breakout' or 'breakout'.
リリースノート
v6- if 'CreateCreationZone' is false the drawn box will start at time_close - time.
- Added "If this is false the 'Draw()' function will start at 'time - time_close'." to the description of 'CreateCreationZone' in the 'Settings' object.
リリースノート
v7- Consecutive rising or falling candles now needs to close above/below the previous candle
- Mitigate bug causing bearish order blocks to have to have too many consecutive falling candles
リリースノート
v8- Consecutive rising or falling candles now use 'hl2' value
リリースノート
v9- Move history reference values to global scope
リリースノート
v10- Check for 'AlertRetests' and 'AlertFalseBrwakouts'
リリースノート
v11- Split out the pivots detection from 'Create()' to its own function 'Pivots()' that can be called on each bar
Added:
Pivots(settings)
Creates pivots (high and low) to be passed to 'Create()'.
Parameters:
settings (Settings): set all values in this parameter to define the settings for the order block creation.
Returns: a tuple containing two pivot values (high and low) or 'na'
Updated:
Create(settings, pivotHigh, pivotLow)
Creates an order block if one is found according to the settings parameter.
Parameters:
settings (Settings): set all values in this parameter to define the settings for the order block creation.
pivotHigh (float): The high pivot to use.
pivotLow (float): The low pivot to use.
Returns: a Zone object if an order block is found, na otherwise
リリースノート
v12- Add setting to keep labels on historical zones
Updated:
Settings
The settings for the creation of order blocks. You will need to set all the containing values in here.
Fields:
TakeOut (series bool): Set to true if you want the base candle of the order block to have to be highet or lower (take out) then the previous candle.
ReactionFactor (series float): Set the factor (%) of the Average True Range (of length 14) that the total reaction must have.
Type (series string): The type of the order block. Can be "Both", "Bullish" or "Bearish".
ConsecutiveRisingOrFalling (series bool): Set to true if you want the 3 candles in the reaction to be consecutivly rising or falling.
FairValueGap (series bool): Set to true if the last and the 3rd (base) candles wicks to don't overlap and create a so called fair value gap or an imbalance.
MaximumZones (series int): Define the maximum of active order blocks.
KeepHistoryZones (series bool): Set to true if you want removed (replaced or broken) zones to be drawn.
NewZonesColor (series color): The color of new order blocks.
ReplacedZonesColor (series color): The color of replaced order blocks.
BrokenZonesColor (series color): The color of broken order blocks.
ShowReaction (series bool): Set if a line should be drawn at the reaction limit.
RemoveBrokenZones (series bool): Enable to remove broken order blocks.
CreateCreationZone (series bool): Set to true if you want a box with a border to be drawn at the creation of the zone. This is usefull when the order blocks come from a higher timeframe, but not from a lower. If this is false the 'Draw()' function will start at 'time - time_close'.
AlertRetests (series bool): Enable if you want alerts to fire when the 'Touched' library signals that a retest of the order block has occured.
AlertFalseBreakouts (series bool): Enable if you want alerts to fire when the 'Touched' library signals that a false breakout of the order block has occured.
AlertBreakouts (series bool): Enable if you want alerts to fire when the 'Touched' library signals that a breakout of the order block has occured.
AlertMessageFormat (series string): Set the format of the fired alert uppon 'Touched' library signals. Need to be in the format of '{0} on order block from ...' where '{0}' is replaced with 'retest', 'false breakout' or 'breakout'.
KeepHistoryLabels (series bool)
リリースノート
v13- remove redundant returns of the 'zone' object
Updated:
Replace(zones, zone, settings)
Replaces a zone in the 'Zones' field in the 'Zones' type.
Parameters:
zones (Zones): The bucket of the zones created.
zone (Zone): The current zone.
settings (Settings): Set all values in this parameter to define the settings for the order blocks.
Remove(zones, settings)
Removes the zone in 'zones.Remove' and its visuals. The visuals will be replaced if 'settings.KeepHistoryZones' is true.
Parameters:
zones (Zones): The current zone.
settings (Settings): Set all values in this parameter to define the settings for the order blocks.
Draw(zone, settings)
Draws all the required visuals for the 'zone' according to the 'settings'.
Parameters:
zone (Zone)
settings (Settings): set all values in this parameter to define the settings for the order block creation.
リリースノート
v14- add 'Latest..BarIndex' for retests, false breakouts and breakouts
- mitigate bug using the wrong 'alert enabled'
Updated:
Zone
Holds the values for visuals for the zone and to handle interactions (retests, false breakouts and breakouts).
Fields:
Time (series int): The start time of the zone creation.
TimeClose (series int): The end time of zone creation.
High (series float): The maximimum price of the zone.
Low (series float): The minimum price of the zone.
ReactionLimit (series float): Set a factor (%) of the Average True Range (of length 14) that the total reaction must have.
TouchedZone (Zone type from mickes/Touched/14): Zone object that will be created and sent to the library 'Touched'.
Visual (Visual): An object that holds the visual elements for the zone.
Type (series int): Defines if the found zone is bullish (1) or bearish (-1).
LatestRetestBarIndex (series int)
LatestFalseBreakoutBarIndex (series int)
LatestBreakoutBarIndex (series int)
リリースノート
v15- Change the time settings in the 'Zone' to be able to create correct zones for higher timeframes, the current timeframe and lower timeframes
- The replaced zone can now be multiple zones
- The colors of the zones are now different for bullish/bearish zones and not 'new', 'replaced' and 'broken' zones
Updated:
Interactions(zones, settings)
Creates an order block if one is found according to the settings parameter.
Parameters:
zones (array<Zone>)
settings (Settings): set all values in this parameter to define the settings for the order block creation.
Zone
Holds the values for visuals for the zone and to handle interactions (retests, false breakouts and breakouts).
Fields:
BaseTimeClose (series int): The time close for the start of the zone.
FoundTimeClose (series int): The time close for the zone when it's found.
ChartBaseTime (series int): The time for the start of the zone according to the chart bar.
High (series float): The maximimum price of the zone.
Low (series float): The minimum price of the zone.
ReactionLimit (series float): Set a factor (%) of the Average True Range (of length 14) that the total reaction must have.
TouchedZone (Zone type from mickes/Touched/14): Zone object that will be created and sent to the library 'Touched'.
Visual (Visual): An object that holds the visual elements for the zone.
SourceTimeframeSeconds (series int)
Type (series int): Defines if the found zone is bullish (1) or bearish (-1).
LatestRetestBarIndex (series int)
LatestFalseBreakoutBarIndex (series int)
LatestBreakoutBarIndex (series int)
BarIndex (series int)
Removed (series bool)
Zones
Holds the values for the charts zones.
Fields:
Index (series int): The current index to use when a new zone appears. This is changed when a new zone appears.
Maximum (series int): The maximum number of zones to show.
Zones (array<Zone>): The currently active zones.
Removes (array<Zone>): Reprsents the zones that will be replaced.
Settings
The settings for the creation of order blocks. You will need to set all the containing values in here.
Fields:
TakeOut (series bool): Set to true if you want the base candle of the order block to have to be highet or lower (take out) then the previous candle.
ReactionFactor (series float): Set the factor (%) of the Average True Range (of length 14) that the total reaction must have.
Type (series string): The type of the order block. Can be "Both", "Bullish" or "Bearish".
ConsecutiveRisingOrFalling (series bool): Set to true if you want the 3 candles in the reaction to be consecutivly rising or falling.
FairValueGap (series bool): Set to true if the last and the 3rd (base) candles wicks to don't overlap and create a so called fair value gap or an imbalance.
MaximumZones (series int): Define the maximum of active order blocks.
KeepHistoryZones (series bool): Set to true if you want removed (replaced or broken) zones to be drawn.
Bull (series color): The color of bullish order blocks.
Bear (series color): The color of bearish order blocks.
ShowReaction (series bool): Set if a line should be drawn at the reaction limit.
RemoveBrokenZones (series bool): Enable to remove broken order blocks.
CreateCreationZone (series bool): Set to true if you want a box with a border to be drawn at the creation of the zone. This is usefull when the order blocks come from a higher timeframe, but not from a lower. If this is false the 'Draw()' function will start at 'time - time_close'.
AlertRetests (series bool): Enable if you want alerts to fire when the 'Touched' library signals that a retest of the order block has occured.
AlertFalseBreakouts (series bool): Enable if you want alerts to fire when the 'Touched' library signals that a false breakout of the order block has occured.
AlertBreakouts (series bool): Enable if you want alerts to fire when the 'Touched' library signals that a breakout of the order block has occured.
AlertMessageFormat (series string): Set the format of the fired alert uppon 'Touched' library signals. Need to be in the format of '{0} on order block from ...' where '{0}' is replaced with 'retest', 'false breakout' or 'breakout'.
KeepHistoryLabels (series bool): Set if labels should be kept on historical zones and not only active zones.
リリースノート
v16- Move '_chartTime2' to 'Create()' function
Pineライブラリ
TradingViewの精神に則り、作者はPineコードをオープンソースライブラリとして公開し、コミュニティ内の他のPineプログラマーが再利用できるようにしました。作者に敬意を表します!このライブラリを個人的に、または他のオープンソースの投稿で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。
Pineライブラリ
TradingViewの精神に則り、作者はPineコードをオープンソースライブラリとして公開し、コミュニティ内の他のPineプログラマーが再利用できるようにしました。作者に敬意を表します!このライブラリを個人的に、または他のオープンソースの投稿で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。