PINE LIBRARY
Updated lib_fvg

Library "lib_fvg"
Fair Value Gap engine — detection, testing/inversion lifecycle, HTF nesting filters, entry-candidate selection, stop-loss derivation, and FVG drawing — extracted 1:1 from rewrite_strategy.pine.
method equals(this, other)
Namespace types: FVG
Parameters:
this (FVG)
other (FVG)
method remove(this, item)
Namespace types: array<FVG>
Parameters:
this (array<FVG>)
item (FVG)
method check_nested_in(this, htf_fvg, check_nested, check_untested, check_nearby, nearby_threshold, check_newer_ltf)
Namespace types: FVG
Parameters:
this (FVG)
htf_fvg (FVG)
check_nested (bool)
check_untested (bool)
check_nearby (bool)
nearby_threshold (float)
check_newer_ltf (bool)
method distance_to_price_post_inverse(this, price)
Namespace types: FVG
Parameters:
this (FVG)
price (float)
method is_higher_tf_or_closer_to_price_than(this, other)
Namespace types: FVG
Parameters:
this (FVG)
other (FVG)
method get_stop_loss(this, entry_price, session_extreme, enable_sl_at_fvg_created_swing_point, trail_session_level_tight_threshold)
Namespace types: FVG
Parameters:
this (FVG)
entry_price (float)
session_extreme (float)
enable_sl_at_fvg_created_swing_point (bool)
trail_session_level_tight_threshold (float)
method delete_bar(this)
Namespace types: Bar
Parameters:
this (Bar)
method delete_fvg(this)
Namespace types: FVG
Parameters:
this (FVG)
log_entry_rejection(enable_log, fvg, reason, smt, note)
Parameters:
enable_log (bool)
fvg (FVG)
reason (series EntryFilterReason)
smt (SMT type from Danieltrade29292/lib_smt/1)
note (string)
method invalidate_fvg(this, fvg, reason, entry_block_reason, lifecycle)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
fvg (FVG)
reason (series FVGFilterReason)
entry_block_reason (series EntryFilterReason)
lifecycle (series FVGLifecycle)
method add_fvg(this, fvg, enable_single_fvg_per_tf)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
fvg (FVG)
enable_single_fvg_per_tf (bool)
method detect_fvg(this, tf, tf_id, t2, h2, l2, h1, l1, h0, l0, min_gap_size, fvg_deprecation_period, enable_single_fvg_per_tf)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
tf (string)
tf_id (int)
t2 (int)
h2 (float)
l2 (float)
h1 (float)
l1 (float)
h0 (float)
l0 (float)
min_gap_size (float)
fvg_deprecation_period (int)
enable_single_fvg_per_tf (bool)
method invalidate_all_of_direction(this, fvg_is_bullish, reason)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
fvg_is_bullish (bool)
reason (series FVGFilterReason)
method invalidate_fvgs_inversed_pre_smt(this, smt_buffer, enable_log)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
smt_buffer (SMTBuffer type from Danieltrade29292/lib_smt/1)
enable_log (bool)
method try_park_in(this, htf_pool, check_nested, check_untested, check_nearby, nearby_threshold, check_newer_ltf)
Namespace types: FVG
Parameters:
this (FVG)
htf_pool (array<FVG>)
check_nested (bool)
check_untested (bool)
check_nearby (bool)
nearby_threshold (float)
check_newer_ltf (bool)
method update_htf_relations(this, enable_filter_by_full_nest_in_HTF_fvg, enable_filter_by_untested, enable_filter_by_edge_nearby_HTF_fvg, nearby_HTF_threshold, enable_filter_by_newer_LTF_fvg)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
enable_filter_by_full_nest_in_HTF_fvg (bool)
enable_filter_by_untested (bool)
enable_filter_by_edge_nearby_HTF_fvg (bool)
nearby_HTF_threshold (float)
enable_filter_by_newer_LTF_fvg (bool)
method update_fvgs(this, tf2, tf2_updated, fvg2_o, fvg2_h, fvg2_l, fvg2_c, tf3, tf3_updated, fvg3_o, fvg3_h, fvg3_l, fvg3_c, tf4, tf4_updated, fvg4_o, fvg4_h, fvg4_l, fvg4_c, min_inversion_distance, max_inversion_distance, tested_by_mode, max_tests_before_inverse)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
tf2 (string)
tf2_updated (bool)
fvg2_o (float)
fvg2_h (float)
fvg2_l (float)
fvg2_c (float)
tf3 (string)
tf3_updated (bool)
fvg3_o (float)
fvg3_h (float)
fvg3_l (float)
fvg3_c (float)
tf4 (string)
tf4_updated (bool)
fvg4_o (float)
fvg4_h (float)
fvg4_l (float)
fvg4_c (float)
min_inversion_distance (float)
max_inversion_distance (float)
tested_by_mode (series FVGTestedByMode)
max_tests_before_inverse (int)
method find_next_best_waiting_fvgs(this, smt_buffer)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
smt_buffer (SMTBuffer type from Danieltrade29292/lib_smt/1)
method find_entry_candidate_fvg(this, smt_buffer, enable_filter_by_inversion_bar_close_in_untested_HTF_fvg, enable_log)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
smt_buffer (SMTBuffer type from Danieltrade29292/lib_smt/1)
enable_filter_by_inversion_bar_close_in_untested_HTF_fvg (bool)
enable_log (bool)
method draw_bar(this, is_bullish, bgcolor, border_color, labelcolor, txt, show_box)
Namespace types: Bar
Parameters:
this (Bar)
is_bullish (bool)
bgcolor (color)
border_color (color)
labelcolor (color)
txt (string)
show_box (bool)
method draw_fvg(this, color_bull, color_bear, debug)
Namespace types: FVG
Parameters:
this (FVG)
color_bull (color)
color_bear (color)
debug (bool)
method draw_fvgs(this, color_bull, color_bear, debug)
Namespace types: array<FVG>
Parameters:
this (array<FVG>)
color_bull (color)
color_bear (color)
debug (bool)
method draw_entry_fvg(this, color_bull, color_bear, debug)
Namespace types: FVG
Parameters:
this (FVG)
color_bull (simple color)
color_bear (simple color)
debug (bool)
method delete_fvgs(this)
Namespace types: array<FVG>
Parameters:
this (array<FVG>)
Bar
Fields:
o (series float)
h (series float)
l (series float)
c (series float)
top (series float)
btm (series float)
t_open (series int)
i_open (series int)
t_close (series int)
i_close (series int)
bar_box (series box)
bar_label (series label)
FVG
Fields:
is_bullish_original (series bool)
is_bullish_post_inverse (series bool)
tf (series string)
tf_id (series int)
top_left (chart.point)
bottom_right (chart.point)
hh (series float)
ll (series float)
deprecate_at (series int)
sl_level (series float)
is_active (series bool)
test_count (series int)
first_test_idx (series int)
is_inversed (series bool)
has_touched (series bool)
fvg_box (series box)
tooltip_label (series label)
hidden (series bool)
draw_signal_inversed (series bool)
draw_signal_text (series bool)
draw_signal_highlight (series bool)
draw_signal_set_candidate (series bool)
draw_signal_reset_candidate (series bool)
fill_state (series FVGFillState)
lifecycle (series FVGLifecycle)
filter_reason (series FVGFilterReason)
entry_filter_reason (series EntryFilterReason)
tf_inversion_bar (Bar)
inversion_idx (series int)
FVGBuffer
Fields:
items (array<FVG>)
inversed (array<FVG>)
invalidated (array<FVG>)
Fair Value Gap engine — detection, testing/inversion lifecycle, HTF nesting filters, entry-candidate selection, stop-loss derivation, and FVG drawing — extracted 1:1 from rewrite_strategy.pine.
method equals(this, other)
Namespace types: FVG
Parameters:
this (FVG)
other (FVG)
method remove(this, item)
Namespace types: array<FVG>
Parameters:
this (array<FVG>)
item (FVG)
method check_nested_in(this, htf_fvg, check_nested, check_untested, check_nearby, nearby_threshold, check_newer_ltf)
Namespace types: FVG
Parameters:
this (FVG)
htf_fvg (FVG)
check_nested (bool)
check_untested (bool)
check_nearby (bool)
nearby_threshold (float)
check_newer_ltf (bool)
method distance_to_price_post_inverse(this, price)
Namespace types: FVG
Parameters:
this (FVG)
price (float)
method is_higher_tf_or_closer_to_price_than(this, other)
Namespace types: FVG
Parameters:
this (FVG)
other (FVG)
method get_stop_loss(this, entry_price, session_extreme, enable_sl_at_fvg_created_swing_point, trail_session_level_tight_threshold)
Namespace types: FVG
Parameters:
this (FVG)
entry_price (float)
session_extreme (float)
enable_sl_at_fvg_created_swing_point (bool)
trail_session_level_tight_threshold (float)
method delete_bar(this)
Namespace types: Bar
Parameters:
this (Bar)
method delete_fvg(this)
Namespace types: FVG
Parameters:
this (FVG)
log_entry_rejection(enable_log, fvg, reason, smt, note)
Parameters:
enable_log (bool)
fvg (FVG)
reason (series EntryFilterReason)
smt (SMT type from Danieltrade29292/lib_smt/1)
note (string)
method invalidate_fvg(this, fvg, reason, entry_block_reason, lifecycle)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
fvg (FVG)
reason (series FVGFilterReason)
entry_block_reason (series EntryFilterReason)
lifecycle (series FVGLifecycle)
method add_fvg(this, fvg, enable_single_fvg_per_tf)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
fvg (FVG)
enable_single_fvg_per_tf (bool)
method detect_fvg(this, tf, tf_id, t2, h2, l2, h1, l1, h0, l0, min_gap_size, fvg_deprecation_period, enable_single_fvg_per_tf)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
tf (string)
tf_id (int)
t2 (int)
h2 (float)
l2 (float)
h1 (float)
l1 (float)
h0 (float)
l0 (float)
min_gap_size (float)
fvg_deprecation_period (int)
enable_single_fvg_per_tf (bool)
method invalidate_all_of_direction(this, fvg_is_bullish, reason)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
fvg_is_bullish (bool)
reason (series FVGFilterReason)
method invalidate_fvgs_inversed_pre_smt(this, smt_buffer, enable_log)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
smt_buffer (SMTBuffer type from Danieltrade29292/lib_smt/1)
enable_log (bool)
method try_park_in(this, htf_pool, check_nested, check_untested, check_nearby, nearby_threshold, check_newer_ltf)
Namespace types: FVG
Parameters:
this (FVG)
htf_pool (array<FVG>)
check_nested (bool)
check_untested (bool)
check_nearby (bool)
nearby_threshold (float)
check_newer_ltf (bool)
method update_htf_relations(this, enable_filter_by_full_nest_in_HTF_fvg, enable_filter_by_untested, enable_filter_by_edge_nearby_HTF_fvg, nearby_HTF_threshold, enable_filter_by_newer_LTF_fvg)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
enable_filter_by_full_nest_in_HTF_fvg (bool)
enable_filter_by_untested (bool)
enable_filter_by_edge_nearby_HTF_fvg (bool)
nearby_HTF_threshold (float)
enable_filter_by_newer_LTF_fvg (bool)
method update_fvgs(this, tf2, tf2_updated, fvg2_o, fvg2_h, fvg2_l, fvg2_c, tf3, tf3_updated, fvg3_o, fvg3_h, fvg3_l, fvg3_c, tf4, tf4_updated, fvg4_o, fvg4_h, fvg4_l, fvg4_c, min_inversion_distance, max_inversion_distance, tested_by_mode, max_tests_before_inverse)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
tf2 (string)
tf2_updated (bool)
fvg2_o (float)
fvg2_h (float)
fvg2_l (float)
fvg2_c (float)
tf3 (string)
tf3_updated (bool)
fvg3_o (float)
fvg3_h (float)
fvg3_l (float)
fvg3_c (float)
tf4 (string)
tf4_updated (bool)
fvg4_o (float)
fvg4_h (float)
fvg4_l (float)
fvg4_c (float)
min_inversion_distance (float)
max_inversion_distance (float)
tested_by_mode (series FVGTestedByMode)
max_tests_before_inverse (int)
method find_next_best_waiting_fvgs(this, smt_buffer)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
smt_buffer (SMTBuffer type from Danieltrade29292/lib_smt/1)
method find_entry_candidate_fvg(this, smt_buffer, enable_filter_by_inversion_bar_close_in_untested_HTF_fvg, enable_log)
Namespace types: FVGBuffer
Parameters:
this (FVGBuffer)
smt_buffer (SMTBuffer type from Danieltrade29292/lib_smt/1)
enable_filter_by_inversion_bar_close_in_untested_HTF_fvg (bool)
enable_log (bool)
method draw_bar(this, is_bullish, bgcolor, border_color, labelcolor, txt, show_box)
Namespace types: Bar
Parameters:
this (Bar)
is_bullish (bool)
bgcolor (color)
border_color (color)
labelcolor (color)
txt (string)
show_box (bool)
method draw_fvg(this, color_bull, color_bear, debug)
Namespace types: FVG
Parameters:
this (FVG)
color_bull (color)
color_bear (color)
debug (bool)
method draw_fvgs(this, color_bull, color_bear, debug)
Namespace types: array<FVG>
Parameters:
this (array<FVG>)
color_bull (color)
color_bear (color)
debug (bool)
method draw_entry_fvg(this, color_bull, color_bear, debug)
Namespace types: FVG
Parameters:
this (FVG)
color_bull (simple color)
color_bear (simple color)
debug (bool)
method delete_fvgs(this)
Namespace types: array<FVG>
Parameters:
this (array<FVG>)
Bar
Fields:
o (series float)
h (series float)
l (series float)
c (series float)
top (series float)
btm (series float)
t_open (series int)
i_open (series int)
t_close (series int)
i_close (series int)
bar_box (series box)
bar_label (series label)
FVG
Fields:
is_bullish_original (series bool)
is_bullish_post_inverse (series bool)
tf (series string)
tf_id (series int)
top_left (chart.point)
bottom_right (chart.point)
hh (series float)
ll (series float)
deprecate_at (series int)
sl_level (series float)
is_active (series bool)
test_count (series int)
first_test_idx (series int)
is_inversed (series bool)
has_touched (series bool)
fvg_box (series box)
tooltip_label (series label)
hidden (series bool)
draw_signal_inversed (series bool)
draw_signal_text (series bool)
draw_signal_highlight (series bool)
draw_signal_set_candidate (series bool)
draw_signal_reset_candidate (series bool)
fill_state (series FVGFillState)
lifecycle (series FVGLifecycle)
filter_reason (series FVGFilterReason)
entry_filter_reason (series EntryFilterReason)
tf_inversion_bar (Bar)
inversion_idx (series int)
FVGBuffer
Fields:
items (array<FVG>)
inversed (array<FVG>)
invalidated (array<FVG>)
Release Notes
v2Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.