PINE LIBRARY

lib_smc

Обновлено
Library "lib_smc"
This is an adaptation of LuxAlgo's Smart Money Concepts indicator with numerous changes. Main changes include integration of object based plotting, plenty of performance improvements, live tracking of Order Blocks, integration of volume profiles to refine Order Blocks, and many more.

This is a library for developers, if you want this converted into a working strategy, let me know.

buffer(item, len, force_rotate)
  Parameters:
    item (float)
    len (int)
    force_rotate (bool)

buffer(item, len, force_rotate)
  Parameters:
    item (int)
    len (int)
    force_rotate (bool)

buffer(item, len, force_rotate)
  Parameters:
    item (Profile type from robbatt/lib_profile/32)
    len (int)
    force_rotate (bool)

swings(len)
  INTERNAL: detect swing points (HH and LL) in given range
  Parameters:
    len (simple int): range to check for new swing points
  Returns: [idx, hh, ll] values are the price level where and if a new HH or LL was detected, else na

method init(this)
  Namespace types: OrderBlockConfig
  Parameters:
    this (OrderBlockConfig)

method delete(this)
  Namespace types: OrderBlock
  Parameters:
    this (OrderBlock)

method clear_broken(this, broken_buffer)
  INTERNAL: delete internal order blocks box coordinates if top/bottom is broken
  Namespace types: map<int, OrderBlock>
  Parameters:
    this (map<int, OrderBlock>)
    broken_buffer (map<int, OrderBlock>)
  Returns: any_bull_ob_broken, any_bear_ob_broken, broken signals are true if an according order block was broken/mitigated, broken contains the broken block(s)

create_ob(id, mode, start_t, start_i, top, end_t, end_i, bottom, break_price, early_confirmation_price, config, init_plot, force_overlay)
  INTERNAL: set internal order block coordinates
  Parameters:
    id (int)
    mode (int): 1: bullish, -1 bearish block
    start_t (int)
    start_i (int)
    top (float)
    end_t (int)
    end_i (int)
    bottom (float)
    break_price (float)
    early_confirmation_price (float)
    config (OrderBlockConfig)
    init_plot (bool)
    force_overlay (bool)
  Returns: [any_bull_ob_broken, any_bear_ob_broken] signals are true if an according order block was broken/mitigated

method align_to_profile(block, align_edge, align_break_price)
  Namespace types: OrderBlock
  Parameters:
    block (OrderBlock)
    align_edge (bool)
    align_break_price (bool)

method create_profile(block, opens, tops, bottoms, closes, values, resolution, vah_pc, val_pc, args, init_calculated, init_plot, force_overlay)
  Namespace types: OrderBlock
  Parameters:
    block (OrderBlock)
    opens (array<float>)
    tops (array<float>)
    bottoms (array<float>)
    closes (array<float>)
    values (array<float>)
    resolution (int)
    vah_pc (float)
    val_pc (float)
    args (ProfileArgs type from robbatt/lib_profile/32)
    init_calculated (bool)
    init_plot (bool)
    force_overlay (bool)

method create_profile(block, resolution, vah_pc, val_pc, args, init_calculated, init_plot, force_overlay)
  Namespace types: OrderBlock
  Parameters:
    block (OrderBlock)
    resolution (int)
    vah_pc (float)
    val_pc (float)
    args (ProfileArgs type from robbatt/lib_profile/32)
    init_calculated (bool)
    init_plot (bool)
    force_overlay (bool)

