robbatt

lib_profile

robbatt Aktualisiert   
Library "lib_profile"
a library with functions to calculate a volume profile for either a set of candles within the current chart, or a single candle from its lower timeframe security data. All you need is to feed the

method delete(this)
  deletes this bucket's plot from the chart
  Namespace types: Bucket
  Parameters:
    this (Bucket)

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

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

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

method update(this, top, bottom, value, fraction)
  updates this bucket's data
  Namespace types: Bucket
  Parameters:
    this (Bucket)
    top (float)
    bottom (float)
    value (float)
    fraction (float)

method update(this, tops, bottoms, values)
  update this Profile's data (recalculates the whole profile and applies the result to this object) TODO optimisation to calculate this incremental to improve performance in realtime on high resolution
  Namespace types: Profile
  Parameters:
    this (Profile)
    tops (float): array of range top/high values (either from ltf or chart candles using history() function
    bottoms (float): array of range bottom/low values (either from ltf or chart candles using history() function
    values (float): array of range volume/1 values (either from ltf or chart candles using history() function (1s can be used for analysing candles in bucket/price range over time)

method tostring(this)
  allows debug print of a bucket
  Namespace types: Bucket
  Parameters:
    this (Bucket)

method draw(this, start_t, start_i, end_t, end_i, args, line_color)
  allows drawing a line in a Profile, representing this bucket and it's value + it's value's fraction of the Profile total value
  Namespace types: Bucket
  Parameters:
    this (Bucket)
    start_t (int): the time x coordinate of the line's left end (depends on the Profile box)
    start_i (int): the bar_index x coordinate of the line's left end (depends on the Profile box)
    end_t (int): the time x coordinate of the line's right end (depends on the Profile box)
    end_i (int): the bar_index x coordinate of the line's right end (depends on the Profile box)
    args (LineArgs type from robbatt/lib_plot_objects/24): the default arguments for the line style
    line_color (color): the color override for POC/VAH/VAL lines

method draw(this, forced_width)
  draw all components of this Profile (Box, Background, Bucket lines, POC/VAH/VAL overlay levels and labels)
  Namespace types: Profile
  Parameters:
    this (Profile)
    forced_width (int): allows to force width of the Profile Box, overrides the ProfileArgs.default_size and ProfileArgs.extend arguments (default: na)

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

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

profile(tops, bottoms, values, resolution, vah_pc, val_pc, bucket_buffer)
  split a chart/parent bar into 'resolution' sections, figure out in which section the most volume/time was spent, by analysing a given set of (intra)bars' top/bottom/volume values. Then return price center of the bin with the highest volume, essentially marking the point of control / highest volume (poc) in the chart/parent bar.
  Parameters:
    tops (float): array of range top/high values (either from ltf or chart candles using history() function
    bottoms (float): array of range bottom/low values (either from ltf or chart candles using history() function
    values (float): array of range volume/1 values (either from ltf or chart candles using history() function (1s can be used for analysing candles in bucket/price range over time)
    resolution (int): amount of buckets/price ranges to sort the candle data into (analyse how much volume / time was spent in a certain bucket/price range) (default: 25)
    vah_pc (float): a threshold percentage (of values' total) for the top end of the value area (default: 80)
    val_pc (float): a threshold percentage (of values' total) for the bottom end of the value area (default: 20)
    bucket_buffer (Bucket): optional buffer of empty Buckets to fill, if omitted a new one is created and returned. The buffer length must match the resolution
  Returns: poc (price level), vah (price level), val (price level), poc_index (idx in buckets), vah_index (idx in buckets), val_index (idx in buckets), buckets (filled buffer or new)

create_profile(start_idx, tops, bottoms, values, resolution, vah_pc, val_pc, args)
  split a chart/parent bar into 'resolution' sections, figure out in which section the most volume/time was spent, by analysing a given set of (intra)bars' top/bottom/volume values. Then return price center of the bin with the highest volume, essentially marking the point of control / highest volume (poc) in the chart/parent bar.
  Parameters:
    start_idx (int): the bar_index at which the Profile should start drawing
    tops (float): array of range top/high values (either from ltf or chart candles using history() function
    bottoms (float): array of range bottom/low values (either from ltf or chart candles using history() function
    values (float): array of range volume/1 values (either from ltf or chart candles using history() function (1s can be used for analysing candles in bucket/price range over time)
    resolution (int): amount of buckets/price ranges to sort the candle data into (analyse how much volume / time was spent in a certain bucket/price range) (default: 25)
    vah_pc (float): a threshold percentage (of values' total) for the top end of the value area (default: 80)
    val_pc (float): a threshold percentage (of values' total) for the bottom end of the value area (default: 20)
    args (ProfileArgs)
  Returns: poc (price level), vah (price level), val (price level), poc_index (idx in buckets), vah_index (idx in buckets), val_index (idx in buckets), buckets (filled buffer or new)

history(src, len, offset)
  allows fetching an array of values from the history series with offset from current candle
  Parameters:
    src (int)
    len (int)
    offset (int)

history(src, len, offset)
  allows fetching an array of values from the history series with offset from current candle
  Parameters:
    src (float)
    len (int)
    offset (int)

history(src, len, offset)
  allows fetching an array of values from the history series with offset from current candle
  Parameters:
    src (bool)
    len (int)
    offset (int)

history(src, len, offset)
  allows fetching an array of values from the history series with offset from current candle
  Parameters:
    src (string)
    len (int)
    offset (int)

Bucket
  Fields:
    idx (series int): the index of this Bucket within the Profile starting with 0 for the lowest Bucket at the bottom of the Profile
    value (series float): the value of this Bucket, can be volume or time, for using time pass and array of 1s to the update function
    top (series float): the top of this Bucket's price range (for calculation)
    btm (series float): the bottom of this Bucket's price range (for calculation)
    center (series float): the center of this Bucket's price range (for plotting)
    fraction (series float): the fraction this Bucket's value is compared to the total of the Profile
    plot_bucket_line (Line type from robbatt/lib_plot_objects/24): the line that resembles this bucket and it's valeu in the Profile

ProfileArgs
  Fields:
    show_poc (series bool): whether to plot a POC line across the Profile Box (default: true)
    show_profile (series bool): whether to plot a line for each Bucket in the Profile Box, indicating the value per Bucket (Price range), e.g. volume that occured in a certain time and price range (default: false)
    show_va (series bool): whether to plot a VAH/VAL line across the Profile Box (default: false)
    show_va_fill (series bool): whether to fill the 'value' area between VAH/VAL line (default: false)
    show_background (series bool): whether to fill the Profile Box with a background color (default: false)
    show_labels (series bool): whether to add labels to the right end of the POC/VAH/VAL line (default: false)
    show_price_levels (series bool): whether add price values to the labels to the right end of the POC/VAH/VAL line (default: false)
    extend (series bool): whether extend the Profile Box to the current candle (default: false)
    default_size (series int): the default min. width of the Profile Box (default: 30)
    args_poc_line (LineArgs type from robbatt/lib_plot_objects/24): arguments for the poc line plot
    args_va_line (LineArgs type from robbatt/lib_plot_objects/24): arguments for the va line plot
    args_poc_label (LabelArgs type from robbatt/lib_plot_objects/24): arguments for the poc label plot
    args_va_label (LabelArgs type from robbatt/lib_plot_objects/24): arguments for the va label plot
    args_profile_line (LineArgs type from robbatt/lib_plot_objects/24): arguments for the Bucket line plots
    args_profile_bg (BoxArgs type from robbatt/lib_plot_objects/24)
    va_fill_color (series color): color for the va area fill plot

Profile
  Fields:
    start (series int): left x coordinate for the Profile Box
    end (series int): right x coordinate for the Profile Box
    resolution (series int): the amount of buckets/price ranges the Profile will dissect the data into
    vah_threshold_pc (series float): the percentage of the total data value to mark the upper threshold for the main value area
    val_threshold_pc (series float): the percentage of the total data value to mark the lower threshold for the main value area
    args (ProfileArgs): the style arguments for the Profile Box
    h (series float): the highest price of the data
    l (series float): the lowest price of the data
    total (series float): the total data value (e.g. volume of all candles, or just one each to analyse candle distribution over time)
    buckets (Bucket): the Bucket objects holding the data for each price range bucket
    poc_bucket_index (series int): the Bucket index in buckets, that holds the poc Bucket
    vah_bucket_index (series int): the Bucket index in buckets, that holds the vah Bucket
    val_bucket_index (series int): the Bucket index in buckets, that holds the val Bucket
    poc (series float): the according price level marking the Point Of Control
    vah (series float): the according price level marking the Value Area High
    val (series float): the according price level marking the Value Area Low
    plot_poc (Line type from robbatt/lib_plot_objects/24)
    plot_vah (Line type from robbatt/lib_plot_objects/24)
    plot_val (Line type from robbatt/lib_plot_objects/24)
    plot_poc_label (Label type from robbatt/lib_plot_objects/24)
    plot_vah_label (Label type from robbatt/lib_plot_objects/24)
    plot_val_label (Label type from robbatt/lib_plot_objects/24)
    plot_va_fill (LineFill type from robbatt/lib_plot_objects/24)
    plot_profile_bg (Box type from robbatt/lib_plot_objects/24)
Versionshinweise:
v2 export get_ltf function to get reasonable timeframe for request.security_lower_tf
Versionshinweise:
v3

Added:
method apply_style(this, args)
  Namespace types: Profile
  Parameters:
    this (Profile)
    args (ProfileArgs)
Versionshinweise:
v4
Versionshinweise:
v5 fixed max_bars_back error on continuous drawing during replay mode

Updated:
Bucket
  Fields:
    idx (series int): the index of this Bucket within the Profile starting with 0 for the lowest Bucket at the bottom of the Profile
    value (series float): the value of this Bucket, can be volume or time, for using time pass and array of 1s to the update function
    top (series float): the top of this Bucket's price range (for calculation)
    btm (series float): the bottom of this Bucket's price range (for calculation)
    center (series float): the center of this Bucket's price range (for plotting)
    fraction (series float): the fraction this Bucket's value is compared to the total of the Profile
    plot_bucket_line (Line type from robbatt/lib_plot_objects/25): the line that resembles this bucket and it's valeu in the Profile

ProfileArgs
  Fields:
    show_poc (series bool): whether to plot a POC line across the Profile Box (default: true)
    show_profile (series bool): whether to plot a line for each Bucket in the Profile Box, indicating the value per Bucket (Price range), e.g. volume that occured in a certain time and price range (default: false)
    show_va (series bool): whether to plot a VAH/VAL line across the Profile Box (default: false)
    show_va_fill (series bool): whether to fill the 'value' area between VAH/VAL line (default: false)
    show_background (series bool): whether to fill the Profile Box with a background color (default: false)
    show_labels (series bool): whether to add labels to the right end of the POC/VAH/VAL line (default: false)
    show_price_levels (series bool): whether add price values to the labels to the right end of the POC/VAH/VAL line (default: false)
    extend (series bool): whether extend the Profile Box to the current candle (default: false)
    default_size (series int): the default min. width of the Profile Box (default: 30)
    args_poc_line (LineArgs type from robbatt/lib_plot_objects/25): arguments for the poc line plot
    args_va_line (LineArgs type from robbatt/lib_plot_objects/25): arguments for the va line plot
    args_poc_label (LabelArgs type from robbatt/lib_plot_objects/25): arguments for the poc label plot
    args_va_label (LabelArgs type from robbatt/lib_plot_objects/25): arguments for the va label plot
    args_profile_line (LineArgs type from robbatt/lib_plot_objects/25): arguments for the Bucket line plots
    args_profile_bg (BoxArgs type from robbatt/lib_plot_objects/25)
    va_fill_color (series color): color for the va area fill plot

Profile
  Fields:
    start (series int): left x coordinate for the Profile Box
    end (series int): right x coordinate for the Profile Box
    resolution (series int): the amount of buckets/price ranges the Profile will dissect the data into
    vah_threshold_pc (series float): the percentage of the total data value to mark the upper threshold for the main value area
    val_threshold_pc (series float): the percentage of the total data value to mark the lower threshold for the main value area
    args (ProfileArgs): the style arguments for the Profile Box
    h (series float): the highest price of the data
    l (series float): the lowest price of the data
    total (series float): the total data value (e.g. volume of all candles, or just one each to analyse candle distribution over time)
    buckets (Bucket): the Bucket objects holding the data for each price range bucket
    poc_bucket_index (series int): the Bucket index in buckets, that holds the poc Bucket
    vah_bucket_index (series int): the Bucket index in buckets, that holds the vah Bucket
    val_bucket_index (series int): the Bucket index in buckets, that holds the val Bucket
    poc (series float): the according price level marking the Point Of Control
    vah (series float): the according price level marking the Value Area High
    val (series float): the according price level marking the Value Area Low
    plot_poc (Line type from robbatt/lib_plot_objects/25)
    plot_vah (Line type from robbatt/lib_plot_objects/25)
    plot_val (Line type from robbatt/lib_plot_objects/25)
    plot_poc_label (Label type from robbatt/lib_plot_objects/25)
    plot_vah_label (Label type from robbatt/lib_plot_objects/25)
    plot_val_label (Label type from robbatt/lib_plot_objects/25)
    plot_va_fill (LineFill type from robbatt/lib_plot_objects/25)
    plot_profile_bg (Box type from robbatt/lib_plot_objects/25)
Versionshinweise:
v6 changed default coordinates to time based
Versionshinweise:
v7 updated to lib_plot_objects v32, replaced Points with builtin chart.point objects
Versionshinweise:
v8, version bump lib_plot_objects v34

Added:
method hide(this)
  hides this Bucket's plot from the chart by setting the line end to na
  Namespace types: Bucket
  Parameters:
    this (Bucket)

method hide(this)
  hides this Profile's plot from the chart by setting the line end to na
  Namespace types: Profile
  Parameters:
    this (Profile)
Versionshinweise:
v9 default to bar_time for use in higher level lib
Versionshinweise:
v10 added switch for the timeframe selection, so non-premium users can also use the lib below 1h timeframe

Updated:
get_ltf(allow_seconds)
  Parameters:
    allow_seconds (simple bool): if true this will use second based timeframes for the volume data (only for premium users)
Versionshinweise:
v11 version bump to lib_plot_objects v36
Versionshinweise:
v12 refactored history methods, so use case 4 (profile of chart candle range) is easier to control

Updated:
history(src, amount, offset, max_buffer_len)
  allows fetching an array of values from the history series with offset from current candle
  Parameters:
    src (string)
    amount (int)
    offset (int)
    max_buffer_len (simple int)
Versionshinweise:
v13 added parameter to use / disable extend_only functionality of lib_plot_objects

Updated:
method draw(this, forced_width, extend_only)
  draw all components of this Profile (Box, Background, Bucket lines, POC/VAH/VAL overlay levels and labels)
  Namespace types: Profile
  Parameters:
    this (Profile)
    forced_width (int): allows to force width of the Profile Box, overrides the ProfileArgs.default_size and ProfileArgs.extend arguments (default: na)
    extend_only (bool): if false will redraw left coordinates of profile, use in combination with profile.update if same instance is reused.
Versionshinweise:
v14 made buffer length dynamic, so reduce memory consumption during multi parameter profiling.

Updated:
history(src, amount, offset, max_buffer_len)
  allows fetching an array of values from the history series with offset from current candle
  Parameters:
    src (string)
    amount (int)
    offset (int)
    max_buffer_len (int)
Versionshinweise:
v15 default to dynamic buffer sizing
Pine Bibliothek

In echter TradingView-Manier hat der Autor diesen Pine-Code als Open-Source-Bibliothek veröffentlicht, so dass andere Pine-Programmierer aus unserer Community ihn weiterverwenden können. Ein Hoch auf den Autor! Sie können diese Bibliothek privat oder in anderen Open-Source-Publikationen verwenden, aber die Wiederverwendung dieses Codes in einer Publikation unterliegt den Hausregeln.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.

Möchten Sie diese Bibliothek nutzen?

Kopieren Sie die folgende Zeile und fügen Sie sie in Ihr Skript ein.