peacefulLizard50262

garbage_collection_and_utilities

peacefulLizard50262 アップデート済   
Garbage Collection and Utilities is a library that offers a set of functions designed for efficient management of various types of arrays. This library provides garbage collection utilities to remove and delete excess elements, and also includes utilities for checking the size of arrays. It's particularly useful for developers who want to manage labels, lines, polylines, boxes, linefills, chart points, floats, integers, booleans, and strings efficiently within their scripts.

Both dump and trim act on the array backwards. This means that for trim, the elements that will be left start from 0. If you want the most recent element to be left after trim, you must use unshift().

Garbage Collection:
  • Functions to remove and delete excess elements from various types of arrays.
  • Useful for freeing up memory and keeping the arrays within desired size limits.
Size Checking:
  • Functions to check if arrays are larger than a specified size.
  • Helps in ensuring that arrays have enough elements before performing operations.
Supported Types:
Compatible with a wide range of array types, including labels, lines, polylines, boxes, linefills, chart points, floats, integers, booleans, and strings.

Usage:
The dump methods are ideal for clearing out unwanted elements from arrays, while the trim methods allow for more refined control over the size of arrays.
The ready methods enable you to verify if arrays have the required number of elements before proceeding with further operations.

Library "garbage_collection_and_utilities"
Provides garbage collection utilities for managing and trimming various types of arrays, and utilities to check if an array is of a specific size. Included types are: labels, lines, polylines, boxes, linefills, chart points, floats, integers, booleans, and strings.

method ready(self, size)
  Checks if an array of labels is larger than a specified size
  Namespace types: array<label>
  Parameters:
    self (array<label>)
    size (int): The minimum size of the array
  Returns: A boolean indicating whether the array is ready

method ready(self, size)
  Checks if an array of lines is larger than a specified size
  Namespace types: array<line>
  Parameters:
    self (array<line>)
    size (int): The minimum size of the array
  Returns: A boolean indicating whether the array is ready

method ready(self, size)
  Checks if an array of polylines is larger than a specified size
  Namespace types: array<polyline>
  Parameters:
    self (array<polyline>)
    size (int): The minimum size of the array
  Returns: A boolean indicating whether the array is ready

method ready(self, size)
  Checks if an array of boxes is larger than a specified size
  Namespace types: array<box>
  Parameters:
    self (array<box>)
    size (int): The minimum size of the array
  Returns: A boolean indicating whether the array is ready

method ready(self, size)
  Checks if an array of linefills is larger than a specified size
  Namespace types: array<linefill>
  Parameters:
    self (array<linefill>)
    size (int): The minimum size of the array
  Returns: A boolean indicating whether the array is ready

method ready(self, size)
  Checks if an array of chart points is larger than a specified size
  Namespace types: array<chart.point>
  Parameters:
    self (array<chart.point>)
    size (int): The minimum size of the array
  Returns: A boolean indicating whether the array is ready

method ready(self, size)
  Checks if an array of floats is larger than a specified size
  Namespace types: array<float>
  Parameters:
    self (array<float>)
    size (int): The minimum size of the array
  Returns: A boolean indicating whether the array is ready

method ready(self, size)
  Checks if an array of integers is larger than a specified size
  Namespace types: array<int>
  Parameters:
    self (array<int>)
    size (int): The minimum size of the array
  Returns: A boolean indicating whether the array is ready

method ready(self, size)
  Checks if an array of booleans is larger than a specified size
  Namespace types: array<bool>
  Parameters:
    self (array<bool>)
    size (int): The minimum size of the array
  Returns: A boolean indicating whether the array is ready

method ready(self, size)
  Checks if an array of strings is larger than a specified size
  Namespace types: array<string>
  Parameters:
    self (array<string>)
    size (int): The minimum size of the array
  Returns: A boolean indicating whether the array is ready

method dump(self, max_size, trigger)
  Removes and deletes excess elements from an array of labels
  Namespace types: array<label>
  Parameters:
    self (array<label>)
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the dumping process
  Returns: void

method dump(self, max_size, trigger)
  Removes and deletes excess elements from an array of lines
  Namespace types: array<line>
  Parameters:
    self (array<line>)
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the dumping process
  Returns: void

method dump(self, max_size, trigger)
  Removes and deletes excess elements from an array of polylines
  Namespace types: array<polyline>
  Parameters:
    self (array<polyline>)
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the dumping process
  Returns: void

method dump(self, max_size, trigger)
  Removes and deletes excess elements from an array of boxes
  Namespace types: array<box>
  Parameters:
    self (array<box>)
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the dumping process
  Returns: void