track_obs(swing_len, hh, ll, top, btm, bull_bos_alert, bull_choch_alert, bear_bos_alert, bear_choch_alert, min_block_size, max_block_size, config_bull, config_bear, init_plot, force_overlay, enabled, extend_blocks, clear_broken_buffer_before, align_edge_to_value_area, align_break_price_to_poc, profile_args_bull, profile_args_bear, use_soft_confirm, soft_confirm_offset, use_retracements_with_FVG_out)
  Parameters:
    swing_len (int)
    hh (float)
    ll (float)
    top (float)
    btm (float)
    bull_bos_alert (bool)
    bull_choch_alert (bool)
    bear_bos_alert (bool)
    bear_choch_alert (bool)
    min_block_size (float)
    max_block_size (float)
    config_bull (OrderBlockConfig)
    config_bear (OrderBlockConfig)
    init_plot (bool)
    force_overlay (bool)
    enabled (bool)
    extend_blocks (simple bool)
    clear_broken_buffer_before (simple bool)
    align_edge_to_value_area (simple bool)
    align_break_price_to_poc (simple bool)
    profile_args_bull (ProfileArgs type from robbatt/lib_profile/32)
    profile_args_bear (ProfileArgs type from robbatt/lib_profile/32)
    use_soft_confirm (simple bool)
    soft_confirm_offset (float)
    use_retracements_with_FVG_out (simple bool)

method draw(this, config, extend_only)
  Namespace types: OrderBlock
  Parameters:
    this (OrderBlock)
    config (OrderBlockConfig)
    extend_only (bool)

method draw(blocks, config)
  INTERNAL: plot order blocks
  Namespace types: array<OrderBlock>
  Parameters:
    blocks (array<OrderBlock>)
    config (OrderBlockConfig)

method draw(blocks, config)
  INTERNAL: plot order blocks
  Namespace types: map<int, OrderBlock>
  Parameters:
    blocks (map<int, OrderBlock>)
    config (OrderBlockConfig)

method cleanup(this, ob_bull, ob_bear)
  removes all Profiles that are older than the latest OrderBlock from this profile buffer
  Namespace types: array<PF.Profile>
  Parameters:
    this (array<Profile> type from robbatt/lib_profile/32)
    ob_bull (OrderBlock)
    ob_bear (OrderBlock)

_plot_swing_points(mode, x, y, show_swing_points, linecolor_swings, keep_history, show_latest_swings_levels, trail_x, trail_y, trend)
  INTERNAL: plot swing points
  Parameters:
    mode (int): 1: bullish, -1 bearish block
    x (int): x-coordingate of swing point to plot (bar_index)
    y (float): y-coordingate of swing point to plot (price)
    show_swing_points (bool): switch to enable/disable plotting of swing point labels
    linecolor_swings (color): color for swing point labels and lates level lines
    keep_history (bool): weater to remove older swing point labels and only keep the most recent
    show_latest_swings_levels (bool)
    trail_x (int): x-coordinate for latest swing point (bar_index)
    trail_y (float): y-coordinate for latest swing point (price)
    trend (int): the current trend 1: bullish, -1: bearish, to determine Strong/Weak Low/Highs

_pivot_lvl(mode, trend, hhll_x, hhll, super_hhll, filter_insignificant_internal_breaks)
  INTERNAL: detect whether a structural level has been broken and if it was in trend direction (BoS) or against trend direction (ChoCh), also track the latest high and low swing points
  Parameters:
    mode (simple int): detect 1: bullish, -1 bearish pivot points
    trend (int): current trend direction
    hhll_x (int): x-coordinate of newly detected hh/ll (bar_index)
    hhll (float): y-coordinate of newly detected hh/ll (price)
    super_hhll (float): level/y-coordinate of superior hhll (if this is an internal structure pivot level)
    filter_insignificant_internal_breaks (bool): if true pivot points / internal structure will be ignored where the wick in trend direction is longer than the opposite (likely to push further in direction of main trend)
  Returns: [x, y, trail_x, trail_y, bos_alert, choch_alert] coordinates of internal structure that has been broken (x,y): start of structure, (trail_x, trail_y): tracking hh/ll after structure break, (bos_alert, choch_alert): signal whether a structural level has been broken

