lib_momentumLibrary "lib_momentum"
This library calculates the momentum, derived from a sample range of prior candles. Depending on set MomentumType it either deduces the momentum from the price, volume, or a product of both. If price/product are selected, you can choose from SampleType if only candle body, full range from high to low or a combination of both (body counts full, wicks half for each direction) should be used. Optional: You can choose to normalize the results, dividing each value by its average (normalization_ma_length, normalization_ma). This will allow comparison between different instruments. For the normalization Moving Average you can choose any currently supported in my lib_no_delay.
get_momentum(momentum_type, sample_type, sample_length, normalization_ma_length, normalization_ma)
Parameters:
momentum_type (series MomentumType) : select one of MomentumType. to sample the price, volume or a product of both
sample_type (series SampleType) : select one of SampleType. to sample the body, total range from high to low or a combination of both (body count full, wicks half for each direction)
sample_length (simple int) : how many candles should be sampled (including the current)
normalization_ma_length (simple int) : if you want to normalize results (momentum / momentum average) this sets the period for the average. (default = 0 => no normalization)
normalization_ma (simple MovingAverage enum from robbatt/lib_no_delay/9) : is the type of moving average to normalize / compare with
Returns: returns the current momentum where the total line is not just (up - down) but also sampled over the sample_length and can therefore be used as trend indicator. If up/down fail to reach total's level it's a sign of decreasing momentum, if up/down exceed total the trend it's a sign of increasing momentum.
MATH
analytics_tablesLibrary "analytics_tables"
📝 Description
This library provides the implementation of several performance-related statistics and metrics, presented in the form of tables.
The metrics shown in the afforementioned tables where developed during the past years of my in-depth analalysis of various strategies in an atempt to reason about the performance of each strategy.
The visualization and some statistics where inspired by the existing implementations of the "Seasonality" script, and the performance matrix implementations of @QuantNomad and @ZenAndTheArtOfTrading scripts.
While this library is meant to be used by my strategy framework "Template Trailing Strategy (Backtester)" script, I wrapped it in a library hoping this can be usefull for other community strategy scripts that will be released in the future.
🤔 How to Guide
To use the functionality this library provides in your script you have to import it first!
Copy the import statement of the latest release by pressing the copy button below and then paste it into your script. Give a short name to this library so you can refer to it later on. The import statement should look like this:
import jason5480/analytics_tables/1 as ant
There are three types of tables provided by this library in the initial release. The stats table the metrics table and the seasonality table.
Each one shows different kinds of performance statistics.
The table UDT shall be initialized once using the `init()` method.
They can be updated using the `update()` method where the updated data UDT object shall be passed.
The data UDT can also initialized and get updated on demend depending on the use case
A code example for the StatsTable is the following:
var ant.StatsData statsData = ant.StatsData.new()
statsData.update(SideStats.new(), SideStats.new(), 0)
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var statsTable = ant.StatsTable.new().init(ant.getTablePos('TOP', 'RIGHT'))
statsTable.update(statsData)
A code example for the MetricsTable is the following:
var ant.StatsData statsData = ant.StatsData.new()
statsData.update(ant.SideStats.new(), ant.SideStats.new(), 0)
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var metricsTable = ant.MetricsTable.new().init(ant.getTablePos('BOTTOM', 'RIGHT'))
metricsTable.update(statsData, 10)
A code example for the SeasonalityTable is the following:
var ant.SeasonalData seasonalData = ant.SeasonalData.new().init(Seasonality.monthOfYear)
seasonalData.update()
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var seasonalTable = ant.SeasonalTable.new().init(seasonalData, ant.getTablePos('BOTTOM', 'LEFT'))
seasonalTable.update(seasonalData)
🏋️♂️ Please refer to the "EXAMPLE" regions of the script for more advanced and up to date code examples!
Special thanks to @Mrcrbw for the proposal to develop this library and @DCNeu for the constructive feedback 🏆.
getTablePos(ypos, xpos)
Get table position compatible string
Parameters:
ypos (simple string) : The position on y axise
xpos (simple string) : The position on x axise
Returns: The position to be passed to the table
method init(this, pos, height, width, positiveTxtColor, negativeTxtColor, neutralTxtColor, positiveBgColor, negativeBgColor, neutralBgColor)
Initialize the stats table object with the given colors in the given position
Namespace types: StatsTable
Parameters:
this (StatsTable) : The stats table object
pos (simple string) : The table position string
height (simple float) : The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
width (simple float) : The width of the table as a percentage of the charts height. By default, 0 auto-adjusts the width based on the text inside the cells
positiveTxtColor (simple color) : The text color when positive
negativeTxtColor (simple color) : The text color when negative
neutralTxtColor (simple color) : The text color when neutral
positiveBgColor (simple color) : The background color with transparency when positive
negativeBgColor (simple color) : The background color with transparency when negative
neutralBgColor (simple color) : The background color with transparency when neutral
method init(this, pos, height, width, neutralBgColor)
Initialize the metrics table object with the given colors in the given position
Namespace types: MetricsTable
Parameters:
this (MetricsTable) : The metrics table object
pos (simple string) : The table position string
height (simple float) : The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
width (simple float) : The width of the table as a percentage of the charts width. By default, 0 auto-adjusts the width based on the text inside the cells
neutralBgColor (simple color) : The background color with transparency when neutral
method init(this, seas)
Initialize the seasonal data
Namespace types: SeasonalData
Parameters:
this (SeasonalData) : The seasonal data object
seas (simple Seasonality) : The seasonality of the matrix data
method init(this, data, pos, maxNumOfYears, height, width, extended, neutralTxtColor, neutralBgColor)
Initialize the seasonal table object with the given colors in the given position
Namespace types: SeasonalTable
Parameters:
this (SeasonalTable) : The seasonal table object
data (SeasonalData) : The seasonality data of the table
pos (simple string) : The table position string
maxNumOfYears (simple int) : The maximum number of years that fit into the table
height (simple float) : The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
width (simple float) : The width of the table as a percentage of the charts width. By default, 0 auto-adjusts the width based on the text inside the cells
extended (simple bool) : The seasonal table with extended columns for performance
neutralTxtColor (simple color) : The text color when neutral
neutralBgColor (simple color) : The background color with transparency when neutral
method update(this, wins, losses, numOfInconclusiveExits)
Update the strategy info data of the strategy
Namespace types: StatsData
Parameters:
this (StatsData) : The strategy statistics object
wins (SideStats)
losses (SideStats)
numOfInconclusiveExits (int) : The number of inconclusive trades
method update(this, stats, positiveTxtColor, negativeTxtColor, negativeBgColor, neutralBgColor)
Update the stats table object with the given data
Namespace types: StatsTable
Parameters:
this (StatsTable) : The stats table object
stats (StatsData) : The stats data to update the table
positiveTxtColor (simple color) : The text color when positive
negativeTxtColor (simple color) : The text color when negative
negativeBgColor (simple color) : The background color with transparency when negative
neutralBgColor (simple color) : The background color with transparency when neutral
method update(this, stats, buyAndHoldPerc, positiveTxtColor, negativeTxtColor, positiveBgColor, negativeBgColor)
Update the metrics table object with the given data
Namespace types: MetricsTable
Parameters:
this (MetricsTable) : The metrics table object
stats (StatsData) : The stats data to update the table
buyAndHoldPerc (float) : The buy and hold percetage
positiveTxtColor (simple color) : The text color when positive
negativeTxtColor (simple color) : The text color when negative
positiveBgColor (simple color) : The background color with transparency when positive
negativeBgColor (simple color) : The background color with transparency when negative
method update(this)
Update the seasonal data based on the season and eon timeframe
Namespace types: SeasonalData
Parameters:
this (SeasonalData) : The seasonal data object
method update(this, data, positiveTxtColor, negativeTxtColor, neutralTxtColor, positiveBgColor, negativeBgColor, neutralBgColor, timeBgColor)
Update the seasonal table object with the given data
Namespace types: SeasonalTable
Parameters:
this (SeasonalTable) : The seasonal table object
data (SeasonalData) : The seasonal cell data to update the table
positiveTxtColor (simple color) : The text color when positive
negativeTxtColor (simple color) : The text color when negative
neutralTxtColor (simple color) : The text color when neutral
positiveBgColor (simple color) : The background color with transparency when positive
negativeBgColor (simple color) : The background color with transparency when negative
neutralBgColor (simple color) : The background color with transparency when neutral
timeBgColor (simple color) : The background color of the time gradient
SideStats
Object that represents the strategy statistics data of one side win or lose
Fields:
numOf (series int)
sumFreeProfit (series float)
freeProfitStDev (series float)
sumProfit (series float)
profitStDev (series float)
sumGain (series float)
gainStDev (series float)
avgQuantityPerc (series float)
avgCapitalRiskPerc (series float)
avgTPExecutedCount (series float)
avgRiskRewardRatio (series float)
maxStreak (series int)
StatsTable
Object that represents the stats table
Fields:
table (series table) : The actual table
rows (series int) : The number of rows of the table
columns (series int) : The number of columns of the table
StatsData
Object that represents the statistics data of the strategy
Fields:
wins (SideStats)
losses (SideStats)
numOfInconclusiveExits (series int)
avgFreeProfitStr (series string)
freeProfitStDevStr (series string)
lossFreeProfitStDevStr (series string)
avgProfitStr (series string)
profitStDevStr (series string)
lossProfitStDevStr (series string)
avgQuantityStr (series string)
MetricsTable
Object that represents the metrics table
Fields:
table (series table) : The actual table
rows (series int) : The number of rows of the table
columns (series int) : The number of columns of the table
SeasonalData
Object that represents the seasonal table dynamic data
Fields:
seasonality (series Seasonality)
eonToMatrixRow (map)
numOfEons (series int)
mostRecentMatrixRow (series int)
balances (matrix)
returnPercs (matrix)
maxDDs (matrix)
eonReturnPercs (array)
eonCAGRs (array)
eonMaxDDs (array)
SeasonalTable
Object that represents the seasonal table
Fields:
table (series table) : The actual table
headRows (series int) : The number of head rows of the table
headColumns (series int) : The number of head columns of the table
eonRows (series int) : The number of eon rows of the table
seasonColumns (series int) : The number of season columns of the table
statsRows (series int)
statsColumns (series int) : The number of stats columns of the table
rows (series int) : The number of rows of the table
columns (series int) : The number of columns of the table
extended (series bool) : Whether the table has additional performance statistics
BinaryInsertionSortLibrary "BinaryInsertionSort"
Library containing functions which can help create sorted array based on binary insertion sort.
This sorting will be quicker than array.sort function if the sorting needs to be done on every bar and the size of the array is comparatively big.
method binary_search_basic(sortedArray, item, order)
binary_search_basic - finds the closest index of the value
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (float) : float item which needs to be searched in the sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item can be inserted into sorted array
method binary_search_basic(sortedArray, item, order)
binary_search_basic - finds the closest index of the value
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (int) : int item which needs to be searched in the sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item can be inserted into sorted array
method binary_insertion_sort(sortedArray, item, order)
binary insertion sort - inserts item into sorted array while maintaining sort order
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (float) : float item which needs to be inserted into sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item is inserted into sorted array
method binary_insertion_sort(sortedArray, item, order)
binary insertion sort - inserts item into sorted array while maintaining sort order
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (int) : int item which needs to be inserted into sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item is inserted into sorted array
update_sort_indices(sortIndices, newItemIndex)
adds the sort index of new item added to sorted array and also updates existing sort indices.
Parameters:
sortIndices (array) : array containing sort indices of an array.
newItemIndex (int) : sort index of new item added to sorted array
Returns: void
get_array_of_series(item, order)
Converts series into array and sorted array.
Parameters:
item (float) : float series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
get_array_of_series(item, order)
Converts series into array and sorted array.
Parameters:
item (int) : int series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
get_sorted_arrays(item, order)
Converts series into array and sorted array. Also calculates the sort order of the value array
Parameters:
item (float) : float|int series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
get_sorted_arrays(item, order)
Converts series into array and sorted array. Also calculates the sort order of the value array
Parameters:
item (int) : int series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
lib_no_delayLibrary "lib_no_delay"
This library contains modifications to standard functions that return na before reaching the bar of their 'length' parameter.
That is because they do not compromise speed at current time for correct results in the past. This is good for live trading in short timeframes but killing applications on Monthly / Weekly timeframes if instruments, like in crypto, do not have extensive history (why would you even trade the monthly on a meme coin ... not my decision).
Also, some functions rely on source (value at previous bar), which is not available on bar 1 and therefore cascading to a na value up to the last bar ... which in turn leads to a non displaying indicator and waste of time debugging this)
Anyway ... there you go, let me know if I should add more functions.
sma(source, length)
Parameters:
source (float) : Series of values to process.
length (simple int) : Number of bars (length).
Returns: Simple moving average of source for length bars back.
ema(source, length)
Parameters:
source (float) : Series of values to process.
length (simple int) : Number of bars (length).
Returns: (float) The exponentially weighted moving average of the source.
rma(source, length)
Parameters:
source (float) : Series of values to process.
length (simple int) : Number of bars (length).
Returns: Exponential moving average of source with alpha = 1 / length.
atr(length)
Function atr (average true range) returns the RMA of true range. True range is max(high - low, abs(high - close ), abs(low - close )). This adapted version extends ta.atr to start without delay at first bar and deliver usable data instead of na by averaging ta.tr(true) via manual SMA.
Parameters:
length (simple int) : Number of bars back (length).
Returns: Average true range.
rsi(source, length)
Relative strength index. It is calculated using the ta.rma() of upward and downward changes of source over the last length bars. This adapted version extends ta.rsi to start without delay at first bar and deliver usable data instead of na.
Parameters:
source (float) : Series of values to process.
length (simple int) : Number of bars back (length).
Returns: Relative Strength Index.
Time Zone CorrectorThe Time Zone Corrector library provides a utility function designed to adjust time based on the user's current time zone. This library supports a wide range of time zones across the Americas, Europe, Asia, and Oceania, making it highly versatile for traders around the world. It simulates a switch-case structure using ternary operators to output the appropriate time offset relative to UTC.
Whether you're dealing with market sessions in New York, Tokyo, London, or other major trading hubs, this library helps ensure your trading algorithms can accurately account for time differences. The library is particularly useful for strategies that rely on precise timing, as it dynamically adjusts the time zone offset depending on the symbol being traded.
iteratorThe "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
Parameters:
self (array) : 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
Parameters:
self (array) : 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
Parameters:
self (array) : 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
Parameters:
self (array) : 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
Parameters:
self (array) : 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
Parameters:
self (array) : 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
Parameters:
self (array) : 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
Parameters:
self (array) : 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
Parameters:
self (array) : 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
Parameters:
self (array) : 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
Parameters:
self (array) : 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
Parameters:
self (array) : 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.
LibraryBitwiseOperandsLibrary "LibraryBitwiseOperands"
Description: When you need more space for your data you can use bitwise operations. For example if you are creating an Order Block indicator and you have multiple types then you can define variables for each type with only one bit set like these:
const int TYPE_OB = 1
const int TYPE_HH = 2
const int TYPE_LH = 4
const int TYPE_HL = 8
const int TYPE_LL = 16
const int TYPE_BOS = 32
const int TYPE_CHOCH = 64
bitwise_shift_left(x, y)
bitwise_shift_left(): Bitwise left shift: x << y
Parameters:
x (int)
y (int)
Returns: : The left operand’s value is moved toward left by the number of bits specified by the right operand.
bitwise_shift_right(x, y)
bitwise_shift_right(): Bitwise right shift: x >> y
Parameters:
x (int)
y (int)
Returns: : The left operand’s value is moved toward right by the number of bits specified by the right operand.
bitwise_not(x)
bitwise_not(): Bitwise NOT: ~x
Parameters:
x (int)
Returns: : Inverts individual bits.
bitwise_and(x, y)
bitwise_and(): Bitwise AND: x & y
Parameters:
x (int)
y (int)
Returns: : Result bit 1, if both operand bits are 1; otherwise results bit 0.
bitwise_or(x, y)
bitwise_or(): Bitwise OR: x | y
Parameters:
x (int)
y (int)
Returns: : Result bit 1, if any of the operand bit is 1; otherwise results bit 0.
bitwise_xor(x, y)
bitwise_xor(): Bitwise (exclusive OR) XOR: x ^ y
Parameters:
x (int)
y (int)
Returns: : Result bit 1, if any of the operand bit is 1 but not both, otherwise results bit 0.
logical_xor(x, y)
logical_xor(): Logical (exclusive OR) XOR: x xor y
Parameters:
x (bool)
y (bool)
Returns: : Result true, if any of the operand bit are different, otherwise results bit 0.
bit_check(x, y)
bit_check(): Bitwise Checks the specified bit
Parameters:
x (int)
y (int)
Returns: : Returns True if the bit is set.
bit_set(x, y)
bit_set(): Bitwise Sets the specified bit
Parameters:
x (int)
y (int)
Returns: : Returns a value with the bit set.
bit_clear(x, y)
bit_clear(): Bitwise Clears the specified bit
Parameters:
x (int)
y (int)
Returns: : Returns a value with the bit cleared.
bit_flip(x, y)
bit_flip(): Bitwise Inverts the specified bit
Parameters:
x (int)
y (int)
Returns: : Returns a value with the bit inverted.
bitmask_check(x, mask)
bitmask_check(): Bitwise Checks the specified Mask
Parameters:
x (int)
mask (int)
Returns: : Returns True if the mask is set.
bitmask_set(x, mask)
bitmask_set(): Bitwise Sets the specified Mask
Parameters:
x (int)
mask (int)
Returns: : Returns a value with the mask set.
bitmask_clear(x, mask)
bitmask_clear(): Bitwise Clears the specified Mask
Parameters:
x (int)
mask (int)
Returns: : Returns a value with the mask cleared.
bitmask_flip(x, mask)
bitmask_flip(): Inverts the specified Mask
Parameters:
x (int)
mask (int)
Returns: : Returns a value with the mask inverted.
math_bit_check(x, y)
math_bit_check(): Fast arithmetic bitwise Checks the specified Mask
Parameters:
x (int)
y (int)
Returns: : Returns True if the mask is set.
math_bit_set(x, y)
math_bit_set(): Fast arithmetic bitwise Sets the specified bit
Parameters:
x (int)
y (int)
Returns: : Returns a value with the bit set.
math_bit_clear(x, y)
math_bit_clear(): Fast arithmetic bitwise Clears the specified bit
Parameters:
x (int)
y (int)
Returns: : Returns a value with the bit cleared.
math_bitmask_check(x, y)
math_bitmask_check(): Fast arithmetic bitwise Checks the specified Mask
Parameters:
x (int)
y (int)
Returns: : Returns True if the mask is set.
math_bitmask_set(x, y)
math_bitmask_set(): Fast arithmetic bitwise Sets the specified Mask
Parameters:
x (int)
y (int)
Returns: : Returns a value with the mask set.
math_bitmask_clear(x, y)
math_bitmask_clear(): Fast arithmetic bitwise Clears the specified Mask
Parameters:
x (int)
y (int)
Returns: : Returns a value with the mask cleared.
SpectrumLibrary "Spectrum"
This library includes spectrum analysis tools such as the Fast Fourier Transform (FFT).
method toComplex(data, polar)
Creates an array of complex type objects from a float type array.
Namespace types: array
Parameters:
data (array) : The float type array of input data.
polar (bool) : Initialization coordinates; the default is false (cartesian).
Returns: The complex type array of converted data.
method sAdd(data, value, end, start, step)
Performs scalar addition of a given float type array and a simple float value.
Namespace types: array
Parameters:
data (array) : The float type array of input data.
value (float) : The simple float type value to be added.
end (int) : The last index of the input array (exclusive) on which the operation is performed.
start (int) : The first index of the input array (inclusive) on which the operation is performed; the default value is 0.
step (int) : The step by which the function iterates over the input data array between the specified boundaries; the default value is 1.
Returns: The modified input array.
method sMult(data, value, end, start, step)
Performs scalar multiplication of a given float type array and a simple float value.
Namespace types: array
Parameters:
data (array) : The float type array of input data.
value (float) : The simple float type value to be added.
end (int) : The last index of the input array (exclusive) on which the operation is performed.
start (int) : The first index of the input array (inclusive) on which the operation is performed; the default value is 0.
step (int) : The step by which the function iterates over the input data array between the specified boundaries; the default value is 1.
Returns: The modified input array.
method eMult(data, data02, end, start, step)
Performs elementwise multiplication of two given complex type arrays.
Namespace types: array
Parameters:
data (array type from RezzaHmt/Complex/1) : the first complex type array of input data.
data02 (array type from RezzaHmt/Complex/1) : The second complex type array of input data.
end (int) : The last index of the input arrays (exclusive) on which the operation is performed.
start (int) : The first index of the input arrays (inclusive) on which the operation is performed; the default value is 0.
step (int) : The step by which the function iterates over the input data array between the specified boundaries; the default value is 1.
Returns: The modified first input array.
method eCon(data, end, start, step)
Performs elementwise conjugation on a given complex type array.
Namespace types: array
Parameters:
data (array type from RezzaHmt/Complex/1) : The complex type array of input data.
end (int) : The last index of the input array (exclusive) on which the operation is performed.
start (int) : The first index of the input array (inclusive) on which the operation is performed; the default value is 0.
step (int) : The step by which the function iterates over the input data array between the specified boundaries; the default value is 1.
Returns: The modified input array.
method zeros(length)
Creates a complex type array of zeros.
Namespace types: series int, simple int, input int, const int
Parameters:
length (int) : The size of array to be created.
method bitReverse(data)
Rearranges a complex type array based on the bit-reverse permutations of its size after zero-padding.
Namespace types: array
Parameters:
data (array type from RezzaHmt/Complex/1) : The complex type array of input data.
Returns: The modified input array.
method R2FFT(data, inverse)
Calculates Fourier Transform of a time series using Cooley-Tukey Radix-2 Decimation in Time FFT algorithm, wikipedia.org
Namespace types: array
Parameters:
data (array type from RezzaHmt/Complex/1) : The complex type array of input data.
inverse (int) : Set to -1 for FFT and to 1 for iFFT.
Returns: The modified input array containing the FFT result.
method LBFFT(data, inverse)
Calculates Fourier Transform of a time series using Leo Bluestein's FFT algorithm, wikipedia.org This function is nearly 4 times slower than the R2FFT function in practice.
Namespace types: array
Parameters:
data (array type from RezzaHmt/Complex/1) : The complex type array of input data.
inverse (int) : Set to -1 for FFT and to 1 for iFFT.
Returns: The modified input array containing the FFT result.
method DFT(data, inverse)
This is the original DFT algorithm. It is not suggested to be used regularly.
Namespace types: array
Parameters:
data (array type from RezzaHmt/Complex/1) : The complex type array of input data.
inverse (int) : Set to -1 for DFT and to 1 for iDFT.
Returns: The complex type array of DFT result.
GraphLibrary "Graph"
Library to collect data and draw scatterplot and heatmap as graph
method init(this)
Initialise Quadrant Data
Namespace types: Quadrant
Parameters:
this (Quadrant) : Quadrant object that needs to be initialised
Returns: current Quadrant object
method init(this)
Initialise Graph Data
Namespace types: Graph
Parameters:
this (Graph) : Graph object that needs to be initialised with 4 Quadrants
Returns: current Graph object
method add(this, data)
Add coordinates to graph
Namespace types: Graph
Parameters:
this (Graph) : Graph object
data (Coordinate) : Coordinates containing x, y data
Returns: current Graph object
method calculate(this)
Calculation required for plotting the graph
Namespace types: Graph
Parameters:
this (Graph) : Graph object
Returns: current Graph object
method paint(this)
Draw graph
Namespace types: Graph
Parameters:
this (Graph) : Graph object
Returns: current Graph object
Coordinate
Coordinates of sample data
Fields:
xValue (series float) : x value of the sample data
yValue (series float) : y value of the sample data
Quadrant
Data belonging to particular quadrant
Fields:
coordinates (array) : Coordinates present in given quadrant
GraphProperties
Properties of Graph that needs to be drawn
Fields:
rows (series int) : Number of rows (y values) in each quadrant
columns (series int) : number of columns (x values) in each quadrant
graphtype (series GraphType) : Type of graph - scatterplot or heatmap
plotColor (series color) : color of plots or heatmap
plotSize (series string) : size of cells in the table
plotchar (series string) : Character to be printed for display of scatterplot
outliers (series int) : Excude the outlier percent of data from calculating the min and max
position (series string) : Table position
bgColor (series color) : graph background color
PlotRange
Range of a plot in terms of x and y values and the number of data points that fall within the Range
Fields:
minX (series float) : min range of X value
maxX (series float) : max range of X value
minY (series float) : min range of Y value
maxY (series float) : max range of Y value
count (series int) : number of samples in the range
Graph
Graph data and properties
Fields:
properties (GraphProperties) : Graph Properties object associated
quadrants (array) : Array containing 4 quadrant data
plotRanges (matrix) : range and count for each cell
xArray (array) : array of x values
yArray (array) : arrray of y values
MarketAnalysisLibrary "MarketAnalysis"
A collection of frequently used market analysis functions in my scripts.
bullFibRet(priceLow, priceHigh, fibLevel)
Calculates a bullish fibonacci retracement value.
Parameters:
priceLow (float) : (float) The lowest price point.
priceHigh (float) : (float) The highest price point.
fibLevel (float) : (float) The fibonacci level to calculate.
Returns: The fibonacci value of the given retracement level.
bearFibRet(priceLow, priceHigh, fibLevel)
Calculates a bearish fibonacci retracement value.
Parameters:
priceLow (float) : (float) The lowest price point.
priceHigh (float) : (float) The highest price point.
fibLevel (float) : (float) The fibonacci level to calculate.
Returns: The fibonacci value of the given retracement level.
bullFibExt(priceLow, priceHigh, thirdPivot, fibLevel)
Calculates a bullish fibonacci extension value.
Parameters:
priceLow (float) : (float) The lowest price point.
priceHigh (float) : (float) The highest price point.
thirdPivot (float) : (float) The third price point.
fibLevel (float) : (float) The fibonacci level to calculate.
Returns: The fibonacci value of the given extension level.
bearFibExt(priceLow, priceHigh, thirdPivot, fibLevel)
Calculates a bearish fibonacci extension value.
Parameters:
priceLow (float) : (float) The lowest price point.
priceHigh (float) : (float) The highest price point.
thirdPivot (float) : (float) The third price point.
fibLevel (float) : (float) The fibonacci level to calculate.
Returns: The fibonacci value of the given extension level.
ComplexLibrary "Complex"
This library includes user-defined complex type, and functions to perform basic arithmetic operations on complex numbers.
real(radius, angle)
Calculates the real part of a complex number based on its polar coordinates.
Parameters:
radius (float)
angle (float)
imag(radius, angle)
Calculates the imaginary part of a complex number based on its polar coordinates.
Parameters:
radius (float)
angle (float)
rds(real, imag)
Calculates the radius of a complex number based on its cartesian coordinates.
Parameters:
real (float)
imag (float)
ang(real, imag)
Calculates the angle of a complex number based on its cartesian coordinates.
Parameters:
real (float)
imag (float)
method realP(c)
Calculates the real part of a complex number represented in polar coordinates.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in polar coordinates.
method imagP(c)
Calculates the imaginary part of a complex number represented in polar coordinates.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in polar coordinates.
method rdsC(c)
Calculates the radius of a complex number represented in cartesian coordinates.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in cartesian coordinates.
method angC(c)
Calculates the angle of a complex number represented in cartesian coordinates.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in cartesian coordinates.
method toCart(c)
Converts a complex number from its polar representation to cartesian.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in polar coordinates.
method toPolar(c)
Converts a complex number from its cartesian representation to polar.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in cartesian coordinates.
method addC(c, z)
Calculates the addition of two complex numbers represented in cartesian coordinates.
Namespace types: complex
Parameters:
c (complex) : First complex number expressed in cartesian coordinates.
z (complex) : Second complex number expressed in cartesian coordinates.
method addP(c, z)
Calculates the addition of two complex numbers represented in polar coordinates. Performing addition and subtraction operations in cartesian form of complex numbers is more efficient.
Namespace types: complex
Parameters:
c (complex) : First complex number expressed in polar coordinates.
z (complex) : Second complex number expressed in polar coordinates.
method subC(c, z)
Calculates the subtraction of two complex numbers represented in cartesian coordinates.
Namespace types: complex
Parameters:
c (complex) : First complex number expressed in cartesian coordinates.
z (complex) : Second complex number expressed in cartesian coordinates.
method subP(c, z)
Calculates the subtraction of two complex numbers represented in polar coordinates.
Namespace types: complex
Parameters:
c (complex) : First complex number expressed in polar coordinates.
z (complex) : Second complex number expressed in polar coordinates.
method multC(c, z)
Calculates the multiplication of two complex numbers represented in cartesian coordinates. Performing multiplication in polar form of complex numbers is more efficient.
Namespace types: complex
Parameters:
c (complex) : First complex number expressed in cartesian coordinates.
z (complex) : Second complex number expressed in cartesian coordinates.
method multP(c, z)
Calculates the multiplication of two complex numbers represented in polar coordinates.
Namespace types: complex
Parameters:
c (complex) : First complex number expressed in polar coordinates.
z (complex) : Second complex number expressed in polar coordinates.
method powC(c, exp, shift)
Exponentiates a complex number represented in cartesian coordinates.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in cartesian coordinates.
exp (float) : The exponent.
shift (float) : The phase shift of the operation. The shift is equal to 2kπ, where k is an integer number from zero to the denominator of the exponent (exclusive). Calculation of the shift value is not included in the function since it isn't always needed and for the purpose of efficiency. Use a for loop to obtain all possible results.
method powP(c, exp, shift)
Exponentiates a complex number represented in polar coordinates.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in polar coordinates.
exp (float) : The exponent.
shift (float) : The phase shift of the operation. The shift is equal to 2kπ, where k is an integer number from zero to the denominator of the exponent (exclusive). Calculation of the shift value is not included in the function since it isn't always needed and for the purpose of efficiency. Use a for loop to obtain all possible results.
method invC(c)
Calculates the multiplicative inverse of a complex number represented in cartesian coordinates.
Namespace types: complex
Parameters:
c (complex)
method invP(c)
Calculates the multiplicative inverse of a complex number represented in polar coordinates.
Namespace types: complex
Parameters:
c (complex)
method negC(c)
Negates a complex number represented in cartesian coordinates.
Namespace types: complex
Parameters:
c (complex)
method negP(c)
Negates a complex number represented in polar coordinates.
Namespace types: complex
Parameters:
c (complex)
method con(c)
Calculates the conjugate of a complex number in either forms.
Namespace types: complex
Parameters:
c (complex)
method fAddC(c, d)
Calculates the addition of a complex number represented in cartesian coordinates and a real number.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in cartesian coordinates.
d (float)
Returns: The complex number resulted by the addition in cartesian form.
method fAddP(c, d)
Calculates the addition of a complex number represented in polar coordinates and a real number.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in polar coordinates.
d (float)
Returns: The complex number resulted by the addition in polar form.
method fMultC(c, d)
Calculates the multiplication of a complex number represented in cartesian coordinates and a real number.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in cartesian coordinates.
d (float)
Returns: The complex number resulted by the multiplication in cartesian form.
method fMultP(c, d)
Calculates the multiplication of a complex number represented in polar coordinates and a real number.
Namespace types: complex
Parameters:
c (complex) : A complex number expressed in polar coordinates.
d (float)
Returns: The complex number resulted by the multiplication in polar form.
complex
Complex number expressed in polar or cartesian coordinates.
Fields:
R (series float) : Real part or radius of the complex number.
J (series float) : Imaginary part or angle (phase) of the complex number.
iP (series bool) : This field is employed to keep track of the coordinates of the number. Note that the functions do not verify this field for the purpose of efficiency.
BinaryLibrary "Binary"
This library includes functions to convert between decimal and binary numeral formats, and logical and arithmetic operations on binary numbers.
method toBin(value)
Converts the provided boolean value into binary integers (0 or 1).
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value (bool) : The boolean value to be converted.
Returns: The converted value in binary integers.
method dec2bin(value, iBits, fBits)
Converts a decimal number into its binary representation.
Namespace types: series float, simple float, input float, const float
Parameters:
value (float) : The decimal number to be converted.
iBits (int) : The number of binary digits allocated for the integer part.
fBits (int) : The number of binary digits allocated for the fractional part.
Returns: An array containing the binary digits for the integer part at the rightmost positions and the digits for the fractional part at the leftmost positions. The array indexes correspond to the bit positions.
method bin2dec(value, iBits, fBits)
Converts a binary number into its decimal representation.
Namespace types: array
Parameters:
value (array) : The binary number to be converted.
iBits (int) : The number of binary digits allocated for the integer part.
fBits (int) : The number of binary digits allocated for the fractional part.
Returns: The converted value in decimal format.
method lgcAnd(a, b)
Bitwise logical AND of two binary numbers. The result of ANDing two binary digits is 1 only if both digits are 1, otherwise, 0.
Namespace types: array
Parameters:
a (array) : First binary number.
b (array) : Second binary number.
Returns: An array containing the logical AND of the inputs.
method lgcOr(a, b)
Bitwise logical OR of two binary numbers. The result of ORing two binary digits is 0 only if both digits are 0, otherwise, 1.
Namespace types: array
Parameters:
a (array) : First binary number.
b (array) : Second binary number.
Returns: An array containing the logical OR of the inputs.
method lgcXor(a, b)
Bitwise logical XOR of two binary numbers. The result of XORing two binary digits is 1 only if ONE of the digits is 1, otherwise, 0.
Namespace types: array
Parameters:
a (array) : First binary number.
b (array) : Second binary number.
Returns: An array containing the logical XOR of the inputs.
method lgcNand(a, b)
Bitwise logical NAND of two binary numbers. The result of NANDing two binary digits is 0 only if both digits are 1, otherwise, 1.
Namespace types: array
Parameters:
a (array) : First binary number.
b (array) : Second binary number.
Returns: An array containing the logical NAND of the inputs.
method lgcNor(a, b)
Bitwise logical NOR of two binary numbers. The result of NORing two binary digits is 1 only if both digits are 0, otherwise, 0.
Namespace types: array
Parameters:
a (array) : First binary number.
b (array) : Second binary number.
Returns: An array containing the logical NOR of the inputs.
method lgcNot(a)
Bitwise logical NOT of a binary number. The result of NOTing a binary digit is 0 if the digit is 1, or vice versa.
Namespace types: array
Parameters:
a (array) : A binary number.
Returns: An array containing the logical NOT of the input.
method lgc2sC(a)
2's complement of a binary number. The 2's complement of a binary number N with n digits is defined as 2^(n) - N.
Namespace types: array
Parameters:
a (array) : A binary number.
Returns: An array containing the 2's complement of the input.
method shift(value, direction, newBit)
Shifts a binary number in the specified direction by one position.
Namespace types: array
Parameters:
value (array)
direction (int) : The direction of the shift operation.
newBit (int) : The bit to be inserted into the unoccupied slot.
Returns: A tuple of the shifted binary number and the serial output of the shift operation.
method multiShift(value, direction, newBits)
Shifts a binary number in the specified direction by multiple positions.
Namespace types: array
Parameters:
value (array)
direction (int) : The direction of the shift operation.
newBits (array)
Returns: A tuple of the shifted binary number and the serial output of the shift operation.
method crclrShift(value, direction, count)
Circularly shifts a binary number in the specified direction by multiple positions. Each ejected bit is inserted from the opposite side.
Namespace types: array
Parameters:
value (array)
direction (int) : The direction of the shift operation.
count (int) : The number of positions to be shifted by.
Returns: The shifted binary number.
method arithmeticShift(value, direction, count)
Performs arithmetic shift on a binary number in the specified direction by multiple positions. Every new bit is 0 if the shift is leftward, otherwise, it equals the sign bit.
Namespace types: array
Parameters:
value (array)
direction (int) : The direction of the shift operation.
count (int) : The number of positions to be shifted by.
Returns: The shifted binary number.
method add(a, b, carry)
Performs arithmetic addition on two binary numbers.
Namespace types: array
Parameters:
a (array) : First binary number.
b (array) : Second binary number.
carry (int) : The input carry of the operation.
Returns: The result of the arithmetic addition of the inputs.
method sub(a, b, carry)
Performs arithmetic subtraction on two binary numbers.
Namespace types: array
Parameters:
a (array) : First binary number.
b (array) : Second binary number. The number to be subtracted.
carry (int) : The input carry of the operation.
Returns: The result of the arithmetic subtraction of the input b from the input a.
TradingUtilsLibrary "TradingUtils"
Utility library for common trading functions
calcVariation(price, threshold)
Calculates variation of a price based on a threshold
Parameters:
price (float) : (float) The price to be varied
threshold (float) : (float) The threshold for the variation
Returns: (float) The varied price
sendAlert(action, symbol, orderType, quantity, message)
Sends an alert message in JSON format
Parameters:
action (string) : (string) The action to be taken (e.g., "BUY", "SELL")
symbol (string) : (string) The trading symbol (e.g., "BTCUSDT")
orderType (string) : (string) The order type (e.g., "MARKET")
quantity (float) : (float) The quantity of the order
message (string) : (string) The message to be included in the alert
updateLine(condition, index, price, lineColor)
Updates or creates a line on the chart
Parameters:
condition (bool) : (bool) Condition to check if the line should be updated or created
index (int) : (int) The current bar index
price (float) : (float) The price value for the line
lineColor (color) : (color) The color of the line
Returns: (line) The updated or newly created line
MathTransformLibrary "MathTransform"
Auxiliary functions for transforming data using mathematical and statistical methods
scaler_zscore(x, lookback_window)
Calculates Z-Score normalization of a series.
Parameters:
x (float) : : floating point series to normalize
lookback_window (int) : : lookback period for calculating mean and standard deviation
Returns: Z-Score normalized series
scaler_min_max(x, lookback_window, min_val, max_val, empiric_min, empiric_max, empiric_mid)
Performs Min-Max scaling of a series within a given window, user-defined bounds, and optional midpoint
Parameters:
x (float) : : floating point series to transform
lookback_window (int) : : int : optional lookback window size to consider for scaling.
min_val (float) : : float : minimum value of the scaled range. Default is 0.0.
max_val (float) : : float : maximum value of the scaled range. Default is 1.0.
empiric_min (float) : : float : user-defined minimum value of the input data. This means that the output could exceed the `min_val` bound if there is data in `x` lesser than `empiric_min`. If na, it's calculated from `x` and `lookback_window`.
empiric_max (float) : : float : user-defined maximum value of the input data. This means that the output could exceed the `max_val` bound if there is data in `x` greater than `empiric_max`. If na, it's calculated from `x` and `lookback_window`.
empiric_mid (float) : : float : user-defined midpoint value of the input data. If na, it's calculated from `empiric_min` and `empiric_max`.
Returns: rescaled series
log(x, base)
Applies logarithmic transformation to a value, base can be user-defined.
Parameters:
x (float) : : floating point value to transform
base (float) : : logarithmic base, must be greater than 0
Returns: logarithm of the value to the given base, if x <= 0, returns logarithm of 1 to the given base
exp(x, base)
Applies exponential transformation to a value, base can be user-defined.
Parameters:
x (float) : : floating point value to transform
base (float) : : base of the exponentiation, must be greater than 0
Returns: the result of raising the base to the power of the value
power(x, exponent)
Applies power transformation to a value, exponent can be user-defined.
Parameters:
x (float) : : floating point value to transform
exponent (float) : : exponent for the transformation
Returns: the value raised to the given exponent, preserving the sign of the original value
tanh(x, scale)
The hyperbolic tangent is the ratio of the hyperbolic sine and hyperbolic cosine. It limits an output to a range of −1 to 1.
Parameters:
x (float) : : floating point series
scale (float)
sigmoid(x, scale, offset)
Applies the sigmoid function to a series.
Parameters:
x (float) : : floating point series to transform
scale (float) : : scaling factor for the sigmoid function
offset (float) : : offset for the sigmoid function
Returns: transformed series using the sigmoid function
sigmoid_double(x, scale, offset)
Applies a double sigmoid function to a series, handling positive and negative values differently.
Parameters:
x (float) : : floating point series to transform
scale (float) : : scaling factor for the sigmoid function
offset (float) : : offset for the sigmoid function
Returns: transformed series using the double sigmoid function
logistic_decay(a, b, c, t)
Calculates logistic decay based on given parameters.
Parameters:
a (float) : : parameter affecting the steepness of the curve
b (float) : : parameter affecting the direction of the decay
c (float) : : the upper bound of the function's output
t (float) : : time variable
Returns: value of the logistic decay function at time t
Cinnamon_Bear Indicators MA LibraryLibrary "Cinnamon_BearIndicatorsMALibrary"
This is a personal Library of the NON built-in PineScript Moving Average function used to code indicators
ma_dema(source, length)
Double Exponential Moving Average (DEMA)
Parameters:
source (simple float)
length (simple int)
Returns: A double level of smoothing helps to follow price movements more closely while still reducing noise compared to a single EMA.
ma_dsma(source, length)
Double Smoothed Moving Average (DSMA)
Parameters:
source (simple float)
length (simple int)
Returns: A double level of smoothing helps to follow price movements more closely while still reducing noise compared to a single SMA.
ma_tema(source, length)
Triple Exponential Moving Average (TEMA)
Parameters:
source (simple float)
length (simple int)
Returns: A Triple level of smoothing helps to follow price movements even more closely compared to a DEMA.
ma_vwema(source, length)
Volume-Weighted Exponential Moving Average (VWEMA)
Parameters:
source (simple float)
length (simple int)
Returns: The VWEMA weights based on volume and recent price, giving more weight to periods with higher trading volumes.
ma_hma(source, length)
Hull Moving Average (HMA)
Parameters:
source (simple float)
length (simple int)
Returns: The HMA formula combines the properties of the weighted moving average (WMA) and the exponential moving average (EMA) to achieve a smoother and more responsive curve.
ma_ehma(source, length)
Enhanced Moving Average (EHMA)
Parameters:
source (simple float)
length (simple int)
Returns: The EHMA is calculated similarly to the Hull Moving Average (HMA) but uses a different weighting factor to further improve responsiveness.
ma_trix(source, length)
Triple Exponential Moving Average (TRIX)
Parameters:
source (simple float)
length (simple int)
Returns: The TRIX is an oscillator that shows the percentage change of a triple EMA. It is designed to filter out minor price movements and display only the most significant trends. The TRIX is a momentum indicator that can help identify trends and buy or sell signals.
ma_lsma(source, length)
Linear Weighted Moving Average (LSMA)
Parameters:
source (simple float)
length (simple int)
Returns: A moving average that gives more weight to recent prices. It is calculated using a formula that assigns linear weights to prices, with the highest weight given to the most recent price and the lowest weight given to the furthest price in the series.
ma_wcma(source, length)
Weighted Cumulative Moving Average (WCMA)
Parameters:
source (simple float)
length (simple int)
Returns: A moving average that gives more weight to recent prices. Compared to a LSMA, the WCMA the weights of data increase linearly with time, so the most recent data has a greater weight compared to older data. This means that the contribution of the most recent data to the moving average is more significant.
ma_vidya(source, length)
Variable Index Dynamic Average (VIDYA)
Parameters:
source (simple float)
length (simple int)
Returns: It is an adaptive moving average that adjusts its momentum based on market volatility using the formula of Chande Momentum Oscillator (CMO) .
ma_zlma(source, length)
Zero-Lag Moving Average (ZLMA)
Parameters:
source (simple float)
length (simple int)
Returns: Its aims to minimize the lag typically associated with MA, designed to react more quickly to price changes.
ma_gma(source, length, power)
Generalized Moving Average (GMA)
Parameters:
source (simple float)
length (simple int)
power (simple int)
Returns: It is a moving average that uses a power parameter to adjust the weight of historical data. This allows the GMA to adapt to various styles of MA.
ma_tma(source, length)
Triangular Moving Average (TMA)
Parameters:
source (simple float)
length (simple int)
Returns: MA more sensitive to changes in recent data compared to the SMA, providing a moving average that better adapts to short-term price changes.
FunctionTimeFrequencyLibrary "FunctionTimeFrequency"
Functions to encode time in a normalized space (-0.5, 0.5) that corresponds to the position of the
current time in the referrence frequency of time.
The purpose of normalizing the time value in this manner is to provide a consistent and easily comparable
representation of normalized time that can be used for various calculations or comparisons without needing
to consider the specific scale of time. This function can be particularly useful when working with high-precision
timing data, as it allows you to compare and manipulate time values more flexibly than using absolute second
counts alone.
Reference:
github.com
second_of_minute(t)
Second of minute encoded as value between (-0.5, 0.5).
Parameters:
t (int) : Time value.
Returns: normalized time.
minute_of_hour(t)
Minute of hour encoded as value between (-0.5, 0.5).
Parameters:
t (int) : Time value.
Returns: normalized time.
hour_of_day(t)
Hour of day encoded as value between (-0.5, 0.5).
Parameters:
t (int) : Time value.
Returns: normalized time.
day_of_week(t)
Day of week encoded as value between (-0.5, 0.5).
Parameters:
t (int) : Time value.
Returns: normalized time.
day_of_month(t)
Day of month encoded as value between (-0.5, 0.5).
Parameters:
t (int) : Time value.
Returns: normalized time.
day_of_year(t)
Day of year encoded as value between (-0.5, 0.5).
Parameters:
t (int) : Time value.
Returns: normalized time.
month_of_year(t)
Month of year encoded as value between (-0.5, 0.5).
Parameters:
t (int) : Time value.
Returns: normalized time.
week_of_year(t)
Week of year encoded as value between (-0.5, 0.5).
Parameters:
t (int) : Time value.
Returns: normalized time.
TRIGLibrary "TRIG"
degreesToRadians(degrees)
Parameters:
degrees (float)
radiansToDegrees(radians)
Parameters:
radians (float)
rt_get_angleAlphaFromLine(x1, y1, x2, y2, inDegrees)
Parameters:
x1 (int)
y1 (float)
x2 (int)
y2 (float)
inDegrees (bool)
rt_get_angleBetaFromLine(x1, y1, x2, y2)
Parameters:
x1 (int)
y1 (float)
x2 (int)
y2 (float)
ALGEBRALibrary "ALGEBRA"
line_fromXy(x1, y1, x2, y2)
Parameters:
x1 (int)
y1 (float)
x2 (int)
y2 (float)
line_getPrice(x, slope, yInt)
Parameters:
x (int)
slope (float)
yInt (float)
line_length(x1, y1, x2, y2)
Parameters:
x1 (int)
y1 (float)
x2 (int)
y2 (float)
distance(x1, y1, x2, y2)
Parameters:
x1 (int)
y1 (float)
x2 (int)
y2 (float)
statsLibrary "stats"
stats
factorial(x)
factorial
Parameters:
x (int)
standardize(x, length, lengthSmooth)
standardize
@description Moving Standardization of a time series.
Parameters:
x (float)
length (int)
lengthSmooth (int)
dnorm(x, mean, sd)
dnorm
@description Approximation for Normal Density Function.
Parameters:
x (float)
mean (float)
sd (float)
pnorm(x, mean, sd, log)
pnorm
@description Approximation for Normal Cumulative Distribution Function.
Parameters:
x (float)
mean (float)
sd (float)
log (bool)
ewma(x, length, tau_hl)
ewma
@description Exponentially Weighted Moving Average.
Parameters:
x (float)
length (int)
tau_hl (float)
ewm_sd(x, length, tau_hl)
Exponentially Weighted Moving Standard Deviation.
Parameters:
x (float)
length (int)
tau_hl (float)
ewm_scoring(x, length, tau_hl)
ewm_scoring
@description Exponentially Weighted Moving Standardization:
Parameters:
x (float)
length (int)
tau_hl (float)
MathOperatorLibrary "MathOperator"
Methods to handle operators.
method add(value_a, value_b)
Add value a to b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: float.
method subtract(value_a, value_b)
subtract value b from a.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: float.
method multiply(value_a, value_b)
multiply value a with b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: float.
method divide(value_a, value_b)
divide value a with b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: float.
method remainder(value_a, value_b)
remainder of a with b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: float.
method equal(value_a, value_b)
equality of value a with b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method not_equal(value_a, value_b)
inequality of value a with b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method over(value_a, value_b)
value a is over b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method under(value_a, value_b)
value a is under b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method over_equal(value_a, value_b)
value a is over equal b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method under_equal(value_a, value_b)
value a is under equal b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method and_(value_a, value_b)
logical and of a with b
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
method or_(value_a, value_b)
logical or of a with b.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
method not_(value_a)
logical not of a.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
Returns: bool.
method xor_(value_a, value_b)
logical xor of a with b.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
method xnor_(value_a, value_b)
logical xnor of a with b.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
method nand_(value_a, value_b)
logical nand of a with b.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
method nor_(value_a, value_b)
logical nor of a with b.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
strategy_helpersThis library is designed to aid traders and developers in calculating risk metrics efficiently across different asset types like equities, futures, and forex. It includes comprehensive functions that calculate the number of units or contracts to trade, the value at risk, and the total value of the position based on provided entry prices, stop levels, and risk percentages. Whether you're managing a portfolio or developing trading strategies, this library provides essential tools for risk management. Functions also automatically select the appropriate risk calculation method based on asset type, calculate leverage levels, and determine potential liquidation points for leveraged positions. Perfect for enhancing the precision and effectiveness of your trading strategies.
Library "strategy_helpers"
Provides tools for calculating risk metrics across different types of trading strategies including equities, futures, and forex. Functions allow for precise control over risk management by calculating the number of units or contracts to trade, the value at risk, and the total position value based on entry prices, stop levels, and desired risk percentage. Additional utilities include automatic risk calculation based on asset type, leverage level calculations, and determination of liquidation levels for leveraged trades.
calculate_risk(entry, stop_level, stop_range, capital, risk_percent, trade_direction, whole_number_buy)
Calculates risk metrics for equity trades based on entry, stop level, and risk percent
Parameters:
entry (float) : The price at which the position is entered. Use close if you arent adding to a position. Use the original entry price if you are adding to a position.
stop_level (float) : The price level where the stop loss is placed
stop_range (float) : The price range from entry to stop level
capital (float) : The total capital available for trading
risk_percent (float) : The percentage of capital risked on the trade. 100% is represented by 100.
trade_direction (bool) : True for long trades, false for short trades
whole_number_buy (bool) : True to adjust the quantity to whole numbers
Returns: A tuple containing the number of units to trade, the value at risk, and the total value of the position:
calculate_risk_futures(risk_capital, stop_range)
Calculates risk metrics for futures trades based on the risk capital and stop range
Parameters:
risk_capital (float) : The capital allocated for the trade
stop_range (float) : The price range from entry to stop level
Returns: A tuple containing the number of contracts to trade, the value at risk, and the total value of the position:
calculate_risk_forex(entry, stop_level, stop_range, capital, risk_percent, trade_direction)
Calculates risk metrics for forex trades based on entry, stop level, and risk percent
Parameters:
entry (float) : The price at which the position is entered. Use close if you arent adding to a position. Use the original entry price if you are adding to a position.
stop_level (float) : The price level where the stop loss is placed
stop_range (float) : The price range from entry to stop level
capital (float) : The total capital available for trading
risk_percent (float) : The percentage of capital risked on the trade. 100% is represented by 100.
trade_direction (bool) : True for long trades, false for short trades
Returns: A tuple containing the number of lots to trade, the value at risk, and the total value of the position:
calculate_risk_auto(entry, stop_level, stop_range, capital, risk_percent, trade_direction, whole_number_buy)
Automatically selects the risk calculation method based on the asset type and calculates risk metrics
Parameters:
entry (float) : The price at which the position is entered. Use close if you arent adding to a position. Use the original entry price if you are adding to a position.
stop_level (float) : The price level where the stop loss is placed
stop_range (float) : The price range from entry to stop level
capital (float) : The total capital available for trading
risk_percent (float) : The percentage of capital risked on the trade. 100% is represented by 100.
trade_direction (bool) : True for long trades, false for short trades
whole_number_buy (bool) : True to adjust the quantity to whole numbers, applicable only for non-futures and non-forex trades
Returns: A tuple containing the number of units or contracts to trade, the value at risk, and the total value of the position:
leverage_level(account_equity, position_value)
Calculates the leverage level used based on account equity and position value
Parameters:
account_equity (float) : Total equity in the trading account
position_value (float) : Total value of the position taken
Returns: The leverage level used in the trade
calculate_liquidation_level(entry, leverage, trade_direction, maintenance_margine)
Calculates the liquidation price level for a leveraged trade
Parameters:
entry (float) : The price at which the position is entered
leverage (float) : The leverage level used in the trade
trade_direction (bool) : True for long trades, false for short trades
maintenance_margine (float) : The maintenance margin requirement, expressed as a percentage
Returns: The price level at which the position would be liquidated, or na if leverage is zero
mathLibrary "math"
It's a library of discrete aproximations of a price or Series float it uses Fourier Discrete transform, Laplace Discrete Original and Modified transform and Euler's Theoreum for Homogenus White noice operations. Calling functions without source value it automatically take close as the default source value.
Here is a picture of Laplace and Fourier approximated close prices from this library:
Copy this indicator and try it yourself:
import AutomatedTradingAlgorithms/math/1 as math
//@version=5
indicator("Close Price with Aproximations", shorttitle="Close and Aproximations", overlay=false)
// Sample input data (replace this with your own data)
inputData = close
// Plot Close Price
plot(inputData, color=color.blue, title="Close Price")
ltf32_result = math.LTF32(a=0.01)
plot(ltf32_result, color=color.green, title="LTF32 Aproximation")
fft_result = math.FFT()
plot(fft_result, color=color.red, title="Fourier Aproximation")
wavelet_result = math.Wavelet()
plot(wavelet_result, color=color.orange, title="Wavelet Aproximation")
wavelet_std_result = math.Wavelet_std()
plot(wavelet_std_result, color=color.yellow, title="Wavelet_std Aproximation")
DFT3(xval, _dir)
Discrete Fourier Transform with last 3 points
Parameters:
xval (float) : Source series
_dir (int) : Direction parameter
Returns: Aproxiated source value
DFT2(xval, _dir)
Discrete Fourier Transform with last 2 points
Parameters:
xval (float) : Source series
_dir (int) : Direction parameter
Returns: Aproxiated source value
FFT(xval)
Fast Fourier Transform once. It aproximates usig last 3 points.
Parameters:
xval (float) : Source series
Returns: Aproxiated source value
DFT32(xval)
Combined Discrete Fourier Transforms of DFT3 and DTF2 it aproximates last point by first
aproximating last 3 ponts and than using last 2 points of the previus.
Parameters:
xval (float) : Source series
Returns: Aproxiated source value
DTF32(xval)
Combined Discrete Fourier Transforms of DFT3 and DTF2 it aproximates last point by first
aproximating last 3 ponts and than using last 2 points of the previus.
Parameters:
xval (float) : Source series
Returns: Aproxiated source value
LFT3(xval, _dir, a)
Discrete Laplace Transform with last 3 points
Parameters:
xval (float) : Source series
_dir (int) : Direction parameter
a (float) : laplace coeficient
Returns: Aproxiated source value
LFT2(xval, _dir, a)
Discrete Laplace Transform with last 2 points
Parameters:
xval (float) : Source series
_dir (int) : Direction parameter
a (float) : laplace coeficient
Returns: Aproxiated source value
LFT(xval, a)
Fast Laplace Transform once. It aproximates usig last 3 points.
Parameters:
xval (float) : Source series
a (float) : laplace coeficient
Returns: Aproxiated source value
LFT32(xval, a)
Combined Discrete Laplace Transforms of LFT3 and LTF2 it aproximates last point by first
aproximating last 3 ponts and than using last 2 points of the previus.
Parameters:
xval (float) : Source series
a (float) : laplace coeficient
Returns: Aproxiated source value
LTF32(xval, a)
Combined Discrete Laplace Transforms of LFT3 and LTF2 it aproximates last point by first
aproximating last 3 ponts and than using last 2 points of the previus.
Parameters:
xval (float) : Source series
a (float) : laplace coeficient
Returns: Aproxiated source value
whitenoise(indic_, _devided, minEmaLength, maxEmaLength, src)
Ehler's Universal Oscillator with White Noise, without extra aproximated src.
It uses dinamic EMA to aproximate indicator and thus reducing noise.
Parameters:
indic_ (float) : Input series for the indicator values to be smoothed
_devided (int) : Divisor for oscillator calculations
minEmaLength (int) : Minimum EMA length
maxEmaLength (int) : Maximum EMA length
src (float) : Source series
Returns: Smoothed indicator value
whitenoise(indic_, dft1, _devided, minEmaLength, maxEmaLength, src)
Ehler's Universal Oscillator with White Noise and DFT1.
It uses src and sproxiated src (dft1) to clearly define white noice.
It uses dinamic EMA to aproximate indicator and thus reducing noise.
Parameters:
indic_ (float) : Input series for the indicator values to be smoothed
dft1 (float) : Aproximated src value for white noice calculation
_devided (int) : Divisor for oscillator calculations
minEmaLength (int) : Minimum EMA length
maxEmaLength (int) : Maximum EMA length
src (float) : Source series
Returns: Smoothed indicator value
smooth(dft1, indic__, _devided, minEmaLength, maxEmaLength, src)
Smoothing source value with help of indicator series and aproximated source value
It uses src and sproxiated src (dft1) to clearly define white noice.
It uses dinamic EMA to aproximate src and thus reducing noise.
Parameters:
dft1 (float) : Value to be smoothed.
indic__ (float) : Optional input for indicator to help smooth dft1 (default is FFT)
_devided (int) : Divisor for smoothing calculations
minEmaLength (int) : Minimum EMA length
maxEmaLength (int) : Maximum EMA length
src (float) : Source series
Returns: Smoothed source (src) series
smooth(indic__, _devided, minEmaLength, maxEmaLength, src)
Smoothing source value with help of indicator series
It uses dinamic EMA to aproximate src and thus reducing noise.
Parameters:
indic__ (float) : Optional input for indicator to help smooth dft1 (default is FFT)
_devided (int) : Divisor for smoothing calculations
minEmaLength (int) : Minimum EMA length
maxEmaLength (int) : Maximum EMA length
src (float) : Source series
Returns: Smoothed src series
vzo_ema(src, len)
Volume Zone Oscillator with EMA smoothing
Parameters:
src (float) : Source series
len (simple int) : Length parameter for EMA
Returns: VZO value
vzo_sma(src, len)
Volume Zone Oscillator with SMA smoothing
Parameters:
src (float) : Source series
len (int) : Length parameter for SMA
Returns: VZO value
vzo_wma(src, len)
Volume Zone Oscillator with WMA smoothing
Parameters:
src (float) : Source series
len (int) : Length parameter for WMA
Returns: VZO value
alma2(series, windowsize, offset, sigma)
Arnaud Legoux Moving Average 2 accepts sigma as series float
Parameters:
series (float) : Input series
windowsize (int) : Size of the moving average window
offset (float) : Offset parameter
sigma (float) : Sigma parameter
Returns: ALMA value
Wavelet(src, len, offset, sigma)
Aproxiates srt using Discrete wavelet transform.
Parameters:
src (float) : Source series
len (int) : Length parameter for ALMA
offset (simple float)
sigma (simple float)
Returns: Wavelet-transformed series
Wavelet_std(src, len, offset, mag)
Aproxiates srt using Discrete wavelet transform with standard deviation as a magnitude.
Parameters:
src (float) : Source series
len (int) : Length parameter for ALMA
offset (float) : Offset parameter for ALMA
mag (int) : Magnitude parameter for standard deviation
Returns: Wavelet-transformed series
LaplaceTransform(xval, N, a)
Original Laplace Transform over N set of close prices
Parameters:
xval (float) : series to aproximate
N (int) : number of close prices in calculations
a (float) : laplace coeficient
Returns: Aproxiated source value
NLaplaceTransform(xval, N, a, repeat)
Y repetirions on Original Laplace Transform over N set of close prices, each time N-k set of close prices
Parameters:
xval (float) : series to aproximate
N (int) : number of close prices in calculations
a (float) : laplace coeficient
repeat (int) : number of repetitions
Returns: Aproxiated source value
LaplaceTransformsum(xval, N, a, b)
Sum of 2 exponent coeficient of Laplace Transform over N set of close prices
Parameters:
xval (float) : series to aproximate
N (int) : number of close prices in calculations
a (float) : laplace coeficient
b (float) : second laplace coeficient
Returns: Aproxiated source value
NLaplaceTransformdiff(xval, N, a, b, repeat)
Difference of 2 exponent coeficient of Laplace Transform over N set of close prices
Parameters:
xval (float) : series to aproximate
N (int) : number of close prices in calculations
a (float) : laplace coeficient
b (float) : second laplace coeficient
repeat (int) : number of repetitions
Returns: Aproxiated source value
N_divLaplaceTransformdiff(xval, N, a, b, repeat)
N repetitions of Difference of 2 exponent coeficient of Laplace Transform over N set of close prices, with dynamic rotation
Parameters:
xval (float) : series to aproximate
N (int) : number of close prices in calculations
a (float) : laplace coeficient
b (float) : second laplace coeficient
repeat (int) : number of repetitions
Returns: Aproxiated source value
LaplaceTransformdiff(xval, N, a, b)
Difference of 2 exponent coeficient of Laplace Transform over N set of close prices
Parameters:
xval (float) : series to aproximate
N (int) : number of close prices in calculations
a (float) : laplace coeficient
b (float) : second laplace coeficient
Returns: Aproxiated source value
NLaplaceTransformdiffFrom2(xval, N, a, b, repeat)
N repetitions of Difference of 2 exponent coeficient of Laplace Transform over N set of close prices, second element has for 1 higher exponent factor
Parameters:
xval (float) : series to aproximate
N (int) : number of close prices in calculations
a (float) : laplace coeficient
b (float) : second laplace coeficient
repeat (int) : number of repetitions
Returns: Aproxiated source value
N_divLaplaceTransformdiffFrom2(xval, N, a, b, repeat)
N repetitions of Difference of 2 exponent coeficient of Laplace Transform over N set of close prices, second element has for 1 higher exponent factor, dynamic rotation
Parameters:
xval (float) : series to aproximate
N (int) : number of close prices in calculations
a (float) : laplace coeficient
b (float) : second laplace coeficient
repeat (int) : number of repetitions
Returns: Aproxiated source value
LaplaceTransformdiffFrom2(xval, N, a, b)
Difference of 2 exponent coeficient of Laplace Transform over N set of close prices, second element has for 1 higher exponent factor
Parameters:
xval (float) : series to aproximate
N (int) : number of close prices in calculations
a (float) : laplace coeficient
b (float) : second laplace coeficient
Returns: Aproxiated source value
AminioLibraryLibrary "AminioLibrary"
: this is my personal library that is being used in different indicators and strategies
calculateMA(source, len, maType)
This fuction returns a moving average value based on the type
Parameters:
source (float) : Is the time series source to calculate average from
len (simple int) : The length of the moving average, this should be integer
maType (string) : The type of moving average, acceptable types are : SMA, HMA, EMA, RMA, WMA, VWMA
Returns: value of moving average
atr(source, len)
This fuction returns atr value for a given source
Parameters:
source (float) : Is the time series source to calculate atr from
len (simple int) : The length of the atr, this should be integer
Returns: value of atr from source
superTrend(source, factor, len)
This fuction returns value of super trend indicator and the trend direction as a tupple
Parameters:
source (float) : Is the time series source to calculate super trend from
factor (simple float) : The multiplication factor for upper and lower band calcualtion, this can be a float
len (simple int) : The length of the super trend, this should be integer
Returns: value of atr from source
halfTrend(am, chdev)
This fuction returns a hTrend type carrying different values for half trend indicator
Parameters:
am (int) : This is the amplitude used for calcucating the half trend, use integers
chdev (float) : This is the Channel Deviation value used for calculating upper and lower atr channel boundaries, you can use floats
Returns: hTrend data type
hTrend
Fields:
halfTrend (series__float)
trend (series__integer)
atrHigh (series__float)
atrLow (series__float)
arrowUp (series__float)
arrowDown (series__float)