method dump(self, max_size, trigger)
  Removes and deletes excess elements from an array of linefills
  Namespace types: array<linefill>
  Parameters:
    self (array<linefill>)
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the dumping process
  Returns: void

method dump(self, max_size, trigger)
  Removes and deletes excess elements from an array of chart points
  Namespace types: array<chart.point>
  Parameters:
    self (array<chart.point>)
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the dumping process
  Returns: void

method dump(self, max_size, trigger)
  Removes and deletes excess elements from an array of floats
  Namespace types: array<float>
  Parameters:
    self (array<float>)
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the dumping process
  Returns: void

method dump(self, max_size, trigger)
  Removes and deletes excess elements from an array of integers
  Namespace types: array<int>
  Parameters:
    self (array<int>)
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the dumping process
  Returns: void

method dump(self, max_size, trigger)
  Removes and deletes excess elements from an array of booleans
  Namespace types: array<bool>
  Parameters:
    self (array<bool>)
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the dumping process
  Returns: void

method dump(self, max_size, trigger)
  Removes and deletes excess elements from an array of strings
  Namespace types: array<string>
  Parameters:
    self (array<string>)
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the dumping process
  Returns: void

method trim(self, max_size, min_size, trigger)
  Removes excess elements and trims an array of labels
  Namespace types: array<label>
  Parameters:
    self (array<label>)
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void

method trim(self, max_size, min_size, trigger)
  Removes excess elements and trims an array of lines
  Namespace types: array<line>
  Parameters:
    self (array<line>)
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void

method trim(self, max_size, min_size, trigger)
  Removes excess elements and trims an array of polylines
  Namespace types: array<polyline>
  Parameters:
    self (array<polyline>)
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void

method trim(self, max_size, min_size, trigger)
  Removes excess elements and trims an array of boxes
  Namespace types: array<box>
  Parameters:
    self (array<box>)
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void

method trim(self, max_size, min_size, trigger)
  Removes excess elements and trims an array of linefills
  Namespace types: array<linefill>
  Parameters:
    self (array<linefill>)
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void

method trim(self, max_size, min_size, trigger)
  Removes excess elements and trims an array of chart points
  Namespace types: array<chart.point>
  Parameters:
    self (array<chart.point>)
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void

method trim(self, max_size, min_size, trigger)
  Removes excess elements and trims an array of floats
  Namespace types: array<float>
  Parameters:
    self (array<float>)
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void

method trim(self, max_size, min_size, trigger)
  Removes excess elements and trims an array of integers
  Namespace types: array<int>
  Parameters:
    self (array<int>)
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void

method trim(self, max_size, min_size, trigger)
  Removes excess elements and trims an array of booleans
  Namespace types: array<bool>
  Parameters:
    self (array<bool>)
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void

method trim(self, max_size, min_size, trigger)
  Removes excess elements and trims an array of strings
  Namespace types: array<string>
  Parameters:
    self (array<string>)
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void
リリースノート:
v2

Changed the order of arguments for trim so that min_size comes before max_size. Added pop_at() and shift_at() functions. shift_at and pop_at, pop/shift when the array is a specified size.

Added:
method pop_at(self, max_size)
  Removes the last element from an array of strings if the array is larger than a specified size
  Namespace types: array
  Parameters:
    self (array)
    max_size (int): The maximum size of the array
  Returns: void

method shift_at(self, max_size)
  Removes the first element from an array of strings if the array is larger than a specified size
  Namespace types: array
  Parameters:
    self (array)
    max_size (int): The maximum size of the array
  Returns: void

Updated:
method trim(self, min_size, max_size, trigger)
  Removes excess elements and trims an array of strings
  Namespace types: array
  Parameters:
    self (array)
    min_size (int): The minimum size of the array
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the trimming process
  Returns: void
リリースノート:
v3

Added array.length() which allows you to get a 0 indexed array size.
Added pop_for() and shift_for() which is like trim but it uses pop and shift. This is handy if you want to order your arrays arbitrarily.

Added:
method length(self)
  Returns the length of an array of strings, adjusted for zero-based indexing
  Namespace types: array
  Parameters:
    self (array)
  Returns: The length of the array, or -1 if the array is empty

method pop_for(self, min_size, max_size, trigger)
  Removes excess elements from the end of an array of strings using the pop method
  Namespace types: array
  Parameters:
    self (array)
    min_size (int): The minimum size of the array
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the popping process
  Returns: void

method shift_for(self, min_size, max_size, trigger)
  Removes excess elements from the start of an array of strings using the shift method
  Namespace types: array
  Parameters:
    self (array)
    min_size (int): The minimum size of the array
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the shifting process
  Returns: void
リリースノート:
v4

Changed the array.size() - 1 to array.length() in the functions. lol
リリースノート:
v5