_plot_structure(x, y, is_bos, is_choch, line_color, line_style, label_style, label_size, keep_history)
  INTERNAL: plot structural breaks (BoS/ChoCh)
  Parameters:
    x (int): x-coordinate of newly broken structure (bar_index)
    y (float): y-coordinate of newly broken structure (price)
    is_bos (bool): whether this structural break was in trend direction
    is_choch (bool): whether this structural break was against trend direction
    line_color (color): color for the line connecting the structural level and the breaking candle
    line_style (string): style (line.style_dashed/solid) for the line connecting the structural level and the breaking candle
    label_style (string): style (label.style_label_down/up) for the label above/below the line connecting the structural level and the breaking candle
    label_size (string): size (size.small/tiny) for the label above/below the line connecting the structural level and the breaking candle
    keep_history (bool): weater to remove older swing point labels and only keep the most recent

structure_values(length, super_hh, super_ll, filter_insignificant_internal_breaks)
  detect (and plot) structural breaks and the resulting new trend
  Parameters:
    length (simple int): lookback period for swing point detection
    super_hh (float): level/y-coordinate of superior hh (for internal structure detection)
    super_ll (float): level/y-coordinate of superior ll (for internal structure detection)
    filter_insignificant_internal_breaks (bool): if true pivot points / internal structure will be ignored where the wick in trend direction is longer than the opposite (likely to push further in direction of main trend)
  Returns: [trend, bull_bos_alert, bull_choch_alert, top_x, top_y, trail_up_x, trail_up, hh, bear_bos_alert, bear_choch_alert, btm_x, btm_y, trail_dn_x, trail_dn, ll, hhll_x] trend: direction 1:bullish -1:bearish, (bull_bos_alert, bull_choch_alert, top_x, top_y, trail_up_x, trail_up): whether and which level broke in a bullish direction, trailing high, (bbear_bos_alert, bear_choch_alert, tm_x, btm_y, trail_dn_x, trail_dn): same in bearish direction

structure_plot(trend, bull_bos_alert, bull_choch_alert, top_x, top_y, trail_up_x, trail_up, hh, bear_bos_alert, bear_choch_alert, btm_x, btm_y, trail_dn_x, trail_dn, ll, color_bull, color_bear, show_swing_points, show_latest_swings_levels, show_bos, show_choch, line_style, label_size, keep_history)
  detect (and plot) structural breaks and the resulting new trend
  Parameters:
    trend (int): crrent trend 1: bullish, -1: bearish
    bull_bos_alert (bool): if there was a bullish bos alert -> plot it
    bull_choch_alert (bool): if there was a bullish choch alert -> plot it
    top_x (int): latest shwing high x
    top_y (float): latest swing high y
    trail_up_x (int): trailing high x
    trail_up (float): trailing high y
    hh (float): if there was a higher high
    bear_bos_alert (bool): if there was a bearish bos alert -> plot it
    bear_choch_alert (bool): if there was a bearish chock alert -> plot it
    btm_x (int): latest swing low x
    btm_y (float): latest swing low y
    trail_dn_x (int): trailing low x
    trail_dn (float): trailing low y
    ll (float): if there was a lower low
    color_bull (color): color for bullish BoS/ChoCh levels
    color_bear (color): color for bearish BoS/ChoCh levels
    show_swing_points (bool): whether to plot swing point labels
    show_latest_swings_levels (bool): whether to track and plot latest swing point levels with lines
    show_bos (bool): whether to plot BoS levels
    show_choch (bool): whether to plot ChoCh levels
    line_style (string): whether to plot BoS levels
    label_size (string): label size of plotted BoS/ChoCh levels
    keep_history (bool): weater to remove older swing point labels and only keep the most recent

