[VWMA] Net Volume LibraryLibrary " Net Volume Library"
TODO: The underlying logic and function that calculates the net volume for the Net Volume indicator. Exposes the nv function and nvPoint fields for use.
nv(src, length, useVwma, offset, sigma, multHigh, multMed, multLow)
Parameters:
src : (float) The source price value
length : (int) The lookback length
useVwma : (bool) To use VWMA in the calculation or not
offset : (float) The ALMA offset value
sigma : (int) The ALMA sigma value
multHigh : (float) The multiplier high band
multMed : (float) The multiplier medium band
multLow : (float) The multiplier low band
Returns: Returns the calculated net volume for each band in an nvPoint object
nvPoint
Fields:
h2
h1
h
n
l
l1
l2
Library
Drawings_publicLibrary "Drawings_public"
: Functions to manage drawings on the chart
extend_line(lineId, labelId)
: Extend specific line with its label
Parameters:
lineId
labelId
update_line_coordinates(lineId, labelId, x1, y1, x2, y2)
: Update specific line coordinates with its label
Parameters:
lineId
labelId
x1
y1
x2
y2
update_label_coordinates(labelId, value)
: Update coordinates of a label
Parameters:
labelId
value
delete_line(lineId, labelId)
: Delete specific line with its label
Parameters:
lineId
labelId
update_box_coordinates(boxId, labelId, left, top, right, bottom)
: Update specific box coordinates with its label
Parameters:
boxId
labelId
left
top
right
bottom
delete_box(boxId, labelId)
: Delete specific box with its label
Parameters:
boxId
labelId
TableBuilderLibrary "TableBuilder"
A helper library to make it simpler to create tables in pinescript
This is a simple table building library that I created because I personally feel that the built-in table building method is too verbose. It features chaining methods and variable arguments.
There are many features that are lacking because the implementation is early, and there may be antipatterns because I am not familiar with the runtime behavior like pinescript. If you have any comments on code improvements or features you want, please comment :D
Vector2FunctionClipLibrary "Vector2FunctionClip"
Sutherland-Hodgman polygon clipping algorithm.
reference:
.
rosettacode.org
.
clip(source, reference)
Perform Clip operation on a vector with another.
Parameters:
source : array . Source polygon to be clipped.
reference : array . Reference polygon to clip source.
Returns: array.
Vector2ArrayLibrary "Vector2Array"
functions to handle vector2 Array operations.
.
references:
docs.unity3d.com
gist.github.com
github.com
gist.github.com
gist.github.com
gist.github.com
.
from(source, prop_sep, vect_sep)
Generate array of vector2 from string.
Parameters:
source : string Source string of the vectors.
prop_sep : string Separator character of the vector properties (x`,`y).
vect_sep : string Separator character of the vectors ((x,y)`;`(x,y)).
Returns: array.
max(vectors)
Combination of the highest elements in column of a array of vectors.
Parameters:
vectors : array, Array of Vector2 objects.
Returns: Vector2.Vector2, Vector2 object.
-> usage:
`a = Vector2.from(1.0) , b = Vector2.from(2.0), c = Vector2.from(3.0), d = max(array.from(a, b, c)) , plot(d.x)`
min(vectors)
Combination of the lowest elements in column of a array of vectors.
Parameters:
vectors : array, Array of Vector2 objects.
Returns: Vector2.Vector2, Vector2 object.
-> usage:
`a = Vector2.from(1.0) , b = Vector2.from(2.0), c = Vector2.from(3.0), d = min(array.from(a, b, c)) , plot(d.x)`
sum(vectors)
Total sum of all vectors.
Parameters:
vectors : array, ID of the vector2 array.
Returns: Vector2.Vector2, vector2 object.
-> usage:
`a = Vector2.from(1.0) , b = Vector2.from(2.0), c = Vector2.from(3.0), d = sum(array.from(a, b, c)) , plot(d.x)`
center(vectors)
Finds the vector center of the array.
Parameters:
vectors : array, ID of the vector2 array.
Returns: Vector2.Vector2, vector2 object.
-> usage:
`a = Vector2.from(1.0) , b = Vector2.from(2.0), c = Vector2.from(3.0), d = center(array.from(a, b, c)) , plot(d.x)`
rotate(vectors, center, degree)
Rotate Array vectors around origin vector by a angle.
Parameters:
vectors : array, ID of the vector2 array.
center : Vector2.Vector2 , Vector2 object. Center of the rotation.
degree : float , Angle value.
Returns: rotated points array.
-> usage:
`a = Vector2.from(1.0) , b = Vector2.from(2.0), c = Vector2.from(3.0), d = rotate(array.from(a, b, c), b, 45.0)`
scale(vectors, center, rate)
Scale Array vectors based on a origin vector perspective.
Parameters:
vectors : array, ID of the vector2 array.
center : Vector2.Vector2 , Vector2 object. Origin center of the transformation.
rate : float , Rate to apply transformation.
Returns: rotated points array.
-> usage:
`a = Vector2.from(1.0) , b = Vector2.from(2.0), c = Vector2.from(3.0), d = scale(array.from(a, b, c), b, 1.25)`
move(vectors, center, rate)
Move Array vectors by a rate of the distance to center position (LERP).
Parameters:
vectors : array, ID of the vector2 array.
center
rate
Returns: Moved points array.
-> usage:
`a = Vector2.from(1.0) , b = Vector2.from(2.0), c = Vector2.from(3.0), d = move(array.from(a, b, c), b, 1.25)`
to_string(id, separator)
Reads a array of vectors into a string, of the form ` `.
Parameters:
id : array, ID of the vector2 array.
separator : string separator for cell splitting.
Returns: string Translated complex array into string.
-> usage:
`a = Vector2.from(1.0) , b = Vector2.from(2.0), c = Vector2.from(3.0), d = to_string(array.from(a, b, c))`
to_string(id, format, separator)
Reads a array of vectors into a string, of the form ` `.
Parameters:
id : array, ID of the vector2 array.
format : string , Format to apply transformation.
separator : string , Separator for cell splitting.
Returns: string Translated complex array into string.
-> usage:
`a = Vector2.from(1.234) , b = Vector2.from(2.23), c = Vector2.from(3.1234), d = to_string(array.from(a, b, c), "#.##")`
Segment2Library "Segment2"
Structure representation of a directed straight line in two dimensions from origin to target vectors.
.
reference:
graphics.stanford.edu
.
new(origin, target)
Generate a new segment.
Parameters:
origin : Vector2 . Origin of the segment.
target : Vector2 . Target of the segment.
Returns: Segment2.
new(origin_x, origin_y, target_x, target_y)
Generate a new segment.
Parameters:
origin_x : float . Origin of the segment x coordinate.
origin_y : float . Origin of the segment y coordinate.
target_x : float . Target of the segment x coordinate.
target_y : float . Target of the segment y coordinate.
Returns: Segment2.
copy(this)
Copy a segment.
Parameters:
this : Vector2 . Segment to copy.
Returns: Segment2.
length_squared(this)
Squared length of the normalized segment vector. For comparing vectors this is computationaly lighter.
Parameters:
this : Segment2 . Sorce segment.
Returns: float.
length(this)
Length of the normalized segment vector.
Parameters:
this : Segment2 . Sorce segment.
Returns: float.
opposite(this)
Reverse the direction of the segment.
Parameters:
this : Segment2 . Source segment.
Returns: Segment2.
is_degenerate(this)
Segment is degenerate when origin and target are equal.
Parameters:
this : Segment2 . Source segment.
Returns: bool.
is_horizontal(this)
Segment is horizontal?.
Parameters:
this : Segment2 . Source segment.
Returns: bool.
is_horizontal(this, precision)
Segment is horizontal?.
Parameters:
this : Segment2 . Source segment.
precision : float . Limit of precision.
Returns: bool.
is_vertical(this)
Segment is vertical?.
Parameters:
this : Segment2 . Source segment.
Returns: bool.
is_vertical(this, precision)
Segment is vertical?.
Parameters:
this : Segment2 . Source segment.
precision : float . Limit of precision.
Returns: bool.
equals(this, other)
Tests two segments for equality (share same origin and target).
Parameters:
this : Segment2 . Source segment.
other : Segment2 . Target segment.
Returns: bool.
nearest_to_point(this, point)
Find the nearest point in a segment to another point.
Parameters:
this : Segment2 . Source segment.
point : Vector2 . Point to aproximate.
Returns: Vector2.
intersection(this, other)
Find the intersection vector of 2 lines.
Parameters:
this : Segment2 . Segment A.
other : Segment2 . Segment B.
Returns: Vector2.Vector2 Object.
extend(this, at_origin, at_target)
Extend a segment by the percent ratio provided.
Parameters:
this : Segment2 . Source segment.
at_origin : float . Percent ratio to extend at origin vector.
at_target : float . Percent ratio to extend at target vector.
Returns: Segment2.
to_string(this)
Translate segment to string format `( (x,y), (x,y) )`.
Parameters:
this : Segment2 . Source segment.
Returns: string.
to_string(this, format)
Translate segment to string format `((x,y), (x,y))`.
Parameters:
this : Segment2 . Source segment.
format : string . Format string to apply.
Returns: string.
to_array(this)
Translate segment to array format.
Parameters:
this : Segment2 . Source segment.
Returns: array.
Vector2DrawQuadLibrary "Vector2DrawQuad"
functions to handle vector2 Quad drawing operations.
new(a, b, c, d, xloc, bg_color, line_color, line_style, line_width)
Draws a quadrilateral with background fill.
Parameters:
a : v2 . Vector2 object, in the form `(x, y)`.
b : v2 . Vector2 object, in the form `(x, y)`.
c : v2 . Vector2 object, in the form `(x, y)`.
d : v2 . Vector2 object, in the form `(x, y)`.
xloc : string . Type of axis unit, bar_index or time.
bg_color : color . Color of the background.
line_color : color . Color of the line.
line_style : string . Style of the line.
line_width : int . Width of the line.
Returns: Quad object.
copy(this)
Copy a existing quad object.
Parameters:
this : Quad . Source quad.
Returns: Quad.
set_position_a(this, x, y)
Set the position of corner `a` (modifies source quad).
Parameters:
this : Quad . Source quad.
x : int . Value at the x axis.
y : float . Value at the y axis.
Returns: Source Quad.
set_position_a(this, position)
Set the position of corner `a` (modifies source quad).
Parameters:
this : Quad . Source quad.
position : Vector2 . New position.
Returns: Source Quad.
set_position_b(this, x, y)
Set the position of corner `b` (modifies source quad).
Parameters:
this : Quad . Source quad.
x : int . Value at the x axis.
y : float . Value at the y axis.
Returns: Source Quad.
set_position_b(this, position)
Set the position of corner `b` (modifies source quad).
Parameters:
this : Quad . Source quad.
position : Vector2 . New position.
Returns: Source Quad.
set_position_c(this, x, y)
Set the position of corner `c` (modifies source quad).
Parameters:
this : Quad . Source quad.
x : int . Value at the x axis.
y : float . Value at the y axis.
Returns: Source Quad.
set_position_c(this, position)
Set the position of corner `c` (modifies source quad).
Parameters:
this : Quad . Source quad.
position : Vector2 . New position.
Returns: Source Quad.
set_position_d(this, x, y)
Set the position of corner `d` (modifies source quad).
Parameters:
this : Quad . Source quad.
x : int . Value at the x axis.
y : float . Value at the y axis.
Returns: Source Quad.
set_position_d(this, position)
Set the position of corner `d` (modifies source quad).
Parameters:
this : Quad . Source quad.
position : Vector2 . New position.
Returns: Source Quad.
set_style(this, bg_color, line_color, line_style, line_width)
Update quad style options (modifies Source quad).
Parameters:
this : Quad . Source quad.
bg_color : color . Color of the background.
line_color : color . Color of the line.
line_style : string . Style of the line.
line_width : int . Width of the line.
Returns: Source Quad.
set_bg_color(this, bg_color)
Update quad style options (modifies Source quad).
Parameters:
this : Quad . Source quad.
bg_color : color . Color of the background.
Returns: Source Quad.
set_line_color(this, line_color)
Update quad style options (modifies Source quad).
Parameters:
this : Quad . Source quad.
line_color : color . Color of the line.
Returns: Source Quad.
set_line_style(this, line_style)
Update quad style options (modifies Source quad).
Parameters:
this : Quad . Source quad.
line_style : string . Style of the line.
Returns: Source Quad.
set_line_width(this, line_width)
Update quad style options (modifies Source quad).
Parameters:
this : Quad . Source quad.
line_width : int . Width of the line.
Returns: Source Quad.
move(this, x, y)
Move quad by provided amount (modifies source quad).
Parameters:
this : Quad . Source quad.
x : float . Amount to move the vertices of the quad in the x axis.
y : float . Amount to move the vertices of the quad in the y axis.
Returns: Source Quad.
move(this, amount)
Move quad by provided amount (modifies source quad).
Parameters:
this : Quad . Source quad.
amount : Vector2 . Amount to move the vertices of the quad in the x and y axis.
Returns: Source Quad.
rotate_around(this, center, angle)
Rotate source quad around a center (modifies source quad).
Parameters:
this : Quad . Source quad.
center : Vector2 . Center coordinates of the rotation.
angle : float . Value of angle in degrees.
Returns: Source Quad.
rotate_around(this, center_x, center_y, angle)
Rotate source quad around a center (modifies source quad).
Parameters:
this : Quad . Source quad.
center_x : int . Center coordinates of the rotation.
center_y : float . Center coordinates of the rotation.
angle : float . Value of angle in degrees.
Returns: Source Quad.
MathComplexNumbersThis is a Pine Script library for handling complex numbers without arrays. It contains several utility functions for performing various operations on complex numbers, including converting complex numbers into tuples, getting the real and imaginary parts of a complex number, adding and subtracting complex numbers, computing the conjugate, multiplying and dividing complex numbers, computing the reciprocal, the inverse, the negative, the exponential, the ceil and the radius of a complex number.
The library exports a complex data type which consists of two float values: re, the real part of the complex number, and im, the imaginary part of the complex number.
The complex_tuple function and ct function convert a complex number into a tuple, and the get_real, get_imaginary, re, and im functions return the real and imaginary parts of a complex number.
The add and subtract functions add and subtract two complex numbers, respectively, by performing the appropriate arithmetic operations on their real and imaginary parts. The conjugate function returns the complex conjugate of a given complex number, which is the same as the original number but with the sign of its imaginary part reversed. The multiply and divide functions multiply and divide two complex numbers, respectively, according to the rules of complex arithmetic. The reciprocal function computes the reciprocal or inverse of a given complex number, while the inverse function computes the inverse of a given complex number. The negative function returns the negative of a given complex number, and the exponential function computes the exponential of a given complex number. The ceil function rounds a given complex number up to a specified number of digits. The radius function computes the radius (magnitude) of a given complex number, which is defined as its distance from the origin (0,0) of the complex plane.
Vector2DrawTriangleLibrary "Vector2DrawTriangle"
Functions to draw a triangle and manipulate its properties.
new(a, b, c, xloc, bg_color, line_color, line_style, line_width)
Draws a triangle with background fill using line prototype.
Parameters:
a : v2 . Vector2 object, in the form `(x, y)`.
b : v2 . Vector2 object, in the form `(x, y)`.
c : v2 . Vector2 object, in the form `(x, y)`.
xloc : string . Type of axis unit, bar_index or time.
bg_color : color . Color of the background.
line_color : color . Color of the line.
line_style : string . Style of the line.
line_width : int . Width of the line.
Returns: Triangle object.
copy(this)
Copy a existing triangle object.
Parameters:
this : Triangle . Source triangle.
Returns: Triangle.
set_position_a(this, x, y)
Set the position of corner `a` (modifies source triangle).
Parameters:
this : Triangle . Source triangle.
x : int . Value at the x axis.
y : float . Value at the y axis.
Returns: Source Triangle.
set_position_a(this, position)
Set the position of corner `a` (modifies source triangle).
Parameters:
this : Triangle . Source triangle.
position : Vector2 . New position.
Returns: Source Triangle.
set_position_b(this, x, y)
Set the position of corner `b` (modifies source triangle).
Parameters:
this : Triangle . Source triangle.
x : int . Value at the x axis.
y : float . Value at the y axis.
Returns: Source Triangle.
set_position_b(this, position)
Set the position of corner `b` (modifies source triangle).
Parameters:
this : Triangle . Source triangle.
position : Vector2 . New position.
Returns: Source Triangle.
set_position_c(this, x, y)
Set the position of corner `c` (modifies source triangle).
Parameters:
this : Triangle . Source triangle.
x : int . Value at the x axis.
y : float . Value at the y axis.
Returns: Source Triangle.
set_position_c(this, position)
Set the position of corner `c` (modifies source triangle).
Parameters:
this : Triangle . Source triangle.
position : Vector2 . New position.
Returns: Source Triangle.
set_style(this, bg_color, line_color, line_style, line_width)
Update triangle style options (modifies Source triangle).
Parameters:
this : Triangle . Source triangle.
bg_color : color . Color of the background.
line_color : color . Color of the line.
line_style : string . Style of the line.
line_width : int . Width of the line.
Returns: Source Triangle.
set_bg_color(this, bg_color)
Update triangle style options (modifies Source triangle).
Parameters:
this : Triangle . Source triangle.
bg_color : color . Color of the background.
Returns: Source Triangle.
set_line_color(this, line_color)
Update triangle style options (modifies Source triangle).
Parameters:
this : Triangle . Source triangle.
line_color : color . Color of the line.
Returns: Source Triangle.
set_line_style(this, line_style)
Update triangle style options (modifies Source triangle).
Parameters:
this : Triangle . Source triangle.
line_style : string . Style of the line.
Returns: Source Triangle.
set_line_width(this, line_width)
Update triangle style options (modifies Source triangle).
Parameters:
this : Triangle . Source triangle.
line_width : int . Width of the line.
Returns: Source Triangle.
move(this, x, y)
Move triangle by provided amount (modifies source triangle).
Parameters:
this : Triangle . Source triangle.
x : float . Amount to move the vertices of the triangle in the x axis.
y : float . Amount to move the vertices of the triangle in the y axis.
Returns: Source Triangle.
move(this, amount)
Move triangle by provided amount (modifies source triangle).
Parameters:
this : Triangle . Source triangle.
amount : Vector2 . Amount to move the vertices of the triangle in the x and y axis.
Returns: Source Triangle.
rotate_around(this, center, angle)
Rotate source triangle around a center (modifies source triangle).
Parameters:
this : Triangle . Source triangle.
center : Vector2 . Center coordinates of the rotation.
angle : float . Value of angle in degrees.
Returns: Source Triangle.
rotate_around(this, center_x, center_y, angle)
Rotate source triangle around a center (modifies source triangle).
Parameters:
this : Triangle . Source triangle.
center_x : int . Center coordinates of the rotation.
center_y : float . Center coordinates of the rotation.
angle : float . Value of angle in degrees.
Returns: Source Triangle.
CommonTypesDrawingLibrary "CommonTypesDrawing"
Provides a common library source for common types of used graphical drawing structures.
Includes: `Triangle, Quad, Polygon`
Triangle
Representation of a triangle using lines and linefill.
Fields:
ab : Edge of point a to b.
bc : Edge of point b to c.
ca : Edge of point c to a.
fill : Fill of the object.
solid : Check if polygon should have a fill.
Quad
Representation of a quadrilateral using lines and linefill.
Fields:
ab : Edge of point a to b.
bc : Edge of point b to c.
cd : Edge of point c to d.
da : Edge of point d to a.
fill : Fill of the object.
solid : Check if polygon should have a fill.
Polygon
Representation of a polygon using lines and linefill.
Fields:
edges : List of edges in the polygon.
fills : Fills of the object.
closed : Check if polygon line should connect last vertice to first.
solid : Check if polygon should have a fill.
Vector2DrawLineLibrary "Vector2DrawLine"
Extends line type with methods for Vector2 and Segment2.
new(origin, target, xloc, extend, color, style, width)
Draws a line using Segment type to hold its coordinate properties..
Parameters:
origin : Vector2 . Origin vector of the line.
target : Vector2 . Target vector of the line.
xloc : string
extend : string
color : color
style : string
width : int
Returns: line object
new(segment, xloc, extend, color, style, width)
Draws a line using Segment type to hold its coordinate properties..
Parameters:
segment : Segment2 . Segment with positional coordinates.
xloc : string
extend : string
color : color
style : string
width : int
Returns: line object
rotate_around(this, center, angle)
Instance method to rotate line around center vector (modifies input line).
Parameters:
this : line . Line object.
center : Vector2 . Center of rotation.
angle : float . Rotation angle in degrees.
Returns: line. Rotated line object.
Vector2Library "Vector2"
Representation of two dimensional vectors or points.
This structure is used to represent positions in two dimensional space or vectors,
for example in spacial coordinates in 2D space.
~~~
references:
docs.unity3d.com
gist.github.com
github.com
gist.github.com
gist.github.com
gist.github.com
~~~
new(x, y)
Create a new Vector2 object.
Parameters:
x : float . The x value of the vector, default=0.
y : float . The y value of the vector, default=0.
Returns: Vector2. Vector2 object.
-> usage:
`unitx = Vector2.new(1.0) , plot(unitx.x)`
from(value)
Assigns value to a new vector `x,y` elements.
Parameters:
value : float, x and y value of the vector.
Returns: Vector2. Vector2 object.
-> usage:
`one = Vector2.from(1.0), plot(one.x)`
from(value, element_sep, open_par, close_par)
Assigns value to a new vector `x,y` elements.
Parameters:
value : string . The `x` and `y` value of the vector in a `x,y` or `(x,y)` format, spaces and parentesis will be removed automatically.
element_sep : string . Element separator character, default=`,`.
open_par : string . Open parentesis character, default=`(`.
close_par : string . Close parentesis character, default=`)`.
Returns: Vector2. Vector2 object.
-> usage:
`one = Vector2.from("1.0,2"), plot(one.x)`
copy(this)
Creates a deep copy of a vector.
Parameters:
this : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = Vector2.new(1.0) , b = a.copy() , plot(b.x)`
down()
Vector in the form `(0, -1)`.
Returns: Vector2. Vector2 object.
left()
Vector in the form `(-1, 0)`.
Returns: Vector2. Vector2 object.
right()
Vector in the form `(1, 0)`.
Returns: Vector2. Vector2 object.
up()
Vector in the form `(0, 1)`.
Returns: Vector2. Vector2 object.
one()
Vector in the form `(1, 1)`.
Returns: Vector2. Vector2 object.
zero()
Vector in the form `(0, 0)`.
Returns: Vector2. Vector2 object.
minus_one()
Vector in the form `(-1, -1)`.
Returns: Vector2. Vector2 object.
unit_x()
Vector in the form `(1, 0)`.
Returns: Vector2. Vector2 object.
unit_y()
Vector in the form `(0, 1)`.
Returns: Vector2. Vector2 object.
nan()
Vector in the form `(float(na), float(na))`.
Returns: Vector2. Vector2 object.
xy(this)
Return the values of `x` and `y` as a tuple.
Parameters:
this : Vector2 . Vector2 object.
Returns: .
-> usage:
`a = Vector2.new(1.0, 1.0) , = a.xy() , plot(ax)`
length_squared(this)
Length of vector `a` in the form. `a.x^2 + a.y^2`, for comparing vectors this is computationaly lighter.
Parameters:
this : Vector2 . Vector2 object.
Returns: float. Squared length of vector.
-> usage:
`a = Vector2.new(1.0, 1.0) , plot(a.length_squared())`
length(this)
Magnitude of vector `a` in the form. `sqrt(a.x^2 + a.y^2)`
Parameters:
this : Vector2 . Vector2 object.
Returns: float. Length of vector.
-> usage:
`a = Vector2.new(1.0, 1.0) , plot(a.length())`
normalize(a)
Vector normalized with a magnitude of 1, in the form. `a / length(a)`.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = normalize(Vector2.new(3.0, 2.0)) , plot(a.y)`
isNA(this)
Checks if any of the components is `na`.
Parameters:
this : Vector2 . Vector2 object.
Returns: bool.
usage:
p = Vector2.new(1.0, na) , plot(isNA(p)?1:0)
add(a, b)
Adds vector `b` to `a`, in the form `(a.x + b.x, a.y + b.y)`.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = one() , b = one() , c = add(a, b) , plot(c.x)`
add(a, b)
Adds vector `b` to `a`, in the form `(a.x + b, a.y + b)`.
Parameters:
a : Vector2 . Vector2 object.
b : float . Value.
Returns: Vector2. Vector2 object.
-> usage:
`a = one() , b = 1.0 , c = add(a, b) , plot(c.x)`
add(a, b)
Adds vector `b` to `a`, in the form `(a + b.x, a + b.y)`.
Parameters:
a : float . Value.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = 1.0 , b = one() , c = add(a, b) , plot(c.x)`
subtract(a, b)
Subtract vector `b` from `a`, in the form `(a.x - b.x, a.y - b.y)`.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = one() , b = one() , c = subtract(a, b) , plot(c.x)`
subtract(a, b)
Subtract vector `b` from `a`, in the form `(a.x - b, a.y - b)`.
Parameters:
a : Vector2 . vector2 object.
b : float . Value.
Returns: Vector2. Vector2 object.
-> usage:
`a = one() , b = 1.0 , c = subtract(a, b) , plot(c.x)`
subtract(a, b)
Subtract vector `b` from `a`, in the form `(a - b.x, a - b.y)`.
Parameters:
a : float . value.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = 1.0 , b = one() , c = subtract(a, b) , plot(c.x)`
multiply(a, b)
Multiply vector `a` with `b`, in the form `(a.x * b.x, a.y * b.y)`.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = one() , b = one() , c = multiply(a, b) , plot(c.x)`
multiply(a, b)
Multiply vector `a` with `b`, in the form `(a.x * b, a.y * b)`.
Parameters:
a : Vector2 . Vector2 object.
b : float . Value.
Returns: Vector2. Vector2 object.
-> usage:
`a = one() , b = 1.0 , c = multiply(a, b) , plot(c.x)`
multiply(a, b)
Multiply vector `a` with `b`, in the form `(a * b.x, a * b.y)`.
Parameters:
a : float . Value.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = 1.0 , b = one() , c = multiply(a, b) , plot(c.x)`
divide(a, b)
Divide vector `a` with `b`, in the form `(a.x / b.x, a.y / b.y)`.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = from(3.0) , b = from(2.0) , c = divide(a, b) , plot(c.x)`
divide(a, b)
Divide vector `a` with value `b`, in the form `(a.x / b, a.y / b)`.
Parameters:
a : Vector2 . Vector2 object.
b : float . Value.
Returns: Vector2. Vector2 object.
-> usage:
`a = from(3.0) , b = 2.0 , c = divide(a, b) , plot(c.x)`
divide(a, b)
Divide value `a` with vector `b`, in the form `(a / b.x, a / b.y)`.
Parameters:
a : float . Value.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = 3.0 , b = from(2.0) , c = divide(a, b) , plot(c.x)`
negate(a)
Negative of vector `a`, in the form `(-a.x, -a.y)`.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = from(3.0) , b = a.negate , plot(b.x)`
pow(a, b)
Raise vector `a` with exponent vector `b`, in the form `(a.x ^ b.x, a.y ^ b.y)`.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = from(3.0) , b = from(2.0) , c = pow(a, b) , plot(c.x)`
pow(a, b)
Raise vector `a` with value `b`, in the form `(a.x ^ b, a.y ^ b)`.
Parameters:
a : Vector2 . Vector2 object.
b : float . Value.
Returns: Vector2. Vector2 object.
-> usage:
`a = from(3.0) , b = 2.0 , c = pow(a, b) , plot(c.x)`
pow(a, b)
Raise value `a` with vector `b`, in the form `(a ^ b.x, a ^ b.y)`.
Parameters:
a : float . Value.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = 3.0 , b = from(2.0) , c = pow(a, b) , plot(c.x)`
sqrt(a)
Square root of the elements in a vector.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = from(3.0) , b = sqrt(a) , plot(b.x)`
abs(a)
Absolute properties of the vector.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = from(-3.0) , b = abs(a) , plot(b.x)`
min(a)
Lowest element of a vector.
Parameters:
a : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(3.0, 1.5) , b = min(a) , plot(b)`
max(a)
Highest element of a vector.
Parameters:
a : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(3.0, 1.5) , b = max(a) , plot(b)`
vmax(a, b)
Highest elements of two vectors.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 2.0) , b = new(2.0, 3.0) , c = vmax(a, b) , plot(c.x)`
vmax(a, b, c)
Highest elements of three vectors.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
c : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 2.0) , b = new(2.0, 3.0) , c = new(1.5, 4.5) , d = vmax(a, b, c) , plot(d.x)`
vmin(a, b)
Lowest elements of two vectors.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 2.0) , b = new(2.0, 3.0) , c = vmin(a, b) , plot(c.x)`
vmin(a, b, c)
Lowest elements of three vectors.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
c : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 2.0) , b = new(2.0, 3.0) , c = new(1.5, 4.5) , d = vmin(a, b, c) , plot(d.x)`
perp(a)
Perpendicular Vector of `a`, in the form `(a.y, -a.x)`.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = perp(a) , plot(b.x)`
floor(a)
Compute the floor of vector `a`.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = floor(a) , plot(b.x)`
ceil(a)
Ceils vector `a`.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = ceil(a) , plot(b.x)`
ceil(a, digits)
Ceils vector `a`.
Parameters:
a : Vector2 . Vector2 object.
digits : int . Digits to use as ceiling.
Returns: Vector2. Vector2 object.
round(a)
Round of vector elements.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = round(a) , plot(b.x)`
round(a, precision)
Round of vector elements.
Parameters:
a : Vector2 . Vector2 object.
precision : int . Number of digits to round vector "a" elements.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(0.123456, 1.234567) , b = round(a, 2) , plot(b.x)`
fractional(a)
Compute the fractional part of the elements from vector `a`.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.123456, 1.23456) , b = fractional(a) , plot(b.x)`
dot_product(a, b)
dot_product product of 2 vectors, in the form `a.x * b.x + a.y * b.y.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = dot_product(a, b) , plot(c)`
cross_product(a, b)
cross product of 2 vectors, in the form `a.x * b.y - a.y * b.x`.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = cross_product(a, b) , plot(c)`
equals(a, b)
Compares two vectors
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: bool. Representing the equality.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = equals(a, b) ? 1 : 0 , plot(c)`
sin(a)
Compute the sine of argument vector `a`.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = sin(a) , plot(b.x)`
cos(a)
Compute the cosine of argument vector `a`.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = cos(a) , plot(b.x)`
tan(a)
Compute the tangent of argument vector `a`.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = tan(a) , plot(b.x)`
atan2(x, y)
Approximation to atan2 calculation, arc tangent of `y/x` in the range (-pi,pi) radians.
Parameters:
x : float . The x value of the vector.
y : float . The y value of the vector.
Returns: float. Value with angle in radians. (negative if quadrante 3 or 4)
-> usage:
`a = new(3.0, 1.5) , b = atan2(a.x, a.y) , plot(b)`
atan2(a)
Approximation to atan2 calculation, arc tangent of `y/x` in the range (-pi,pi) radians.
Parameters:
a : Vector2 . Vector2 object.
Returns: float, value with angle in radians. (negative if quadrante 3 or 4)
-> usage:
`a = new(3.0, 1.5) , b = atan2(a) , plot(b)`
distance(a, b)
Distance between vector `a` and `b`.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = distance(a, b) , plot(c)`
rescale(a, length)
Rescale a vector to a new magnitude.
Parameters:
a : Vector2 . Vector2 object.
length : float . Magnitude.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = 2.0 , c = rescale(a, b) , plot(c.x)`
rotate(a, radians)
Rotates vector by a angle.
Parameters:
a : Vector2 . Vector2 object.
radians : float . Angle value in radians.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = 2.0 , c = rotate(a, b) , plot(c.x)`
rotate_degree(a, degree)
Rotates vector by a angle.
Parameters:
a : Vector2 . Vector2 object.
degree : float . Angle value in degrees.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = 45.0 , c = rotate_degree(a, b) , plot(c.x)`
rotate_around(this, center, angle)
Rotates vector `target` around `origin` by angle value.
Parameters:
this
center : Vector2 . Vector2 object.
angle : float . Angle value in degrees.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = rotate_around(a, b, 45.0) , plot(c.x)`
perpendicular_distance(a, b, c)
Distance from point `a` to line between `b` and `c`.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
c : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(1.5, 2.6) , b = from(1.0) , c = from(3.0) , d = perpendicular_distance(a, b, c) , plot(d.x)`
project(a, axis)
Project a vector onto another.
Parameters:
a : Vector2 . Vector2 object.
axis : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = project(a, b) , plot(c.x)`
projectN(a, axis)
Project a vector onto a vector of unit length.
Parameters:
a : Vector2 . Vector2 object.
axis : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = projectN(a, b) , plot(c.x)`
reflect(a, axis)
Reflect a vector on another.
Parameters:
a : Vector2 . Vector2 object.
axis
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = reflect(a, b) , plot(c.x)`
reflectN(a, axis)
Reflect a vector to a arbitrary axis.
Parameters:
a : Vector2 . Vector2 object.
axis
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = reflectN(a, b) , plot(c.x)`
angle(a)
Angle in radians of a vector.
Parameters:
a : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(3.0, 1.5) , b = angle(a) , plot(b)`
angle_unsigned(a, b)
unsigned degree angle between 0 and +180 by given two vectors.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = angle_unsigned(a, b) , plot(c)`
angle_signed(a, b)
Signed degree angle between -180 and +180 by given two vectors.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = angle_signed(a, b) , plot(c)`
angle_360(a, b)
Degree angle between 0 and 360 by given two vectors
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = angle_360(a, b) , plot(c)`
clamp(a, min, max)
Restricts a vector between a min and max value.
Parameters:
a : Vector2 . Vector2 object.
min
max
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = from(2.5) , d = clamp(a, b, c) , plot(d.x)`
clamp(a, min, max)
Restricts a vector between a min and max value.
Parameters:
a : Vector2 . Vector2 object.
min : float . Lower boundary value.
max : float . Higher boundary value.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = clamp(a, 2.0, 2.5) , plot(b.x)`
lerp(a, b, rate)
Linearly interpolates between vectors a and b by rate.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
rate : float . Value between (a:-infinity -> b:1.0), negative values will move away from b.
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = lerp(a, b, 0.5) , plot(c.x)`
herp(a, b, rate)
Hermite curve interpolation between vectors a and b by rate.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
rate : Vector2 . Vector2 object. Value between (a:0 > 1:b).
Returns: Vector2. Vector2 object.
-> usage:
`a = new(3.0, 1.5) , b = from(2.0) , c = from(2.5) , d = herp(a, b, c) , plot(d.x)`
transform(position, mat)
Transform a vector by the given matrix.
Parameters:
position : Vector2 . Source vector.
mat : M32 . Transformation matrix
Returns: Vector2. Transformed vector.
transform(position, mat)
Transform a vector by the given matrix.
Parameters:
position : Vector2 . Source vector.
mat : M44 . Transformation matrix
Returns: Vector2. Transformed vector.
transform(position, mat)
Transform a vector by the given matrix.
Parameters:
position : Vector2 . Source vector.
mat : matrix . Transformation matrix, requires a 3x2 or a 4x4 matrix.
Returns: Vector2. Transformed vector.
transform(this, rotation)
Transform a vector by the given quaternion rotation value.
Parameters:
this : Vector2 . Source vector.
rotation : Quaternion . Rotation to apply.
Returns: Vector2. Transformed vector.
area_triangle(a, b, c)
Find the area in a triangle of vectors.
Parameters:
a : Vector2 . Vector2 object.
b : Vector2 . Vector2 object.
c : Vector2 . Vector2 object.
Returns: float.
-> usage:
`a = new(1.0, 2.0) , b = from(2.0) , c = from(1.0) , d = area_triangle(a, b, c) , plot(d.x)`
random(max)
2D random value.
Parameters:
max : Vector2 . Vector2 object. Vector upper boundary.
Returns: Vector2. Vector2 object.
-> usage:
`a = from(2.0) , b = random(a) , plot(b.x)`
random(max)
2D random value.
Parameters:
max : float, Vector upper boundary.
Returns: Vector2. Vector2 object.
-> usage:
`a = random(2.0) , plot(a.x)`
random(min, max)
2D random value.
Parameters:
min : Vector2 . Vector2 object. Vector lower boundary.
max : Vector2 . Vector2 object. Vector upper boundary.
Returns: Vector2. Vector2 object.
-> usage:
`a = from(1.0) , b = from(2.0) , c = random(a, b) , plot(c.x)`
random(min, max)
2D random value.
Parameters:
min : Vector2 . Vector2 object. Vector lower boundary.
max : Vector2 . Vector2 object. Vector upper boundary.
Returns: Vector2. Vector2 object.
-> usage:
`a = random(1.0, 2.0) , plot(a.x)`
noise(a)
2D Noise based on Morgan McGuire @morgan3d.
Parameters:
a : Vector2 . Vector2 object.
Returns: Vector2. Vector2 object.
-> usage:
`a = from(2.0) , b = noise(a) , plot(b.x)`
to_string(a)
Converts vector `a` to a string format, in the form `"(x, y)"`.
Parameters:
a : Vector2 . Vector2 object.
Returns: string. In `"(x, y)"` format.
-> usage:
`a = from(2.0) , l = barstate.islast ? label.new(bar_index, 0.0, to_string(a)) : label(na)`
to_string(a, format)
Converts vector `a` to a string format, in the form `"(x, y)"`.
Parameters:
a : Vector2 . Vector2 object.
format : string . Format to apply transformation.
Returns: string. In `"(x, y)"` format.
-> usage:
`a = from(2.123456) , l = barstate.islast ? label.new(bar_index, 0.0, to_string(a, "#.##")) : label(na)`
to_array(a)
Converts vector to a array format.
Parameters:
a : Vector2 . Vector2 object.
Returns: array.
-> usage:
`a = from(2.0) , b = to_array(a) , plot(array.get(b, 0))`
to_barycentric(this, a, b, c)
Captures the barycentric coordinate of a cartesian position in the triangle plane.
Parameters:
this : Vector2 . Source cartesian coordinate position.
a : Vector2 . Triangle corner `a` vertice.
b : Vector2 . Triangle corner `b` vertice.
c : Vector2 . Triangle corner `c` vertice.
Returns: bool.
from_barycentric(this, a, b, c)
Captures the cartesian coordinate of a barycentric position in the triangle plane.
Parameters:
this : Vector2 . Source barycentric coordinate position.
a : Vector2 . Triangle corner `a` vertice.
b : Vector2 . Triangle corner `b` vertice.
c : Vector2 . Triangle corner `c` vertice.
Returns: bool.
to_complex(this)
Translate a Vector2 structure to complex.
Parameters:
this : Vector2 . Source vector.
Returns: Complex.
to_polar(this)
Translate a Vector2 cartesian coordinate into polar coordinates.
Parameters:
this : Vector2 . Source vector.
Returns: Pole. The returned angle is in radians.
Replica of TradingView's Backtesting Engine with ArraysHello everyone,
Here is a perfectly replicated TradingView backtesting engine condensed into a single library function calculated with arrays. It includes TradingView's calculations for Net profit, Total Trades, Percent of Trades Profitable, Profit Factor, Max Drawdown (absolute and percent), and Average Trade (absolute and percent). Here's how TradingView defines each aspect of its backtesting system:
Net Profit: The overall profit or loss achieved.
Total Trades: The total number of closed trades, winning and losing.
Percent Profitable: The percentage of winning trades, the number of winning trades divided by the total number of closed trades.
Profit Factor: The amount of money the strategy made for every unit of money it lost, gross profits divided by gross losses.
Max Drawdown: The greatest loss drawdown, i.e., the greatest possible loss the strategy had compared to its highest profits.
Average Trade: The sum of money gained or lost by the average trade, Net Profit divided by the overall number of closed trades.
Here's how each variable is defined in the library function:
_backtest(bool _enter, bool _exit, float _startQty, float _tradeQty)
bool _enter: When the strategy should enter a trade (entry condition)
bool _exit: When the strategy should exit a trade (exit condition)
float _startQty: The starting capital in the account (for BTCUSD, it is the amount of USD the account starts with)
float _tradeQty: The amount of capital traded (if set to 1000 on BTCUSD, it will trade 1000 USD on each trade)
Currently, this library only works with long strategies, and I've included a commented out section under DEMO STRATEGY where you can replicate my results with TradingView's backtesting engine. There's tons I could do with this beyond what is shown, but this was a project I worked on back in June of 2022 before getting burned out. Feel free to comment with any suggestions or bugs, and I'll try to add or fix them all soon. Here's my list of thing to add to the library currently (may not all be added):
Add commission calculations.
Add support for shorting
Add a graph that resembles TradingView's overview graph.
Clean and optimize code.
Clean up in a way that makes it easy to add other TradingView calculations (such as Sharpe and Sortino ratio).
Separate all variables, so they become accessible outside of calculations (such as gross profit, gross loss, number of winning trades, number of losing trades, etc.).
Thanks for reading,
OztheWoz
HendrixLIBRARY - utilsLibrary "HendrixLIBRARY"
getVolumeData()
getLTF(customTimeframe, ltf)
Parameters:
customTimeframe
ltf
sumArray(a)
Parameters:
a
arrs2vals(upVolumeArray, downVolumeArray, volArr)
Parameters:
upVolumeArray
downVolumeArray
volArr
getVolumesFromUpDownArrays(upVolumeArray, downVolumeArray)
Parameters:
upVolumeArray
downVolumeArray
getDeltaFromVolumes(upVolume, downVolume)
Parameters:
upVolume
downVolume
getDeltaFromUpDownArrays(upVolumeArray, downVolumeArray)
Parameters:
upVolumeArray
downVolumeArray
getUpColor()
getDownColor()
getBlackColor()
getColors()
printTableTR(txt)
Parameters:
txt
printTableBR(txt)
Parameters:
txt
printTableMR(txt)
Parameters:
txt
print(txt, lbl)
Parameters:
txt
lbl
printSyminfo(sym)
Parameters:
sym
ReduceSecurityCallsLibrary "ReduceSecurityCalls"
This library allows you to reduce the number of request.security calls to 1 per symbol per timeframe. Script provides example how to use it with request.security and possible optimisation applied to htf data call.
This data can be used to calculate everything you need and more than that (for example you can calculate 4 emas with one function call on mat_out).
ParseSource(mat_outs, o)
Should be used inside request.security call. Optimise your calls using timeframe.change when htf data parsing! Supports up to 5 expressions (results of expressions must be float or int)
Parameters:
mat_outs : Matrix to be used as outputs, first value is newest
o : Please use parametres in the order they specified (o should be 1st, h should be 2nd etc..)
Returns: outs array, due to weird limitations do not try this :matrix_out = matrix.copy(ParseSource)
SetSessionTimesIndiaLibrary "SetSessionTimesIndia"
This library might be useful to code an indicator or strategy that requires to call Indian trading sessions at NSE and MCX.
SetSessionTimes()
Moving Averages ProxyLibrary "MovingAveragesProxy"
Moving Averages Proxy - Library of all moving averages spread out in different libraries
rvwap(_src, fixedTfInput, minsInput, hoursInput, daysInput, minBarsInput)
Calculates the Rolling VWAP (customized VWAP developed by the team of TradingView)
Parameters:
_src : (float) Source. Default: close
fixedTfInput : (bool) Use a fixed time period. Default: false
minsInput : (int) Minutes. Default: 0
hoursInput : (int) Hours. Default: 0
daysInput : (int) Days. Default: 1
minBarsInput : (int) Bars. Default: 10
Returns: (float) Rolling VWAP
correlationMa(src, len, factor)
Correlation Moving Average
Parameters:
src : (float) Source. Default: close
len : (int) Length
factor : (float) Factor. Default: 1.7
Returns: (float) Correlation Moving Average
regma(src, len, lambda)
Regularized Exponential Moving Average
Parameters:
src : (float) Source. Default: close
len : (int) Length
lambda : (float) Lambda. Default: 0.5
Returns: (float) Regularized Exponential Moving Average
repma(src, len)
Repulsion Moving Average
Parameters:
src : (float) Source. Default: close
len : (int) Length
Returns: (float) Repulsion Moving Average
epma(src, length, offset)
End Point Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
offset : (float) Offset. Default: 4
Returns: (float) End Point Moving Average
lc_lsma(src, length)
1LC-LSMA (1 line code lsma with 3 functions)
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) 1LC-LSMA Moving Average
aarma(src, length)
Adaptive Autonomous Recursive Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Adaptive Autonomous Recursive Moving Average
alsma(src, length)
Adaptive Least Squares
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Adaptive Least Squares
ahma(src, length)
Ahrens Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Ahrens Moving Average
adema(src)
Ahrens Moving Average
Parameters:
src : (float) Source. Default: close
Returns: (float) Moving Average
autol(src, lenDev)
Auto-Line
Parameters:
src : (float) Source. Default: close
lenDev : (int) Length for standard deviation
Returns: (float) Auto-Line
fibowma(src, length)
Fibonacci Weighted Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Moving Average
fisherlsma(src, length)
Fisher Least Squares Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Moving Average
leoma(src, length)
Leo Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Moving Average
linwma(src, period, weight)
Linear Weighted Moving Average
Parameters:
src : (float) Source. Default: close
period : (int) Length
weight : (int) Weight
Returns: (float) Moving Average
mcma(src, length)
McNicholl Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Moving Average
srwma(src, length)
Square Root Weighted Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Moving Average
EDSMA(src, len)
Ehlers Dynamic Smoothed Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: EDSMA smoothing.
dema(x, t)
Double Exponential Moving Average.
Parameters:
x : Series to use ('close' is used if no argument is supplied).
t : Lookback length to use.
Returns: DEMA smoothing.
tema(src, len)
Triple Exponential Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: TEMA smoothing.
smma(src, len)
Smoothed Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: SMMA smoothing.
hullma(src, len)
Hull Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: Hull smoothing.
frama(x, t)
Fractal Reactive Moving Average.
Parameters:
x : Series to use ('close' is used if no argument is supplied).
t : Lookback length to use.
Returns: FRAMA smoothing.
kama(x, t)
Kaufman's Adaptive Moving Average.
Parameters:
x : Series to use ('close' is used if no argument is supplied).
t : Lookback length to use.
Returns: KAMA smoothing.
vama(src, len)
Volatility Adjusted Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: VAMA smoothing.
donchian(len)
Donchian Calculation.
Parameters:
len : Lookback length to use.
Returns: Average of the highest price and the lowest price for the specified look-back period.
Jurik(src, len)
Jurik Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: JMA smoothing.
xema(src, len)
Optimized Exponential Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: XEMA smoothing.
ehma(src, len)
EHMA - Exponential Hull Moving Average
Parameters:
src : Source
len : Period
Returns: Exponential Hull Moving Average (EHMA)
covwema(src, len)
Coefficient of Variation Weighted Exponential Moving Average (COVWEMA)
Parameters:
src : Source
len : Period
Returns: Coefficient of Variation Weighted Exponential Moving Average (COVWEMA)
covwma(src, len)
Coefficient of Variation Weighted Moving Average (COVWMA)
Parameters:
src : Source
len : Period
Returns: Coefficient of Variation Weighted Moving Average (COVWMA)
eframa(src, len, FC, SC)
Ehlrs Modified Fractal Adaptive Moving Average (EFRAMA)
Parameters:
src : Source
len : Period
FC : Lower Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
SC : Upper Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
Returns: Ehlrs Modified Fractal Adaptive Moving Average (EFRAMA)
etma(src, len)
Exponential Triangular Moving Average (ETMA)
Parameters:
src : Source
len : Period
Returns: Exponential Triangular Moving Average (ETMA)
rma(src, len)
RMA - RSI Moving average
Parameters:
src : Source
len : Period
Returns: RSI Moving average (RMA)
thma(src, len)
THMA - Triple Hull Moving Average
Parameters:
src : Source
len : Period
Returns: Triple Hull Moving Average (THMA)
vidya(src, len)
Variable Index Dynamic Average (VIDYA)
Parameters:
src : Source
len : Period
Returns: Variable Index Dynamic Average (VIDYA)
zsma(src, len)
Zero-Lag Simple Moving Average (ZSMA)
Parameters:
src : Source
len : Period
Returns: Zero-Lag Simple Moving Average (ZSMA)
zema(src, len)
Zero-Lag Exponential Moving Average (ZEMA)
Parameters:
src : Source
len : Period
Returns: Zero-Lag Exponential Moving Average (ZEMA)
evwma(src, len)
EVWMA - Elastic Volume Weighted Moving Average
Parameters:
src : Source
len : Period
Returns: Elastic Volume Weighted Moving Average (EVWMA)
tt3(src, len, a1_t3)
Tillson T3
Parameters:
src : Source
len : Period
a1_t3 : Tillson T3 Volume Factor
Returns: Tillson T3
gma(src, len)
GMA - Geometric Moving Average
Parameters:
src : Source
len : Period
Returns: Geometric Moving Average (GMA)
wwma(src, len)
WWMA - Welles Wilder Moving Average
Parameters:
src : Source
len : Period
Returns: Welles Wilder Moving Average (WWMA)
cma(src, len)
Corrective Moving average (CMA)
Parameters:
src : Source
len : Period
Returns: Corrective Moving average (CMA)
edma(src, len)
Exponentially Deviating Moving Average (MZ EDMA)
Parameters:
src : Source
len : Period
Returns: Exponentially Deviating Moving Average (MZ EDMA)
rema(src, len)
Range EMA (REMA)
Parameters:
src : Source
len : Period
Returns: Range EMA (REMA)
sw_ma(src, len)
Sine-Weighted Moving Average (SW-MA)
Parameters:
src : Source
len : Period
Returns: Sine-Weighted Moving Average (SW-MA)
mama(src, len)
MAMA - MESA Adaptive Moving Average
Parameters:
src : Source
len : Period
Returns: MESA Adaptive Moving Average (MAMA)
fama(src, len)
FAMA - Following Adaptive Moving Average
Parameters:
src : Source
len : Period
Returns: Following Adaptive Moving Average (FAMA)
hkama(src, len)
HKAMA - Hilbert based Kaufman's Adaptive Moving Average
Parameters:
src : Source
len : Period
Returns: Hilbert based Kaufman's Adaptive Moving Average (HKAMA)
getMovingAverage(type, src, len, lsmaOffset, inputAlmaOffset, inputAlmaSigma, FC, SC, a1_t3, fixedTfInput, daysInput, hoursInput, minsInput, minBarsInput, lambda, volumeWeighted, gamma_aarma, smooth, linweight, volatility_lookback, jurik_phase, jurik_power)
Abstract proxy function that invokes the calculation of a moving average according to type
Parameters:
type : (string) Type of moving average
src : (float) Source of series (close, high, low, etc.)
len : (int) Period of loopback to calculate the average
lsmaOffset : (int) Offset for Least Squares MA
inputAlmaOffset : (float) Offset for ALMA
inputAlmaSigma : (float) Sigma for ALMA
FC : (int) Lower Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
SC : (int) Upper Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
a1_t3 : (float) Tillson T3 Volume Factor
fixedTfInput : (bool) Use a fixed time period in Rolling VWAP
daysInput : (int) Days in Rolling VWAP
hoursInput : (int) Hours in Rolling VWAP
minsInput : (int) Minutrs in Rolling VWAP
minBarsInput : (int) Bars in Rolling VWAP
lambda : (float) Regularization Constant in Regularized EMA
volumeWeighted : (bool) Apply volume weighted calculation in selected moving average
gamma_aarma : (float) Gamma for Adaptive Autonomous Recursive Moving Average
smooth : (float) Smooth for Adaptive Least Squares
linweight : (float) Weight for Volume Weighted Moving Average
volatility_lookback : (int) Loopback for Volatility Adjusted Moving Average
jurik_phase : (int) Phase for Jurik Moving Average
jurik_power : (int) Power for Jurik Moving Average
Returns: (float) Moving average
L_BetaLibrary "L_Beta"
TODO: add library description here
length()
beta()
simple_beta()
index_selector()
Color Library: Rainbow Index & Simplest Return ColorLibrary "Color Library!"
To help with large projects that need colors!
If you guys make the library bigger, share it so we can all have tons of colors!
2 Functions
Uppercase and Lowercase, because why not?
import library as color
1.) color.this("Brown") // or color.this("brown") both work
2.) color.rainbow(1) //Returns first index of Rainbow
this(x)
TODO: color.this(Brown)
Parameters:
x : TODO: String Color Name
Returns: TODO: Color
rainbow(x)
TODO: Return Rainbow Index
Parameters:
x : TODO: Number is index of Rainbow :)
Returns: TODO: Color
Binance_Min_Limit_Order_amount_libraryLibrary "Binance_Min_Limit_Order_amount_library"
TODO: This library give us the minimum Limit Order amount for the contract in Binance.
m_qty(n_v, m_fee, t_fee, cost, m_t)
TODO: it give us the Minimum Qty for the trading in Binance
Parameters:
n_v : TODO: min_notional_value. 5 dollar is the minimum notional amount in Binance at the moment.
m_fee : TODO: maker_fee %
t_fee : TODO: taker_fee %
cost : TODO: your investing money
m_t : TODO: if you want Limit_Order, put the "T", if you want Market_Order, put the "M" defval="M"
Returns: TODO: for the coin of binance on your chart,
Reference: www.binance.com
MiteTricksLibrary "MiteTricks"
Matrix Global Registry.
Get, Set, automatic growing, universal get/set,
multi-matrix dictionaries, multi-dictionary matrixes..
add slice matrixes of any type, share one common global key registry
pull up an item from a category, and item name ie a table of info.
same cell needs a color, a size, a string, a value, etc..
all of which can be pulled up with the same group id, and key id.
just swap which matrix you pull the value from.
this has a side benefit of non-repainting and recalculating
when pulling values, changing inputs..
makes for very fast/clean usage..
benefit :
floats = value
strings = names
lines = drawn items
table =table of data items for this key
colors = color for line/table/fill,label..
all of those can be pulled with "get(_VALUES,_groupIDX,_keyIDX)" where only the values matrix needs be swapped, and the same item/coordinates remains for all the possible matrixes that item appears in.
also useful as a dictionary/registry for any given type of item,,
and goes very handy with floats/strings/colors/bools with my matrixautotable
very helpful when prototyping or doing development work as a shortcut.
initRegistry()
Registry inititalizer
Returns: registry of string matrix type
newbool(optional, optional, optional)
create bool type new matrix presized 2x2 for reg
Parameters:
optional: row size
optional: column size
optional: fill value(default is bool (na)
Returns: bool matrix of specified size and fill, or blank 2x2 for registry use
newbox(optional, optional, optional)
create box type new matrix presized 2x2 for reg
Parameters:
optional: row size
optional: column size
optional: fill value(default is box (na)
Returns: box matrix of specified size and fill, or blank 2x2 for registry use
newcolor(optional, optional, optional)
create color type new matrix presized 2x2 for reg
Parameters:
optional: row size
optional: column size
optional: fill value(default is color (na)
Returns: color matrix of specified size and fill, or blank 2x2 for registry use
newfloat(optional, optional, optional)
create float type new matrix presized 2x2 for reg
Parameters:
optional: row size
optional: column size
optional: fill value(default is float (na)
Returns: float matrix of specified size and fill, or blank 2x2 for registry use
newint(optional, optional, optional)
create int type new matrix presized 2x2 for reg
Parameters:
optional: row size
optional: column size
optional: fill value(default is int (na)
Returns: int matrix of specified size and fill, or blank 2x2 for registry use
newlabel(optional, optional, optional)
create label type new matrix presized 2x2 for reg
Parameters:
optional: row size
optional: column size
optional: fill value(default is label (na)
Returns: label matrix of specified size and fill, or blank 2x2 for registry use
newline(optional, optional, optional)
create line type new matrix presized 2x2 for reg
Parameters:
optional: row size
optional: column size
optional: fill value(default is line (na)
Returns: line matrix of specified size and fill, or blank 2x2 for registry use
newlinefill(optional, optional, optional)
create linefill type new matrix presized 2x2 for reg
Parameters:
optional: row size
optional: column size
optional: fill value(default is linefill(na)
Returns: linefill matrix of specified size and fill, or blank 2x2 for registry use
newstring(optional, optional, optional)
create string type new matrix presized 2x2 for reg
Parameters:
optional: row size
optional: column size
optional: fill value(default is string (na)
Returns: string matrix of specified size and fill, or blank 2x2 for registry use
newtable(optional, optional, optional)
create table type new matrix presized 2x2 for reg
Parameters:
optional: row size
optional: column size
optional: fill value(default is table (na)
Returns: table matrix of specified size and fill, or blank 2x2 for registry use
newfrom(INIT_FILL)
newfrom Matrix full of item input
Parameters:
INIT_FILL: item to fill (2x2) the matri and set type. a type(na) works
addrow(m, v)
addrow Add new row to matrix
Parameters:
m: matrix of type being added to
v: value of type being added to ( best leave NA on string for registry purposes)
addcolumn(matrix, value)
addcolumn
Parameters:
matrix: of type being added to
value: of type being added to ( best leave NA on string for registry purposes)
get(_VALS, _KEYREG, _GROUP, _KEY)
get Grabs value and returns single item
Parameters:
_VALS: Matrix Values slice
_KEYREG: Registry values matrix (strings)
_GROUP: name of group/category or int group key
_KEY: name of item to fetch from value registry or int key id
Returns: item
get(_VALS, _GROUP, _KEY)
get Grabs value and returns single item
Parameters:
_VALS: Matrix Values slice
_GROUP: name of group/category
_KEY: name of item to fetch from value registry
getgid(_KEYREG, _GROUP)
getgid
Parameters:
_KEYREG: Reg to pull group id from
_GROUP: group index int, or string name to get the other missing type
getkid(_KEYREG, _GROUP, _KEY)
getkid
Parameters:
_KEYREG: Reg to pull Key id from
_GROUP: group index int, or string name
_KEY: index of string key id to get it's ID int
getkey(_KEYREG, _GROUP, _KEY)
getkey
Parameters:
_KEYREG: Reg to pull Key id from
_GROUP: group index int, or string name for getting key string
_KEY: index of string key id to get it's match of other type
set(_VALS, _KEYREG, _GROUP, _KEY, _value)
set items to reg and matrix container
Parameters:
_VALS: Values matrix container
_KEYREG: Key registry
_GROUP: (string) Group/Category name
_KEY: (string) Key for item
_value: item
Returns: void
del(_VALS, _KEYREG, _GROUP, _KEY)
del grroup id
Parameters:
_VALS: Matrix Values slice
_KEYREG: Registry values matrix (strings)
_GROUP: name of group/category
_KEY: name of item to Delete from values and key
detached(_GROUP, _KEY, _VALUE)
detached make detached registry/val matrix
Parameters:
_GROUP: Name of first group
_KEY: Name of first item
_VALUE: Item of any type, sets the output type too.
threengine_global_automation_libraryLibrary "threengine_global_automation_library"
A collection of functions used for trade automation
getBaseCurrency()
Gets the base currency for the chart's ticker. Supported trade pairs are USD, USDT, USDC, BTC, and PERP.
Returns: Base currency as a string
getChartSymbol()
Get the current chart's symbol without the base currency appended to it. Supported trade paris are USD, USDT, USDC, BTC, and PERP.
Returns: Ssymbol and base currency
getDecimals()
Calculates how many decimals are on the quote price of the current market
Returns: The current deimal places on the market quote price
checkVar()
Plot a string as a label on the chart to test variable value. Use str.tostring() for any variable that isn't a string.
Returns: Label with stringified variable
getStrategyAlertMessage()
Generates stringified JSON for a limit order that can be passed to the strategy alert_message for a long entry.
Returns: Stringifed JSON for a long entry
taGetAdx()
Calculates the Average Directional Index
Returns: The value of ADX as a float
taGetEma()
Calculates the EMA based on a type, source, and length. Supported types are EMA, SMA, RMA, and WMA.
Returns: The value of the selected EMA
isBetweenTwoTimes()
Checks to see if within a rage based on two times
@retunrs true/false boolean
getAllTradeIDs()
This gets all closed trades and open trades
@retunrs an array of all open and closed trade ID's
getOpenTradeIDs()
This gets all open trades
@retunrs an array of all open trade ID's
orderAlreadyExists()
This checks to see if a provided order id uses the getAllTradeIDs() function to check
@retunrs an array of all open and closed trade ID's
orderCurrentlyExists()
This checks to see if a provided order id uses the getAllTradeIDs() function to check
Returns: an array of all open and closed trade ID's
getContractCount()
calulates the number of contracts you can buy with a set amount of capital and a limit price
Returns: number of contracts you can buy based on amount of capital you want to use and a price
getLadderSteps()
Returns: array of ladder entry prices and amounts based on total amount you want to invest across all ladder rungs and either a range between ladderStart and LadderStop based on specificed number of ladderRungs OR ladderStart, ladderRungs, and LadderSpacingPercent
"Swap" - Bool/Position/Value : Array / Matrix / Var AutoswapLibrary "swap"
Side / Boundary Based All Types Swapper
- three automagical types for Arrays, Matrixes, and Variables
-- no signal : Long/ Short position autoswap
-- true / false : Boolean based side choice
-- Src / Thresh : if source is above or below the threshold
- two operating modes for variables, Holding mode only for arrays/matrixes
-- with two items, will automatically change between the two caveat is it does not delete table/box/line(fill VAR items automatically)
-- with three items, a neutral is available for NA input or neutral
- one function name for all of them. One import name that's easy to type/remember
-- make life easy for your conditional items.
side(source, thresh, _a, _b, _c)
side Change outputs based on position or a crossing level
Parameters:
source : (float) OPTIONAL value input
thresh : (float) OPTIONAL boundary line to cross
_a : (any) if Long/True/Above
_b : (any) if Short/False/Below
_c : (any) OPTIONAL NOT FOR MTX OR ARR... Neutral Item, if var/varip on a/b it will leave behind, ie, a table or box or line will not erase , if it's a varip you're sending in.
Returns: first, second, or third items based on input conditions
Please notify if bugs found.
Thanks.