Added:
pop_label_at(max_size, trigger)
  Removes and deletes excess labels if the global array of labels is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global array of labels
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_line_at(max_size, trigger)
  Removes and deletes excess lines if the global array of lines is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global array of lines
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_polyline_at(max_size, trigger)
  Removes and deletes excess polylines if the global array of polylines is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global array of polylines
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_box_at(max_size, trigger)
  Removes and deletes excess boxes if the global array of boxes is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global array of boxes
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_linefill_at(max_size, trigger, remove_line)
  Removes and deletes excess linefills if the global array of linefills is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global array of linefills
    trigger (bool): A condition to trigger the popping process
    remove_line (bool): A condition to remove the associated lines when popping linefills
  Returns: void

pop_all_drawings_at(max_size, trigger)
  Removes and deletes excess drawings if any global drawing array is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global drawing arrays
    trigger (bool): A condition to trigger the popping process
  Returns: void

shift_label_at(max_size, trigger)
  Removes and deletes excess labels if the global array of labels is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global array of labels
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_line_at(max_size, trigger)
  Removes and deletes excess lines if the global array of lines is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global array of lines
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_polyline_at(max_size, trigger)
  Removes and deletes excess polylines if the global array of polylines is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global array of polylines
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_box_at(max_size, trigger)
  Removes and deletes excess boxes if the global array of boxes is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global array of boxes
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_linefill_at(max_size, trigger, remove_line)
  Removes and deletes excess linefills if the global array of linefills is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global array of linefills
    trigger (bool): A condition to trigger the shifting process
    remove_line (bool): A condition to remove the associated lines when shifting linefills
  Returns: void

shift_all_drawings_at(max_size, trigger)
  Removes and deletes excess drawings if any global drawing array is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global drawing arrays
    trigger (bool): A condition to trigger the shifting process
  Returns: void
リリースノート:
v6
pop_label_for(max_size, min_size, trigger)
  Removes and deletes excess labels if the global array of labels is larger than a specified size using the pop method
  Parameters:
    max_size (int): The maximum size of the global array of labels
    min_size (int): The minimum size of the global array of labels
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_line_for(max_size, min_size, trigger)
  Removes and deletes excess lines if the global array of lines is larger than a specified size using the pop method
  Parameters:
    max_size (int): The maximum size of the global array of lines
    min_size (int): The minimum size of the global array of lines
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_polyline_for(max_size, min_size, trigger)
  Removes and deletes excess polylines if the global array of polylines is larger than a specified size using the pop method
  Parameters:
    max_size (int): The maximum size of the global array of polylines
    min_size (int): The minimum size of the global array of polylines
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_box_for(max_size, min_size, trigger)
  Removes and deletes excess boxes if the global array of boxes is larger than a specified size using the pop method
  Parameters:
    max_size (int): The maximum size of the global array of boxes
    min_size (int): The minimum size of the global array of boxes
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_linefill_for(max_size, min_size, trigger, remove_line)
  Removes and deletes excess linefills if the global array of linefills is larger than a specified size using the pop method
  Parameters:
    max_size (int): The maximum size of the global array of linefills
    min_size (int): The minimum size of the global array of linefills
    trigger (bool): A condition to trigger the popping process
    remove_line (bool): A condition to remove the associated lines when popping linefills
  Returns: void

pop_all_drawings_for(max_size, min_size, trigger)
  Removes and deletes excess drawings if any global drawing array is larger than a specified size using the pop method
  Parameters:
    max_size (int): The maximum size of the global drawing arrays
    min_size (int): The minimum size of the global drawing arrays
    trigger (bool): A condition to trigger the popping process
  Returns: void

shift_label_for(max_size, min_size, trigger)
  Removes and deletes excess labels if the global array of labels is larger than a specified size using the shift method
  Parameters:
    max_size (int): The maximum size of the global array of labels
    min_size (int): The minimum size of the global array of labels
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_line_for(max_size, min_size, trigger)
  Removes and deletes excess lines if the global array of lines is larger than a specified size using the shift method
  Parameters:
    max_size (int): The maximum size of the global array of lines
    min_size (int): The minimum size of the global array of lines
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_polyline_for(max_size, min_size, trigger)
  Removes and deletes excess elements from the start of an array of polylines using the shift method
  Parameters:
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_box_for(max_size, min_size, trigger)
  Removes and deletes excess elements from the start of an array of boxes using the shift method
  Parameters:
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_linefill_for(max_size, min_size, trigger, remove_line)
  Removes excess elements from the start of an array of linefills using the shift method
  Parameters:
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the shifting process
    remove_line (bool): A condition to remove the associated lines when shifting linefills
  Returns: void