structure(length, color_bull, color_bear, super_hh, super_ll, filter_insignificant_internal_breaks, show_swing_points, show_latest_swings_levels, show_bos, show_choch, line_style, label_size, keep_history, enabled)
  detect (and plot) structural breaks and the resulting new trend
  Parameters:
    length (simple int): lookback period for swing point detection
    color_bull (color): color for bullish BoS/ChoCh levels
    color_bear (color): color for bearish BoS/ChoCh levels
    super_hh (float): level/y-coordinate of superior hh (for internal structure detection)
    super_ll (float): level/y-coordinate of superior ll (for internal structure detection)
    filter_insignificant_internal_breaks (bool): if true pivot points / internal structure will be ignored where the wick in trend direction is longer than the opposite (likely to push further in direction of main trend)
    show_swing_points (bool): whether to plot swing point labels
    show_latest_swings_levels (bool): whether to track and plot latest swing point levels with lines
    show_bos (bool): whether to plot BoS levels
    show_choch (bool): whether to plot ChoCh levels
    line_style (string): whether to plot BoS levels
    label_size (string): label size of plotted BoS/ChoCh levels
    keep_history (bool): weater to remove older swing point labels and only keep the most recent
    enabled (bool)

_check_equal_level(mode, len, eq_threshold, enabled)
  INTERNAL: detect equal levels (double top/bottom)
  Parameters:
    mode (int): detect 1: bullish/high, -1 bearish/low pivot points
    len (int): lookback period for equal level (swing point) detection
    eq_threshold (float): maximum price offset for a level to be considered equal
    enabled (bool)
  Returns: [eq_alert, x1, y1, x2, y2] eq_alert whether an equal level was detected and coordinates of the first and the second level/swing point

