PINE LIBRARY

iterator

已更新
The "Iterator" library is designed to provide a flexible way to work with sequences of values. This library offers a set of functions to create and manage iterators for various data types, including integers, floats, and more. Whether you need to generate an array of values with specific increments or iterate over elements in reverse order, this library has you covered.

Key Features:
  • Array Creation: Easily generate arrays of integers or floats with customizable steps, both inclusive and exclusive of the end values.
  • Flexible Iteration: Includes methods to iterate over arrays of different types, such as booleans, integers, floats, strings, colors, and drawing objects like lines and labels.
  • Reverse Iteration: Support for reverse iteration, giving you control over the order in which elements are processed.
  • Automatic Loop Control: One of the key advantages of this library is that when using the .iterate() method, it only loops over the array when there are values present. This means you don’t have to manually check if the array is populated before iterating, simplifying your code and reducing potential errors.
  • Versatile Use Cases: Ideal for scenarios where you need to loop over an array without worrying about empty arrays or checking conditions manually.

This library is particularly useful in cases where you need to perform operations on each element in an array, ensuring that your loops are efficient and free from unnecessary checks.


Library "iterator"
The "iterator" library provides a versatile and efficient set of functions for creating and managing iterators.
It allows you to generate arrays of integers or floats with customizable steps, both inclusive and exclusive of the end values.
The library also includes methods for iterating over various types, including booleans, integers, floats, strings, colors,
and drawing objects like lines and labels. With support for reverse iteration and flexible customization options.

iterator(stop, start, step)
  Creates an array of integers from start to stop with a specified step, excluding the stop value.
  Parameters:
    stop (int): The end value of the iterator, exclusive.
    start (int): The starting value of the iterator. Default is 0.
    step (int): The increment value for each step in the iterator. Default is 1. Must be greater than 0.
  Returns: An array of integers incremented by the step value from start to stop. Will return and empty array if start = stop.

iterator(stop, start, step)
  Creates an array of floats from start to stop with a specified step, excluding the stop value.
  Parameters:
    stop (float): The end value of the iterator, exclusive.
    start (float): The starting value of the iterator. Default is 0.
    step (float): The increment value for each step in the iterator. Default is 1. Must be greater than 0.
  Returns: An array of floats incremented by the step value from start to stop. Will return and empty array if start = stop.

iterator_inclusive(stop, start, step)
  Creates an array of integers from start to stop with a specified step, including the stop value.
  Parameters:
    stop (int): The end value of the iterator, inclusive.
    start (int): The starting value of the iterator. Default is 0.
    step (int): The increment value for each step in the iterator. Default is 1. Must be greater than 0.
  Returns: An array of integers incremented by the step value from start to stop, including the stop value.

iterator_inclusive(stop, start, step)
  Creates an array of floats from start to stop with a specified step, including the stop value.
  Parameters:
    stop (float): The end value of the iterator, inclusive.
    start (float): The starting value of the iterator. Default is 0.
    step (float): The increment value for each step in the iterator. Default is 1. Must be greater than 0.
  Returns: An array of floats incremented by the step value from start to stop, including the stop value.

itr(stop, start, step)
  Creates an array of integers from start to stop with a specified step, excluding the stop value.
  Parameters:
    stop (int): The end value of the iterator, exclusive.
    start (int): The starting value of the iterator. Default is 0.
    step (int): The increment value for each step in the iterator. Default is 1. Must be greater than 0.
  Returns: An array of integers incremented by the step value from start to stop.

itr(stop, start, step)
  Creates an array of floats from start to stop with a specified step, excluding the stop value.
  Parameters:
    stop (float): The end value of the iterator, exclusive.
    start (float): The starting value of the iterator. Default is 0.
    step (float): The increment value for each step in the iterator. Default is 1. Must be greater than 0.
  Returns: An array of floats incremented by the step value from start to stop.

itr_in(stop, start, step)
  Creates an array of integers from start to stop with a specified step, including the stop value.
  Parameters:
    stop (int): The end value of the iterator, inclusive.
    start (int): The starting value of the iterator. Default is 0.
    step (int): The increment value for each step in the iterator. Default is 1. Must be greater than 0.
  Returns: An array of integers incremented by the step value from start to stop, including the stop value.

itr_in(stop, start, step)
  Creates an array of floats from start to stop with a specified step, including the stop value.
  Parameters:
    stop (float): The end value of the iterator, inclusive.
    start (float): The starting value of the iterator. Default is 0.
    step (float): The increment value for each step in the iterator. Default is 1. Must be greater than 0.
  Returns: An array of floats incremented by the step value from start to stop, including the stop value.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<bool>
  Parameters:
    self (array<bool>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<int>
  Parameters:
    self (array<int>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<float>
  Parameters:
    self (array<float>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<string>
  Parameters:
    self (array<string>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<color>
  Parameters:
    self (array<color>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<line>
  Parameters:
    self (array<line>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<linefill>
  Parameters:
    self (array<linefill>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<box>
  Parameters:
    self (array<box>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<label>
  Parameters:
    self (array<label>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<chart.point>
  Parameters:
    self (array<chart.point>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<polyline>
  Parameters:
    self (array<polyline>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.

method iterate(self, reverse)
  Creates an iterator array for the indices of ana array, with an option to reverse the order.
  Namespace types: array<table>
  Parameters:
    self (array<table>): The array to iterate over.
    reverse (bool): A boolean flag indicating whether to reverse the iterator order. Default is false.
  Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
發布通知
v2

Sped up reverse so that it dont have to sort lol.
發布通知
v3

fixed bug where it didnt make the arrays correctly
arraysMATHpinepinescriptpythonrangeutilitiesutility

Pine腳本庫

在真正的TradingView精神中,作者將這段Pine程式碼發佈為開源程式庫,以便我們社群的其他Pine程式設計師可以重複使用它。請向作者致敬!您可以私下使用這個函式庫,或在其他開源出版品中使用,但在出版物中再次使用這段程式碼將受到網站規則的約束。

免責聲明