PINE LIBRARY
アップデート済 Helper Lib by tristanlee85

Library "helpers"
This library offers various functions and types based on the algorithmic
concepts as authored by ICT.
kv(key, value)
Returns a string of the key/value set, suitable for debug logging
Parameters:
key (string)
value (string)
Returns: A string formatted as "{key}: {value}"
kv(key, value)
Parameters:
key (string)
value (int)
kv(key, value)
Parameters:
key (string)
value (float)
kv(key, value)
Parameters:
key (string)
value (bool)
method enable(this, enable)
Enable/Disable debug logging
Namespace types: Debugger
Parameters:
this (Debugger)
enable (bool): Set to `true` by default.
method group(this, label)
Creates a group label for nested debug() invocations
Namespace types: Debugger
Parameters:
this (Debugger)
label (string)
method groupEnd(this, label)
Ends the specified debug group
Namespace types: Debugger
Parameters:
this (Debugger)
label (string)
method log(this, s, arg1, arg2, arg3, arg4, arg5)
Logs the param values if debug mode is enabled
Namespace types: Debugger
Parameters:
this (Debugger)
s (string): Title of the log message
arg1 (string)
arg2 (string)
arg3 (string)
arg4 (string)
arg5 (string)
method logIf(this, expr, s, arg1, arg2, arg3, arg4, arg5)
Same behavior as debug() except will only log if the passed expression is true
Namespace types: Debugger
Parameters:
this (Debugger)
expr (bool): Boolean expression to determine if debug logs should be logged
s (string): Title of the log message
arg1 (string)
arg2 (string)
arg3 (string)
arg4 (string)
arg5 (string)
style_getLineStyleFromType(opt)
Returns the corresponding line style constant for the given LineStyleType
Parameters:
opt (series LineStyleType): The selected line style type
Returns: The Pine Script line style constant
style_getTextSizeFromType(opt)
Returns the corresponding text size constant for the given TextSizeType
Parameters:
opt (series TextSizeType): The selected text size type
Returns: The Pine Script text size constant
style_getTextHAlignFromType(t)
Returns the corresponding horizontal text align constant for the given HAlignType
Parameters:
t (series HAlignType): The selected text align type
Returns: The Pine Script text align constant
style_getTextVAlignFromType(t)
Returns the corresponding vertical text align constant for the given VAlignType
Parameters:
t (series VAlignType): The selected text align type
Returns: The Pine Script text align constant
format_sentimentType(sentiment, pd)
Used to produce a string with the sentiment and PD array type (e.g., "+FVG")
Parameters:
sentiment (series SentimentType): The sentiment value (e.g., SentimentType.BULLISH)
pd (series PDArrayType): The price data array (e.g., PDArrayType.FVG)
Returns: A formatted string with the sentiment and PD array (e.g., "+FVG")
format_timeToString(timestamp)
Formats a UNIX timestamp into a date and time string based on predefined formats
Parameters:
timestamp (int): The UNIX timestamp to format
Returns: A formatted string as "MM-dd (E) - HH:mm"
method init(this)
Initializes the session and validates the configuration. This MUST be called immediately after creating a new instance.
Namespace types: Session
Parameters:
this (Session): The Session object reference
Returns: The Session object (chainable) or throws a runtime error if invalid
method isActive(this, _time)
Determines if the session is active based on the current bar time
Namespace types: Session
Parameters:
this (Session): The Session object reference
_time (int)
Returns: `true` if the session is currently active; `false` otherwise
method draw(this)
Draws the line and optional label
Namespace types: LineLabel
Parameters:
this (LineLabel): The LineLabel object reference
Returns: The LineLabel object (chainable)
method extend(this, x)
Extends the line and label right to the specified bar index
Namespace types: LineLabel
Parameters:
this (LineLabel): The LineLabel object reference
x (int): The bar index to extend to
Returns: The LineLabel object (chainable)
method destroy(this)
Removes the line and label from the chart
Namespace types: LineLabel
Parameters:
this (LineLabel): The LineLabel object reference
isFVG(includeVI, barIdx)
Checks if the previous bars form a Fair Value Gap (FVG)
Parameters:
includeVI (bool): If true, includes Volume Imbalance in the FVG calculation
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A Gap object if a FVG is detected; otherwise, `na`
isVolumeImbalance(barIdx)
Checks if the previous bars form a Volume Imbalance (VI)
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A Gap object if a VI is detected; otherwise, `na`
isLiquidityVoid(barIdx)
Checks if the previous bars form a Liquidity Void (LV)
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A Gap object if an LV is detected; otherwise, `na`
isSwingPoint(barIdx)
Checks if the previous bars form a swing point
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A SwingPoint object if a swing point is detected; otherwise, `na`
Debugger
A debug logging utility with group support
Fields:
enabled (series bool)
_debugGroupStack (array<string>)
Session
Defines a trading session with a name and time range. When creating a new instance of this type, you MUST call init() immediately.
Fields:
name (series string): A display-friendly name (e.g., "NY AM")
session (series string): A string defining the session time range (e.g., "1300-1400")
enabled (series bool): Optional flag for custom logic; defaults to false
start (series int): UNIX time representing the session start (set via isActive())
end (series int): UNIX time representing the session end (set via isActive())
_t (series int)
_start_HH (series float)
_start_mm (series float)
_end_HH (series float)
_end_mm (series float)
Gap
Represents a price inefficiency (gap) with details on sentiment and price levels
Fields:
type (series SentimentType): The sentiment of the gap (e.g., SentimentType.BULLISH)
name (series string): A display-friendly name (e.g., "+FVG")
startTime (series int): UNIX time value for the gap's start
endTime (series int): UNIX time value for the gap's end
startIndex (series int): Bar index where the gap starts
endIndex (series int): Bar index where the gap ends
gapLow (series float): The lowest price level of the gap
gapHigh (series float): The highest price level of the gap
ce (series float): The consequent encroachment level of the gap
SwingPoint
Represents a swing point with details on type and price level
Fields:
type (series SwingPointType): The type of swing point (e.g., SwingPointType.HIGH)
time (series int): UNIX time value for the swing point
barIdx (series int): Bar index where the swing point occurs
price (series float): The price level of the swing point which is either the high or low of the middle bar
LineLabel
Combines a line and box type to produce a line with a label that is properly aligned
Fields:
x (series int): The X-axis starting point as a bar index
y (series float): The Y-axis starting point as the price level
color (series color): Both the line and text color
width (series int): Thickness of the line
label (series string): Text to display
showLabel (series bool): Boolean to conditionally show/hide the label (default is false)
lineStyle (series LineStyleType): The style of the line
textSize (series TextSizeType)
_b (series box)
_l (series line)
This library offers various functions and types based on the algorithmic
concepts as authored by ICT.
kv(key, value)
Returns a string of the key/value set, suitable for debug logging
Parameters:
key (string)
value (string)
Returns: A string formatted as "{key}: {value}"
kv(key, value)
Parameters:
key (string)
value (int)
kv(key, value)
Parameters:
key (string)
value (float)
kv(key, value)
Parameters:
key (string)
value (bool)
method enable(this, enable)
Enable/Disable debug logging
Namespace types: Debugger
Parameters:
this (Debugger)
enable (bool): Set to `true` by default.
method group(this, label)
Creates a group label for nested debug() invocations
Namespace types: Debugger
Parameters:
this (Debugger)
label (string)
method groupEnd(this, label)
Ends the specified debug group
Namespace types: Debugger
Parameters:
this (Debugger)
label (string)
method log(this, s, arg1, arg2, arg3, arg4, arg5)
Logs the param values if debug mode is enabled
Namespace types: Debugger
Parameters:
this (Debugger)
s (string): Title of the log message
arg1 (string)
arg2 (string)
arg3 (string)
arg4 (string)
arg5 (string)
method logIf(this, expr, s, arg1, arg2, arg3, arg4, arg5)
Same behavior as debug() except will only log if the passed expression is true
Namespace types: Debugger
Parameters:
this (Debugger)
expr (bool): Boolean expression to determine if debug logs should be logged
s (string): Title of the log message
arg1 (string)
arg2 (string)
arg3 (string)
arg4 (string)
arg5 (string)
style_getLineStyleFromType(opt)
Returns the corresponding line style constant for the given LineStyleType
Parameters:
opt (series LineStyleType): The selected line style type
Returns: The Pine Script line style constant
style_getTextSizeFromType(opt)
Returns the corresponding text size constant for the given TextSizeType
Parameters:
opt (series TextSizeType): The selected text size type
Returns: The Pine Script text size constant
style_getTextHAlignFromType(t)
Returns the corresponding horizontal text align constant for the given HAlignType
Parameters:
t (series HAlignType): The selected text align type
Returns: The Pine Script text align constant
style_getTextVAlignFromType(t)
Returns the corresponding vertical text align constant for the given VAlignType
Parameters:
t (series VAlignType): The selected text align type
Returns: The Pine Script text align constant
format_sentimentType(sentiment, pd)
Used to produce a string with the sentiment and PD array type (e.g., "+FVG")
Parameters:
sentiment (series SentimentType): The sentiment value (e.g., SentimentType.BULLISH)
pd (series PDArrayType): The price data array (e.g., PDArrayType.FVG)
Returns: A formatted string with the sentiment and PD array (e.g., "+FVG")
format_timeToString(timestamp)
Formats a UNIX timestamp into a date and time string based on predefined formats
Parameters:
timestamp (int): The UNIX timestamp to format
Returns: A formatted string as "MM-dd (E) - HH:mm"
method init(this)
Initializes the session and validates the configuration. This MUST be called immediately after creating a new instance.
Namespace types: Session
Parameters:
this (Session): The Session object reference
Returns: The Session object (chainable) or throws a runtime error if invalid
method isActive(this, _time)
Determines if the session is active based on the current bar time
Namespace types: Session
Parameters:
this (Session): The Session object reference
_time (int)
Returns: `true` if the session is currently active; `false` otherwise
method draw(this)
Draws the line and optional label
Namespace types: LineLabel
Parameters:
this (LineLabel): The LineLabel object reference
Returns: The LineLabel object (chainable)
method extend(this, x)
Extends the line and label right to the specified bar index
Namespace types: LineLabel
Parameters:
this (LineLabel): The LineLabel object reference
x (int): The bar index to extend to
Returns: The LineLabel object (chainable)
method destroy(this)
Removes the line and label from the chart
Namespace types: LineLabel
Parameters:
this (LineLabel): The LineLabel object reference
isFVG(includeVI, barIdx)
Checks if the previous bars form a Fair Value Gap (FVG)
Parameters:
includeVI (bool): If true, includes Volume Imbalance in the FVG calculation
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A Gap object if a FVG is detected; otherwise, `na`
isVolumeImbalance(barIdx)
Checks if the previous bars form a Volume Imbalance (VI)
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A Gap object if a VI is detected; otherwise, `na`
isLiquidityVoid(barIdx)
Checks if the previous bars form a Liquidity Void (LV)
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A Gap object if an LV is detected; otherwise, `na`
isSwingPoint(barIdx)
Checks if the previous bars form a swing point
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A SwingPoint object if a swing point is detected; otherwise, `na`
Debugger
A debug logging utility with group support
Fields:
enabled (series bool)
_debugGroupStack (array<string>)
Session
Defines a trading session with a name and time range. When creating a new instance of this type, you MUST call init() immediately.
Fields:
name (series string): A display-friendly name (e.g., "NY AM")
session (series string): A string defining the session time range (e.g., "1300-1400")
enabled (series bool): Optional flag for custom logic; defaults to false
start (series int): UNIX time representing the session start (set via isActive())
end (series int): UNIX time representing the session end (set via isActive())
_t (series int)
_start_HH (series float)
_start_mm (series float)
_end_HH (series float)
_end_mm (series float)
Gap
Represents a price inefficiency (gap) with details on sentiment and price levels
Fields:
type (series SentimentType): The sentiment of the gap (e.g., SentimentType.BULLISH)
name (series string): A display-friendly name (e.g., "+FVG")
startTime (series int): UNIX time value for the gap's start
endTime (series int): UNIX time value for the gap's end
startIndex (series int): Bar index where the gap starts
endIndex (series int): Bar index where the gap ends
gapLow (series float): The lowest price level of the gap
gapHigh (series float): The highest price level of the gap
ce (series float): The consequent encroachment level of the gap
SwingPoint
Represents a swing point with details on type and price level
Fields:
type (series SwingPointType): The type of swing point (e.g., SwingPointType.HIGH)
time (series int): UNIX time value for the swing point
barIdx (series int): Bar index where the swing point occurs
price (series float): The price level of the swing point which is either the high or low of the middle bar
LineLabel
Combines a line and box type to produce a line with a label that is properly aligned
Fields:
x (series int): The X-axis starting point as a bar index
y (series float): The Y-axis starting point as the price level
color (series color): Both the line and text color
width (series int): Thickness of the line
label (series string): Text to display
showLabel (series bool): Boolean to conditionally show/hide the label (default is false)
lineStyle (series LineStyleType): The style of the line
textSize (series TextSizeType)
_b (series box)
_l (series line)
リリースノート
v2Added:
parseSessionString(session)
Parses a session string (e.g., "1300-1400") to start/end hour and minute numbers
Parameters:
session (string): The session string (e.g., "1300-1400")
Returns: A tuple `[start_HH, start_mm, end_HH, end_mm]` of float values
リリースノート
v3Updated:
method draw(this, _xloc)
Draws the line and optional label
Namespace types: LineLabel
Parameters:
this (LineLabel): The LineLabel object reference
_xloc (string)
Returns: The LineLabel object (chainable)
リリースノート
v4Updated:
style_getTextHAlignFromType(t, invert)
Returns the corresponding horizontal text align constant for the given HAlignType
Parameters:
t (series HAlignType): The selected text align type
invert (bool): Whether to invert the text alignment type (left > right | right > left)
Returns: The Pine Script text align constant
method draw(this, xloc)
Draws the line and optional label
Namespace types: LineLabel
Parameters:
this (LineLabel): The LineLabel object reference
xloc (string)
Returns: The LineLabel object (chainable)
リリースノート
v5Updated:
style_getTextVAlignFromType(t, invert)
Returns the corresponding vertical text align constant for the given VAlignType
Parameters:
t (series VAlignType): The selected text align type
invert (bool): Whether to invert the text alignment type (top > bottom | bottom > top)
Returns: The Pine Script text align constant
リリースノート
v6リリースノート
v7Added:
method get(this)
Gets the OHLCBT as a tuple
Namespace types: OHLC
Parameters:
this (OHLC): The OHLC object reference
Returns: [float, float, float, float, int, int]
OHLC
Simple type for referencing OHLC, bar index, and time
Fields:
data (array<float>): Values as an array (e.g., OHLC.new(array.from(open, high, low, close, bar_index, time)))
Updated:
isFVG(includeVI, barIdx, data)
Checks if the previous bars form a Fair Value Gap (FVG)
Parameters:
includeVI (bool): If true, includes Volume Imbalance in the FVG calculation
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
data (OHLC)
Returns: A Gap object if a FVG is detected; otherwise, `na`
isVolumeImbalance(barIdx, data)
Checks if the previous bars form a Volume Imbalance (VI)
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
data (OHLC)
Returns: A Gap object if a VI is detected; otherwise, `na`
isLiquidityVoid(barIdx, data)
Checks if the previous bars form a Liquidity Void (LV)
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
data (OHLC)
Returns: A Gap object if an LV is detected; otherwise, `na`
isSwingPoint(barIdx, data)
Checks if the previous bars form a swing point
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
data (OHLC)
Returns: A SwingPoint object if a swing point is detected; otherwise, `na`
リリースノート
v8Added:
method getFlat(this)
Namespace types: Bar
Parameters:
this (Bar)
Bar
Simple type for referencing bar-related values
Fields:
_time (series int)
_bar_index (series int)
ohlc (OHLC)
_isnew (series bool)
_isconfirmed (series bool)
Updated:
method init(this)
Namespace types: Bar
Parameters:
this (Bar)
method get(this)
Namespace types: Bar
Parameters:
this (Bar)
isFVG(includeVI, barIdx, data)
Checks if the previous bars form a Fair Value Gap (FVG)
Parameters:
includeVI (bool): If true, includes Volume Imbalance in the FVG calculation
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
data (Bar)
Returns: A Gap object if a FVG is detected; otherwise, `na`
isVolumeImbalance(barIdx, data)
Checks if the previous bars form a Volume Imbalance (VI)
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
data (Bar)
Returns: A Gap object if a VI is detected; otherwise, `na`
isLiquidityVoid(barIdx, data)
Checks if the previous bars form a Liquidity Void (LV)
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
data (Bar)
Returns: A Gap object if an LV is detected; otherwise, `na`
isSwingPoint(barIdx, data)
Checks if the previous bars form a swing point
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
data (Bar)
Returns: A SwingPoint object if a swing point is detected; otherwise, `na`
OHLC
Simple type for referencing OHLC
Fields:
data (array<float>): Values as an array (e.g., OHLC.new(array.from(open, high, low, close)))
リリースノート
v9Updated OHLC.get() logic
リリースノート
v10Updated:
isFVG(includeVI, barIdx)
Checks if the previous bars form a Fair Value Gap (FVG)
Parameters:
includeVI (bool): If true, includes Volume Imbalance in the FVG calculation
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A Gap object if a FVG is detected; otherwise, `na`
リリースノート
v11Updated:
method init(this)
Initializes the session and validates the configuration. This MUST be called immediately after creating a new instance.
Namespace types: Session
Parameters:
this (Session): The Session object reference
Returns: The Session object (chainable) or throws a runtime error if invalid
isVolumeImbalance(barIdx)
Checks if the previous bars form a Volume Imbalance (VI)
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A Gap object if a VI is detected; otherwise, `na`
isLiquidityVoid(barIdx)
Checks if the previous bars form a Liquidity Void (LV)
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A Gap object if an LV is detected; otherwise, `na`
isSwingPoint(barIdx)
Checks if the previous bars form a swing point
Parameters:
barIdx (int): The index of the bar to check from (default is 0 for the current bar)
Returns: A SwingPoint object if a swing point is detected; otherwise, `na`
Removed:
method get(this)
method getFlat(this)
OHLC
Simple type for referencing OHLC
Bar
Simple type for referencing bar-related values
リリースノート
Release Notes - v12New: Daily Range Levels
The levels price refers back to intraday. Each daily candle is measured into its full high-to-low range, plus its upper or lower wick when that wick is large enough to be a range in its own right. Every range is subdivided into eighths — the boundaries, the C.E. at 4/8, the quadrants at 2/8 and 6/8, and the remaining octants. Nine prices per range, not ten.
Two calls, because the request stays at your call site: a request.*() expression inside an exported function is fixed at compile time and cannot depend on that function's arguments (CE10051).
bars = request.security(lib.settlementTickerId(mode), "D", lib.collectOhlcBars(3, false), lookahead = barmerge.lookahead_off)
days = lib.measureBars(bars)
Hold the request on every bar as Pine requires, but only call measureBars() when the day rolls — re-measuring on every intraday bar is pure allocation churn.
• DayLevels — one per day, newest first: dayRange, upperWick and lowerWick (wicks are na when insignificant), plus allLevels, every price flattened, sorted and de-duplicated.
• RangeLevels — levels holds 9 ascending prices where index k is the k/8 level; levelName(k) names them. Read via rangeCe(), rangeLevel(), rangeContains(), dayAllLevels(), dayKeyLevels(), dayBoundLevels().
• levelsBetween(days, low, high) — the confluence test: an FVG whose own range contains daily levels has an additional reason for price to trade back into it. levelsNear() for proximity instead of containment.
• settlementTickerId(mode) — settlement-as-close on futures. Note what it does not move: settlement replaces the close only, so it shifts the body boundary the wicks start from and leaves the daily range and its eighths untouched. TradingView exposes the chart toggle on 1D and higher only, so on an intraday chart "inherit" resolves to the symbol default rather than anything you can see.
• Also added: measureRange() for any high/low pair, and the RangeKind and SettlementMode enums.
Breaking Changes:
• VI and LV Anchors: isVolumeImbalance() and isLiquidityVoid() set startTime/startIndex three bars back — the FVG's span, not theirs. Both are two-candle constructs and now start at [1 + barIdx], so boxes drawn from those anchors come out one bar narrower.
• Bearish LV Name: A bearish liquidity void named itself "+LV". It reports "-LV" now.
• Session.isActive(): The int _time parameter is gone. It never reached the session check, only a log line, and the check goes through time() — which is what makes it weekend- and holiday-aware. Calls written as isActive() are unaffected.
• Session Fields: An unused internal field was removed, shifting positional constructor arguments after end. Named arguments and the three-argument form are unaffected.
Fixes:
• Session Logging: init() and isActive() no longer log on every call — that was up to three lines per session per bar.
• Session Validation: init()'s validation branch was unreachable, testing a variable nothing assigned. It now validates the session string's length and contents.
• LineLabel.extend(): No longer calls set_right() on a label box that does not exist when showLabel is false, and returns the object as its docs claimed.
• logIf(): Tests its expression before assembling the message, so a false expression costs nothing.
• Faster Dates: Internal date splitting parsed substrings out of a formatted string where the date builtins take a timezone directly.
Notes on Upgrading:
• Scripts pinned to an earlier version are unaffected until they bump the import.
• The VI/LV anchor fix moves where existing drawings start. Nothing throws — the boxes just shift — so check any chart rendering those gap types.
リリースノート
v13Updated:
levelName(idx)
Display name for a level index
Parameters:
idx (int): Level index, 0 (low) to 8 (high)
Returns: A label such as "Low", "25%", "CE", "High"
Pineライブラリ
TradingViewの精神に則り、作者はこのPineコードをオープンソースライブラリとして公開してくれました。コミュニティの他のPineプログラマーが再利用できるようにという配慮です。作者に拍手を!このライブラリは個人利用や他のオープンソースの公開コンテンツで使用できますが、公開物でのコードの再利用はハウスルールに準じる必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
Pineライブラリ
TradingViewの精神に則り、作者はこのPineコードをオープンソースライブラリとして公開してくれました。コミュニティの他のPineプログラマーが再利用できるようにという配慮です。作者に拍手を!このライブラリは個人利用や他のオープンソースの公開コンテンツで使用できますが、公開物でのコードの再利用はハウスルールに準じる必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。