_plot_equal_level(show_eq, x1, y1, x2, y2, label_txt, label_style, label_size, line_color, line_style, keep_history)
  INTERNAL: plot equal levels (double top/bottom)
  Parameters:
    show_eq (bool): whether to plot the level or not
    x1 (int): x-coordinate of the first level / swing point
    y1 (float): y-coordinate of the first level / swing point
    x2 (int): x-coordinate of the second level / swing point
    y2 (float): y-coordinate of the second level / swing point
    label_txt (string): text for the label above/below the line connecting the equal levels
    label_style (string): style (label.style_label_down/up) for the label above/below the line connecting the equal levels
    label_size (string): size (size.tiny) for the label above/below the line connecting the equal levels
    line_color (color): color for the line connecting the equal levels (and it's label)
    line_style (string): style (line.style_dotted) for the line connecting the equal levels
    keep_history (bool): weater to remove older swing point labels and only keep the most recent

equal_levels_values(len, threshold, enabled)
  detect (and plot) equal levels (double top/bottom), returns coordinates
  Parameters:
    len (int): lookback period for equal level (swing point) detection
    threshold (float): maximum price offset for a level to be considered equal
    enabled (bool): whether detection is enabled
  Returns: [eqh_alert, eqh_x1, eqh_y1, eqh_x2, eqh_y2, eql_alert, eql_x1, eql_y1, eql_x2, eql_y2] (eqh_alert, eqh_x1, eqh_y1, eqh_x2, eqh_y2) whether an equal high was detected and coordinates of the first and the second level/swing point, (eql_alert, eql_x1, eql_y1, eql_x2, eql_y2) same for equal lows

equal_levels_plot(eqh_x1, eqh_y1, eqh_x2, eqh_y2, eql_x1, eql_y1, eql_x2, eql_y2, color_eqh, color_eql, show, keep_history)
  detect (and plot) equal levels (double top/bottom), returns coordinates
  Parameters:
    eqh_x1 (int): coordinates of first point of equal high
    eqh_y1 (float): coordinates of first point of equal high
    eqh_x2 (int): coordinates of second point of equal high
    eqh_y2 (float): coordinates of second point of equal high
    eql_x1 (int): coordinates of first point of equal low
    eql_y1 (float): coordinates of first point of equal low
    eql_x2 (int): coordinates of second point of equal low
    eql_y2 (float): coordinates of second point of equal low
    color_eqh (color): color for the line connecting the equal highs (and it's label)
    color_eql (color): color for the line connecting the equal lows (and it's label)
    show (bool): whether plotting is enabled
    keep_history (bool): weater to remove older swing point labels and only keep the most recent
  Returns: [eqh_alert, eqh_x1, eqh_y1, eqh_x2, eqh_y2, eql_alert, eql_x1, eql_y1, eql_x2, eql_y2] (eqh_alert, eqh_x1, eqh_y1, eqh_x2, eqh_y2) whether an equal high was detected and coordinates of the first and the second level/swing point, (eql_alert, eql_x1, eql_y1, eql_x2, eql_y2) same for equal lows

equal_levels(len, threshold, color_eqh, color_eql, enabled, show, keep_history)
  detect (and plot) equal levels (double top/bottom)
  Parameters:
    len (int): lookback period for equal level (swing point) detection
    threshold (float): maximum price offset for a level to be considered equal
    color_eqh (color): color for the line connecting the equal highs (and it's label)
    color_eql (color): color for the line connecting the equal lows (and it's label)
    enabled (bool): whether detection is enabled
    show (bool): whether plotting is enabled
    keep_history (bool): weater to remove older swing point labels and only keep the most recent
  Returns: [eqh_alert, eql_alert] (eqh_alert) whether an equal high was detected, (eql_alert) same for equal lows

_detect_fvg(mode, enabled, o, h, l, c, filter_insignificant_fvgs, change_tf)
  INTERNAL: detect FVG (fair value gap)
  Parameters:
    mode (int): detect 1: bullish, -1 bearish gaps
    enabled (bool): whether detection is enabled
    o (float): reference source open
    h (float): reference source high
    l (float): reference source low
    c (float): reference source close
    filter_insignificant_fvgs (bool): whether to calculate and filter small/insignificant gaps
    change_tf (bool): signal when the previous reference timeframe closed, triggers new calculation
  Returns: [cnd, top, mid, btm] whether a new FVG was detected and its top/mid/bottom levels

_clear_broken_fvg(mode, upper_boxes, lower_boxes)
  INTERNAL: clear mitigated FVGs (fair value gaps)
  Parameters:
    mode (int): detect 1: bullish, -1 bearish gaps
    upper_boxes (array<box>): array<box> that stores the upper parts of the FVG boxes
    lower_boxes (array<box>): array<box> that stores the lower parts of the FVG boxes

_plot_fvg(mode, show, top, mid, btm, border_color, extend_box)
  INTERNAL: plot (and clear broken) FVG (fair value gap)
  Parameters:
    mode (int): plot 1: bullish, -1 bearish gap
    show (bool): whether plotting is enabled
    top (float): top level of fvg
    mid (float): center level of fvg
    btm (float): bottom level of fvg
    border_color (color): color for the FVG box
    extend_box (int): how many bars into the future the FVG box should be extended after detection

fvgs_values(o, h, l, c, filter_insignificant_fvgs, change_tf, enabled)
  detect (and plot / clear broken) FVGs (fair value gaps), and return alerts and level values
  Parameters:
    o (float): reference source open
    h (float): reference source high
    l (float): reference source low
    c (float): reference source close
    filter_insignificant_fvgs (bool): whether to calculate and filter small/insignificant gaps
    change_tf (bool): signal when the previous reference timeframe closed, triggers new calculation
    enabled (bool): whether detection is enabled
  Returns: [bullish_fvg_alert, bull_top, bull_mid, bull_btm, bearish_fvg_alert, bear_top, bear_mid, bear_btm] (bullish_fvg_alert, bull_top, bull_mid, bull_btm): whether a new bullish FVG was detected and its top/mid/bottom levels, (bearish_fvg_alert, bear_top, bear_mid, bear_btm): same for bearish FVGs

fvgs_plot(bullish_fvg_alert, bull_top, bull_mid, bull_btm, bearish_fvg_alert, bear_top, bear_mid, bear_btm, color_bull, color_bear, extend_box, show)
  Parameters:
    bullish_fvg_alert (bool)
    bull_top (float)
    bull_mid (float)
    bull_btm (float)
    bearish_fvg_alert (bool)
    bear_top (float)
    bear_mid (float)
    bear_btm (float)
    color_bull (color): color for bullish FVG boxes
    color_bear (color): color for bearish FVG boxes
    extend_box (int): how many bars into the future the FVG box should be extended after detection
    show (bool): whether plotting is enabled
  Returns: [bullish_fvg_alert, bull_top, bull_mid, bull_btm, bearish_fvg_alert, bear_top, bear_mid, bear_btm] (bullish_fvg_alert, bull_top, bull_mid, bull_btm): whether a new bullish FVG was detected and its top/mid/bottom levels, (bearish_fvg_alert, bear_top, bear_mid, bear_btm): same for bearish FVGs

fvgs(o, h, l, c, filter_insignificant_fvgs, change_tf, color_bull, color_bear, extend_box, enabled, show)
  detect (and plot / clear broken) FVGs (fair value gaps)
  Parameters:
    o (float): reference source open
    h (float): reference source high
    l (float): reference source low
    c (float): reference source close
    filter_insignificant_fvgs (bool): whether to calculate and filter small/insignificant gaps
    change_tf (bool): signal when the previous reference timeframe closed, triggers new calculation
    color_bull (color): color for bullish FVG boxes
    color_bear (color): color for bearish FVG boxes
    extend_box (int): how many bars into the future the FVG box should be extended after detection
    enabled (bool): whether detection is enabled
    show (bool): whether plotting is enabled
  Returns: [bullish_fvg_alert, bearish_fvg_alert] (bullish_fvg_alert): whether a new bullish FVG was detected, (bearish_fvg_alert): same for bearish FVGs

OrderBlock
  Fields:
    id (series int)
    dir (series int)
    left_top (chart.point)
    right_bottom (chart.point)
    break_price (series float)
    early_confirmation_price (series float)
    ltf_high (array<float>)
    ltf_low (array<float>)
    ltf_volume (array<float>)
    plot (Box type from robbatt/lib_plot_objects/49)
    profile (Profile type from robbatt/lib_profile/32)
    trailing (series bool)
    extending (series bool)
    awaiting_confirmation (series bool)
    touched_break_price_before_confirmation (series bool)
    soft_confirmed (series bool)
    has_fvg_out (series bool)
    hidden (series bool)
    broken (series bool)

OrderBlockConfig
  Fields:
    show (series bool)
    show_last (series int)
    show_id (series bool)
    show_profile (series bool)
    args (BoxArgs type from robbatt/lib_plot_objects/49)
    txt (series string)
    txt_args (BoxTextArgs type from robbatt/lib_plot_objects/49)
    delete_when_broken (series bool)
    broken_args (BoxArgs type from robbatt/lib_plot_objects/49)
    broken_txt (series string)
    broken_txt_args (BoxTextArgs type from robbatt/lib_plot_objects/49)
    broken_profile_args (ProfileArgs type from robbatt/lib_profile/32)
    use_profile (series bool)
    profile_args (ProfileArgs type from robbatt/lib_profile/32)
Информация о релизе
v2 removed logging for performance improvement
Информация о релизе
v3 minor refactoring
Информация о релизе
v4 fixed latest pivot line display
libraryMATHorderblockssmartmoneyconceptsstatisticstechindicatortoolkit

Библиотека Pine

В истинном духе TradingView автор опубликовал этот код Pine как библиотеку с открытым исходным кодом, чтобы другие программисты Pine из нашего сообщества могли им воспользоваться. Вы можете использовать эту библиотеку в приватных или других публикациях с открытым исходным кодом, но повторное использование этого кода в публикации регулируется Правилами поведения.

Отказ от ответственности