shift_all_drawings_for(max_size, min_size, trigger)
  Removes excess elements from the start of all drawing objects using the shift method
  Parameters:
    max_size (int): The maximum size of the array
    min_size (int): The minimum size of the array
    trigger (bool): A condition to trigger the shifting process
  Returns: void
リリースノート:
v7

fixed order of arguments for x_for() functions and added the remove_line argument.

Updated:
pop_all_drawings_at(max_size, trigger, remove_line)
  Removes and deletes excess drawings if any global drawing array is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global drawing arrays
    trigger (bool): A condition to trigger the popping process
    remove_line (bool)
  Returns: void

shift_all_drawings_at(max_size, trigger, remove_line)
  Removes and deletes excess drawings if any global drawing array is larger than a specified size
  Parameters:
    max_size (int): The maximum size of the global drawing arrays
    trigger (bool): A condition to trigger the shifting process
    remove_line (bool)
  Returns: void

pop_label_for(min_size, max_size, trigger)
  Removes and deletes excess labels if the global array of labels is larger than a specified size using the pop method
  Parameters:
    min_size (int): The minimum size of the global array of labels
    max_size (int): The maximum size of the global array of labels
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_line_for(min_size, max_size, trigger)
  Removes and deletes excess lines if the global array of lines is larger than a specified size using the pop method
  Parameters:
    min_size (int): The minimum size of the global array of lines
    max_size (int): The maximum size of the global array of lines
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_polyline_for(min_size, max_size, trigger)
  Removes and deletes excess polylines if the global array of polylines is larger than a specified size using the pop method
  Parameters:
    min_size (int): The minimum size of the global array of polylines
    max_size (int): The maximum size of the global array of polylines
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_box_for(min_size, max_size, trigger)
  Removes and deletes excess boxes if the global array of boxes is larger than a specified size using the pop method
  Parameters:
    min_size (int): The minimum size of the global array of boxes
    max_size (int): The maximum size of the global array of boxes
    trigger (bool): A condition to trigger the popping process
  Returns: void

pop_linefill_for(min_size, max_size, trigger, remove_line)
  Removes and deletes excess linefills if the global array of linefills is larger than a specified size using the pop method
  Parameters:
    min_size (int): The minimum size of the global array of linefills
    max_size (int): The maximum size of the global array of linefills
    trigger (bool): A condition to trigger the popping process
    remove_line (bool): A condition to remove the associated lines when popping linefills
  Returns: void

pop_all_drawings_for(min_size, max_size, trigger, remove_line)
  Removes and deletes excess drawings if any global drawing array is larger than a specified size using the pop method
  Parameters:
    min_size (int): The minimum size of the global drawing arrays
    max_size (int): The maximum size of the global drawing arrays
    trigger (bool): A condition to trigger the popping process
    remove_line (bool)
  Returns: void

shift_label_for(min_size, max_size, trigger)
  Removes and deletes excess labels if the global array of labels is larger than a specified size using the shift method
  Parameters:
    min_size (int): The minimum size of the global array of labels
    max_size (int): The maximum size of the global array of labels
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_line_for(min_size, max_size, trigger)
  Removes and deletes excess lines if the global array of lines is larger than a specified size using the shift method
  Parameters:
    min_size (int): The minimum size of the global array of lines
    max_size (int): The maximum size of the global array of lines
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_polyline_for(min_size, max_size, trigger)
  Removes and deletes excess elements from the start of an array of polylines using the shift method
  Parameters:
    min_size (int): The minimum size of the array
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_box_for(min_size, max_size, trigger)
  Removes and deletes excess elements from the start of an array of boxes using the shift method
  Parameters:
    min_size (int): The minimum size of the array
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the shifting process
  Returns: void

shift_linefill_for(min_size, max_size, trigger, remove_line)
  Removes excess elements from the start of an array of linefills using the shift method
  Parameters:
    min_size (int): The minimum size of the array
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the shifting process
    remove_line (bool): A condition to remove the associated lines when shifting linefills
  Returns: void

shift_all_drawings_for(min_size, max_size, trigger, remove_line)
  Removes excess elements from the start of all drawing objects using the shift method
  Parameters:
    min_size (int): The minimum size of the array
    max_size (int): The maximum size of the array
    trigger (bool): A condition to trigger the shifting process
    remove_line (bool)
  Returns: void

Pineライブラリ

TradingViewの精神に則り、作者はPineコードをオープンソースライブラリとして公開し、コミュニティの他のPineプログラマーが再利用できるようにしました。作者に敬意を表します!このライブラリを個人的に、または他のオープンソースの投稿で使用することができますが、、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。

このライブラリを使用したいですか?

以下の行をコピーして、スクリプト内に貼り付けてください。