GeneratorBetaLib:Generator
This library generate levels that could be used inside SNG scripts and strategies. Also uses beta version of SNG Types library
Indicators and strategies
IndicatorsLibrary "Indicators"
this has a calculation for the most used indicators.
macd4C(fastMa, slowMa)
this calculates macd 4c
Parameters:
fastMa (simple int) : is the period for the fast ma. the minimum value is 7
slowMa (simple int) : is the period for the slow ma. the minimum value is 7
Returns: the macd 4c value for the current bar
rsi(rsiSourceInput, rsiLengthInput)
this calculates rsi
Parameters:
rsiSourceInput (float) : is the source for the rsi
rsiLengthInput (simple int) : is the period for the rsi
Returns: the rsi value for the current bar
ao(source, fastPeriod, slowPeriod)
this calculates ao
Parameters:
source (float) : is the source for the ao
fastPeriod (int) : is the period for the fast ma
slowPeriod (int) : is the period for the slow ma
Returns: the ao value for the current bar
kernelAoOscillator(kernelFastLookback, kernelSlowLookback, kernelFastWeight, kernelSlowWeight, kernelFastRegressionStart, kernelSlowRegressionStart, kernelFastSmoothPeriod, kernelSlowSmoothPeriod, kernelFastSmooth, kernelSlowSmooth, source)
this calculates our own kernel ao oscillator which we made
Parameters:
kernelFastLookback (simple int)
kernelSlowLookback (simple int)
kernelFastWeight (simple float)
kernelSlowWeight (simple float)
kernelFastRegressionStart (simple int)
kernelSlowRegressionStart (simple int)
kernelFastSmoothPeriod (int)
kernelSlowSmoothPeriod (int)
kernelFastSmooth (bool)
kernelSlowSmooth (bool)
source (float) : is the source for the ao
Returns: the kernel ao oscillator value for the current bar, the colors for both the fast and slow kernel, the fast & slow kernel
signalLineKernel(lag, h, r, x_0, smoothColors, _src, c_bullish, c_bearish)
Parameters:
lag (int)
h (float)
r (float)
x_0 (int)
smoothColors (bool)
_src (float)
c_bullish (color)
c_bearish (color)
zigzagCalc(Depth, Deviation, Backstep, repaint, Show_zz, line_thick, text_color)
Parameters:
Depth (int)
Deviation (int)
Backstep (int)
repaint (bool)
Show_zz (bool)
line_thick (int)
text_color (color)
RelativeValue█ OVERVIEW
This library is a Pine Script™ programmer's tool offering the ability to compute relative values, which represent comparisons of current data points, such as volume, price, or custom indicators, with their analogous historical data points from corresponding time offsets. This approach can provide insightful perspectives into the intricate dynamics of relative market behavior over time.
█ CONCEPTS
Relative values
In this library, a relative value is a metric that compares a current data point in a time interval to an average of data points with corresponding time offsets across historical periods. Its purpose is to assess the significance of a value by considering the historical context within past time intervals.
For instance, suppose we wanted to calculate relative volume on an hourly chart over five daily periods, and the last chart bar is two hours into the current trading day. In this case, we would compare the current volume to the average of volume in the second hour of trading across five days. We obtain the relative volume value by dividing the current volume by this average.
This form of analysis rests on the hypothesis that substantial discrepancies or aberrations in present market activity relative to historical time intervals might help indicate upcoming changes in market trends.
Cumulative and non-cumulative values
In the context of this library, a cumulative value refers to the cumulative sum of a series since the last occurrence of a specific condition (referred to as `anchor` in the function definitions). Given that relative values depend on time, we use time-based conditions such as the onset of a new hour, day, etc. On the other hand, a non-cumulative value is simply the series value at a specific time without accumulation.
Calculating relative values
Four main functions coordinate together to compute the relative values: `maintainArray()`, `calcAverageByTime()`, `calcCumulativeSeries()`, and `averageAtTime()`. These functions are underpinned by a `collectedData` user-defined type (UDT), which stores data collected since the last reset of the timeframe along with their corresponding timestamps. The relative values are calculated using the following procedure:
1. The `averageAtTime()` function invokes the process leveraging all four of the methods and acts as the main driver of the calculations. For each bar, this function adds the current bar's source and corresponding time value to a `collectedData` object.
2. Within the `averageAtTime()` function, the `maintainArray()` function is called at the start of each anchor period. It adds a new `collectedData` object to the array and ensures the array size does not exceed the predefined `maxSize` by removing the oldest element when necessary. This method plays an essential role in limiting memory usage and ensuring only relevant data over the desired number of periods is in the calculation window.
3. Next, the `calcAverageByTime()` function calculates the average value of elements within the `data` field for each `collectedData` object that corresponds to the same time offset from each anchor condition. This method accounts for cases where the current index of a `collectedData` object exceeds the last index of any past objects by using the last available values instead.
4. For cumulative calculations, the `averageAtTime()` function utilizes the `isCumulative` boolean parameter. If true, the `calcCumulativeSeries()` function will track the running total of the source data from the last bar where the anchor condition was met, providing a cumulative sum of the source values from one anchor point to the next.
To summarize, the `averageAtTime()` function continually stores values with their corresponding times in a `collectedData` object for each bar in the anchor period. When the anchor resets, this object is added to a larger array. The array's size is limited by the specified number of periods to be averaged. To correlate data across these periods, time indexing is employed, enabling the function to compare corresponding points across multiple periods.
█ USING THIS LIBRARY
The library simplifies the complex process of calculating relative values through its intuitive functions. Follow the steps below to use this library in your scripts.
Step 1: Import the library and declare inputs
Import the library and declare variables based on the user's input. These can include the timeframe for each period, the number of time intervals to include in the average, and whether the calculation uses cumulative values. For example:
//@version=5
import TradingView/RelativeValue/1 as TVrv
indicator("Relative Range Demo")
string resetTimeInput = input.timeframe("D")
int lengthInput = input.int(5, "No. of periods")
Step 2: Define the anchor condition
With these inputs declared, create a condition to define the start of a new period (anchor). For this, we use the change in the time value from the input timeframe:
bool anchor = timeframe.change(resetTimeInput)
Step 3: Calculate the average
At this point, one can calculate the average of a value's history at the time offset from the anchor over a number of periods using the `averageAtTime()` function. In this example, we use True Range (TR) as the `source` and set `isCumulative` to false:
float pastRange = TVrv.averageAtTime(ta.tr, lengthInput, anchor, false)
Step 4: Display the data
You can visualize the results by plotting the returned series. These lines display the non-cumulative TR alongside the average value over `lengthInput` periods for relative comparison:
plot(pastRange, "Past True Range Avg", color.new(chart.bg_color, 70), 1, plot.style_columns)
plot(ta.tr, "True Range", close >= open ? color.new(color.teal, 50) : color.new(color.red, 50), 1, plot.style_columns)
This example will display two overlapping series of columns. The green and red columns depict the current TR on each bar, and the light gray columns show the average over a defined number of periods, e.g., the default inputs on an hourly chart will show the average value at the hour over the past five days. This comparative analysis aids in determining whether the range of a bar aligns with its typical historical values or if it's an outlier.
█ NOTES
• The foundational concept of this library was derived from our initial Relative Volume at Time script. This library's logic significantly boosts its performance. Keep an eye out for a forthcoming updated version of the indicator. The demonstration code included in the library emulates a streamlined version of the indicator utilizing the library functions.
• Key efficiencies in the data management are realized through array.binary_search_leftmost() , which offers a performance improvement in comparison to its loop-dependent counterpart.
• This library's architecture utilizes user-defined types (UDTs) to create custom objects which are the equivalent of variables containing multiple parts, each able to hold independent values of different types . The recently added feature was announced in this blog post.
• To enhance readability, the code substitutes array functions with equivalent methods .
Look first. Then leap.
█ FUNCTIONS
This library contains the following functions:
calcCumulativeSeries(source, anchor)
Calculates the cumulative sum of `source` since the last bar where `anchor` was `true`.
Parameters:
source (series float) : Source used for the calculation.
anchor (series bool) : The condition that triggers the reset of the calculation. The calculation is reset when `anchor` evaluates to `true`, and continues using the values accumulated since the previous reset when `anchor` is `false`.
Returns: (float) The cumulative sum of `source`.
averageAtTime(source, length, anchor, isCumulative)
Calculates the average of all `source` values that share the same time difference from the `anchor` as the current bar for the most recent `length` bars.
Parameters:
source (series float) : Source used for the calculation.
length (simple int) : The number of reset periods to consider for the average calculation of historical data.
anchor (series bool) : The condition that triggers the reset of the average calculation. The calculation is reset when `anchor` evaluates to `true`, and continues using the values accumulated since the previous reset when `anchor` is `false`.
isCumulative (simple bool) : If `true`, `source` values are accumulated until the next time `anchor` is `true`. Optional. The default is `true`.
Returns: (float) The average of the source series at the specified time difference.
AoDivergenceLibrary_Library "AoDivergenceLibrary_"
this has functions which calculate and plot divergences which are used for ao divergences. essentially, this finds divergences by using the ao divergence logic. this logic has been used in "AO Hid & Reg Div with LC & Kernel".
regBullDivergence(swingLow, osc, colour)
Parameters:
swingLow (bool)
osc (float)
colour (color)
regBearDivergence(swingHigh, osc, colour)
Parameters:
swingHigh (bool)
osc (float)
colour (color)
hidBullDivergence(swingHigh, osc, colour)
Parameters:
swingHigh (bool)
osc (float)
colour (color)
hidBearDivergence(swingHigh, osc, colour)
Parameters:
swingHigh (bool)
osc (float)
colour (color)
.print()
You don't need to initialize anything..
After you import the library you can use .print() as easy as that..!
Hope this helps
* use a unique ID for each .print() call
let me know if you run into any bugs
by trying to make it as user friendly as possible i had to do
some not ideal things so there's a chance it could present some bugs with
a lot of labels present on the chart
and if you use label.all to parse and manipulate the labels on the chart..
most likely it will cause an issue but not a lot of people use this so
I don't think that will be a problem.
thanks,
FFriZz | frizlabz
Library "print"
Single function to print any type to console
method str(inp)
`method` convert all types to string
```
(overload)
*.str(any inp) => string
```
Namespace types: series string, simple string, input string, const string
Parameters:
inp (string) : `any` - desc | Required
Returns: `string` formatted string
method str(inp)
Namespace types: series int, simple int, input int, const int
Parameters:
inp (int)
method str(inp)
Namespace types: series float, simple float, input float, const float
Parameters:
inp (float)
method str(inp)
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
inp (bool)
method str(inp)
Namespace types: series linefill
Parameters:
inp (linefill)
method str(inp)
Namespace types: series line
Parameters:
inp (line)
method str(inp)
Namespace types: series box
Parameters:
inp (box)
method str(inp)
Namespace types: series label
Parameters:
inp (label)
method str(inp)
Namespace types: matrix
Parameters:
inp (matrix)
method str(inp)
Namespace types: matrix
Parameters:
inp (matrix)
method str(inp)
Namespace types: matrix
Parameters:
inp (matrix)
method str(inp)
Namespace types: matrix
Parameters:
inp (matrix)
method str(inp)
Namespace types: matrix
Parameters:
inp (matrix)
method str(inp)
Namespace types: matrix
Parameters:
inp (matrix)
method str(inp)
Namespace types: matrix
Parameters:
inp (matrix)
method str(inp)
Namespace types: matrix
Parameters:
inp (matrix)
method str(inp)
Namespace types: linefill
Parameters:
inp (linefill )
method str(inp)
Namespace types: line
Parameters:
inp (line )
method str(inp)
Namespace types: box
Parameters:
inp (box )
method str(inp)
Namespace types: label
Parameters:
inp (label )
method str(inp)
Namespace types: string
Parameters:
inp (string )
method str(inp)
Namespace types: int
Parameters:
inp (int )
method str(inp)
Namespace types: float
Parameters:
inp (float )
method str(inp)
Namespace types: bool
Parameters:
inp (bool )
method arrayShorten(str)
arrayShorten
Namespace types: series string, simple string, input string, const string
Parameters:
str (string) : `string` - the string to shorten | Required
Returns: `string` - a shortened version of the input string if it is an array with more than 7 elements, otherwise the original string
method matrixShorten(str)
matrixShorten
Namespace types: series string, simple string, input string, const string
Parameters:
str (string) : `string` - the string to shorten | Required
Returns: `string` - the shortened matrix string if the input is a matrix, otherwise returns the input string as is
method print(x, ID)
print all types to theh same console with just this `method/function`
```
(overload)
*.print(any x, string ID, bool shorten=true?) => console
"param 'shorten' - only for arrays and matrixs" | true
```
Namespace types: series string, simple string, input string, const string
Parameters:
x (string) : - `any` input to convert
ID (string) : - `string` unique id for label on console `MUST BE UNIQUE`
Returns: adds the `ID` and the `inp` to the console on the chart
method print(x, ID)
Namespace types: series float, simple float, input float, const float
Parameters:
x (float)
ID (string)
method print(x, ID)
Namespace types: series int, simple int, input int, const int
Parameters:
x (int)
ID (string)
method print(x, ID)
Namespace types: series box
Parameters:
x (box)
ID (string)
method print(x, ID)
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
x (bool)
ID (string)
method print(x, ID)
Namespace types: series label
Parameters:
x (label)
ID (string)
method print(x, ID)
Namespace types: series line
Parameters:
x (line)
ID (string)
method print(x, ID)
Namespace types: series linefill
Parameters:
x (linefill)
ID (string)
method print(x, ID, shorten)
Namespace types: string
Parameters:
x (string )
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: float
Parameters:
x (float )
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: int
Parameters:
x (int )
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: box
Parameters:
x (box )
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: bool
Parameters:
x (bool )
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: label
Parameters:
x (label )
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: line
Parameters:
x (line )
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: linefill
Parameters:
x (linefill )
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: matrix
Parameters:
x (matrix)
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: matrix
Parameters:
x (matrix)
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: matrix
Parameters:
x (matrix)
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: matrix
Parameters:
x (matrix)
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: matrix
Parameters:
x (matrix)
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: matrix
Parameters:
x (matrix)
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: matrix
Parameters:
x (matrix)
ID (string)
shorten (bool)
method print(x, ID, shorten)
Namespace types: matrix
Parameters:
x (matrix)
ID (string)
shorten (bool)
DarkWaveColorThemesLibrary "DarkWaveColorThemes"
Description:
A simple, binary color-theming library that provides you with easy-access 'bullish and bearish' colors which you can use to make your indicators more aesthetically pleasing. These color themes were developed to help the community make indicators look excellent with ease.
Functions:
1. getThemeColor(themeName, colorType)
Description:
This function returns a color (either a 'Bullish' or 'Bearish' color, depending on your 'colorType' parameter input) according to the theme you have supplied as the 'themeName' parameter.
Parameters:
themeName (string) : Specify the theme you want to reference. Options include: 'DarkWave', 'Synthwave', 'DarkWave Crypto', 'Crystal Pool', 'Aquafarer', 'Mystic Armor', 'Futurist', 'Electric Zest', 'Stealth Ride', 'Long Trader', 'Short Trader', 'Emerald Glow', 'Gold Heist', 'Floral', 'Cobalt Twilight', and 'Sunrise'.
colorType (string) : Specify which color you want to reference from the theme. Options include: 'Bullish' and 'Bearish'.
Returns:
Your specified color type according to your specified theme.
LibraryTimeframeHelperLibrary "LibraryTimeframeHelper"
Helper functions to work with timeframes: to get the next higher TF, and to make the string pretty for use in labels. Perhaps I'll add more later.
f_getHigherTF(_TF)
f_getHigherTF(): Converts the input timeframe into the next one up in the list of commonly used timeframes. NOTE: You can NOT use a TF from this function as input to a request.security() call if called from this library because it gets converted to a series (since there's nothing special about this function, I expect this probably goes for any library). However, you CAN copy the code and use it directly in your script, in which case the output is only a simple variable and thus suitable for the timeframe of a request.security() call.
Parameters:
_TF (string) - The timeframe to convert.
Returns: : A string in standard timeframe format.
f_prettifyTF(_TF)
f_prettifyTF(): Converts the input timeframe from standard timeframe format to the format shown by TradingView on a chart. The output is not suitable for use as an input timeframe of a request.security() call.
Parameters:
_TF (string) - The timeframe to convert.
Returns: : A string in prettified timeframe format.
AlgebraLibLibrary "AlgebraLib"
f_signaldraw(_side, _date)
: Draw a simple label with Buy or Sell signal
Parameters:
_side (string)
_date (int)
Returns: : VOID, it draws a new label
cphelperLibrary "cphelper"
ACPU helper library - for private use. Not so meaningful for others.
calculate_rr(targetArray, rrArray, breakevenOnTarget1)
calculates risk reward for given targets
Parameters:
targetArray (float ) : array of targets
rrArray (float ) : array of risk reward
breakevenOnTarget1 (simple bool) : option to breakeven
Returns: array rrArray
trendPairs(l1StartX, l1StartY, l1EndX, l1EndY, l2StartX, l2StartY, l2EndX, l2EndY, zgColor)
creates trendline pairs
Parameters:
l1StartX (int) : startX of first line
l1StartY (float) : startY of first line
l1EndX (int) : endX of first line
l1EndY (float) : endY of first line
l2StartX (int) : startX of second line
l2StartY (float) : startY of second line
l2EndX (int) : endX of second line
l2EndY (float) : endY of second line
zgColor (color) : line color
Returns:
find_type(l1t, l2t, channelThreshold)
Finds type based on trendline pairs
Parameters:
l1t (line) : line1
l2t (line) : line2
channelThreshold (simple float) : theshold for channel identification
Returns: pattern type and flags
getFlags(flags)
Flatten flags
Parameters:
flags (bool ) : array of flags
Returns: - flattened flags isChannel, isTriangle, isWedge, isExpanding, isContracting, isFlat, isRising, isFalling
getType(typeNum)
Get type based on type number
Parameters:
typeNum (int) : number representing type
Returns: String value of type
getStatus(status, maxStatus)
Get status based on integer value representations
Parameters:
status (int) : integer representing current status
maxStatus (int) : integer representing max status
Returns: String status value
calculate_simple_targets(trendLines, settingsMatrix, patternTypeMapping, patternType)
Calculate targets based on trend lines
Parameters:
trendLines (line ) : trendline pair array
settingsMatrix (matrix) : matrix containing settings
patternTypeMapping (string ) : array containing pattern type mapping
patternType (int) : pattern type
Returns: arrays containing long and short calculated targets
recalculate_position(patternTypeAndStatusMatrix, targetMatrix, index, pIndex, status, maxStatus, targetValue, stopValue, dir, breakevenOnTarget1)
Recalculate position values
Parameters:
patternTypeAndStatusMatrix (matrix) : matrix containing pattern type and status
targetMatrix (matrix) : matrix containing targets
index (int) : current index
pIndex (int) : pattern index
status (int) : current status
maxStatus (int) : max status reached
targetValue (float) : current target value
stopValue (float) : current stop value
dir (int) : direction
breakevenOnTarget1 (simple bool) : flag to breakeven upon target1
Returns: new status and maxStatus values
draw_targets(longTargets, shortTargets, index, labelColor, patternName, positionIndex, longMaxStatus, longStatus, shortMaxStatus, shortStatus, tempBoxes, tempLines, tempLabels)
Draw targets on chart
Parameters:
longTargets (matrix) : matrix containing long targets
shortTargets (matrix) : matrix containing short targets
index (int) : current index
labelColor (color) : color of lines and labels
patternName (string) : Pattern name
positionIndex (int) : position on the chart
longMaxStatus (int) : max status for long
longStatus (int) : long status value
shortMaxStatus (int) : max status for short
shortStatus (int) : short status value
tempBoxes (box ) : temporary box array
tempLines (line ) : temporary lines array
tempLabels (label ) : temporary labels array
Returns: void
populate_open_stats(patternIdArray, barMatrix, patternTypeAndStatusMatrix, patternColorArray, longTargets, shortTargets, patternRRMatrix, OpenStatPosition, lblSizeOpenTrades)
Populate open stats table
Parameters:
patternIdArray (int ) : pattern Ids
barMatrix (matrix) : matrix containing bars
patternTypeAndStatusMatrix (matrix) : matrix containing pattern type and status
patternColorArray (color ) : array containing current patter colors
longTargets (matrix) : matrix of long targets
shortTargets (matrix) : matrix of short targets
patternRRMatrix (matrix) : pattern risk reward matrix
OpenStatPosition (simple string) : table position
lblSizeOpenTrades (simple string) : text size
Returns: void
draw_pattern_label(trendLines, patternFlagMatrix, patternTypeAndStatusMatrix, patternColorArray, patternFlags, patternLabelArray, zgColor, patternType, drawLabel, clearOldPatterns, safeRepaint, maxPatternsReference)
Parameters:
trendLines (line )
patternFlagMatrix (matrix)
patternTypeAndStatusMatrix (matrix)
patternColorArray (color )
patternFlags (bool )
patternLabelArray (label )
zgColor (color)
patternType (int)
drawLabel (simple bool)
clearOldPatterns (simple bool)
safeRepaint (simple bool)
maxPatternsReference (simple int)
populate_closed_stats(patternTypeAndStatusMatrix, bullishCounts, bearishCounts, bullishRetouchCounts, bearishRetouchCounts, bullishSizeMatrix, bearishSizeMatrix, bullishRR, bearishRR, ClosedStatsPosition, lblSizeClosedTrades, showSelectivePatternStats, showPatternStats, showStatsInPercentage)
Parameters:
patternTypeAndStatusMatrix (matrix)
bullishCounts (matrix)
bearishCounts (matrix)
bullishRetouchCounts (matrix)
bearishRetouchCounts (matrix)
bullishSizeMatrix (matrix)
bearishSizeMatrix (matrix)
bullishRR (matrix)
bearishRR (matrix)
ClosedStatsPosition (simple string)
lblSizeClosedTrades (simple string)
showSelectivePatternStats (simple bool)
showPatternStats (simple bool)
showStatsInPercentage (simple bool)
FinandyHookLibLibrary "FinandyHookLib"
TODO: add library description here
createOrderJson(model, hook_secret, options)
Parameters:
model (orderModel type from Hamster-Coder/OrderLib/7)
hook_secret (string)
options (textFormatOptions)
textFormatOptions
Fields:
price_format (series__string)
percent_format (series__string)
KernelFunctionsFiltersLibrary "KernelFunctionsFilters"
This library provides filters for non-repainting kernel functions for Nadaraya-Watson estimator implementations made by @jdehorty. Filters include a smoothing formula and zero lag formula. You can find examples in the code. For more information check out the original library KernelFunctions.
rationalQuadratic(_src, _lookback, _relativeWeight, startAtBar, _filter)
Parameters:
_src (float)
_lookback (simple int)
_relativeWeight (simple float)
startAtBar (simple int)
_filter (simple string)
gaussian(_src, _lookback, startAtBar, _filter)
Parameters:
_src (float)
_lookback (simple int)
startAtBar (simple int)
_filter (simple string)
periodic(_src, _lookback, _period, startAtBar, _filter)
Parameters:
_src (float)
_lookback (simple int)
_period (simple int)
startAtBar (simple int)
_filter (simple string)
locallyPeriodic(_src, _lookback, _period, startAtBar, _filter)
Parameters:
_src (float)
_lookback (simple int)
_period (simple int)
startAtBar (simple int)
_filter (simple string)
j(line1, line2)
Parameters:
line1 (float)
line2 (float)
MyCandleLibraryLibrary "MyCandleLibrary"
TODO: Candle Pattern Library
IsEngulfingCandle(n, trendRule)
TODO: Identify Bullish Engulfing Candle
Parameters:
n (int) : TODO: Candle Number
trendRule (string)
Returns: TODO: If Identify Bullish Engulfing candle return True otherwise False
HelperTALibrary "HelperTA"
This library contains useful technical indicators that I use regularly in my charts.
`stockRSI` is not mine, but included because used often and referenced by internal functions.
`DCO` is a normalisation of the donchian channels; the price relative to the donchian channels, on a range.
`MarketCycle` is a weighted aggregate of RSI, Stochastic RSI & DCO (demo on the chart)
stockRSI(src, K, D, rsiPeriod, stochPeriod)
stockRSI
Parameters:
src (float)
K (int)
D (int)
rsiPeriod (simple int)
stochPeriod (int)
Returns:
DCO(price, donchianPeriod, smaPeriod)
DCO
Parameters:
price (float)
donchianPeriod (int)
smaPeriod (int)
Returns:
MarketCycle(donchianPrice, rsiPrice, srsiPrice, donchianPeriod, donchianSmoothing, rsiPeriod, rsiSmoothing, srsiPeriod, srsiSmoothing, srsiK, srsiD, rsiWeight, srsiWeight, dcoWeight)
MarketCycle
Parameters:
donchianPrice (float)
rsiPrice (float)
srsiPrice (float)
donchianPeriod (simple int)
donchianSmoothing (simple int)
rsiPeriod (simple int)
rsiSmoothing (int)
srsiPeriod (simple int)
srsiSmoothing (simple int)
srsiK (simple int)
srsiD (simple int)
rsiWeight (simple float)
srsiWeight (simple float)
dcoWeight (simple float)
Returns:
Vector3Library "Vector3"
Representation of 3D vectors and points.
This structure is used to pass 3D positions and directions around. It also contains functions for doing common vector operations.
Besides the functions listed below, other classes can be used to manipulate vectors and points as well.
For example the Quaternion and the Matrix4x4 classes are useful for rotating or transforming vectors and points.
___
**Reference:**
- github.com
- github.com
- github.com
- www.movable-type.co.uk
- docs.unity3d.com
- referencesource.microsoft.com
- github.com
\
new(x, y, z)
Create a new `Vector3`.
Parameters:
x (float) : `float` Property `x` value, (optional, default=na).
y (float) : `float` Property `y` value, (optional, default=na).
z (float) : `float` Property `z` value, (optional, default=na).
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.new(1.1, 1, 1)
```
from(value)
Create a new `Vector3` from a single value.
Parameters:
value (float) : `float` Properties positional value, (optional, default=na).
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.from(1.1)
```
from_Array(values, fill_na)
Create a new `Vector3` from a list of values, only reads up to the third item.
Parameters:
values (float ) : `array` Vector property values.
fill_na (float) : `float` Parameter value to replace missing indexes, (optional, defualt=na).
Returns: `Vector3` Generated new vector.
___
**Notes:**
- Supports any size of array, fills non available fields with `na`.
___
**Usage:**
```
.from_Array(array.from(1.1, fill_na=33))
.from_Array(array.from(1.1, 2, 3))
```
from_Vector2(values)
Create a new `Vector3` from a `Vector2`.
Parameters:
values (Vector2 type from RicardoSantos/CommonTypesMath/1) : `Vector2` Vector property values.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.from:Vector2(.Vector2.new(1, 2.0))
```
___
**Notes:**
- Type `Vector2` from CommonTypesMath library.
from_Quaternion(values)
Create a new `Vector3` from a `Quaternion`'s `x, y, z` properties.
Parameters:
values (Quaternion type from RicardoSantos/CommonTypesMath/1) : `Quaternion` Vector property values.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.from_Quaternion(.Quaternion.new(1, 2, 3, 4))
```
___
**Notes:**
- Type `Quaternion` from CommonTypesMath library.
from_String(expression, separator, fill_na)
Create a new `Vector3` from a list of values in a formated string.
Parameters:
expression (string) : `array` String with the list of vector properties.
separator (string) : `string` Separator between entries, (optional, default=`","`).
fill_na (float) : `float` Parameter value to replace missing indexes, (optional, defualt=na).
Returns: `Vector3` Generated new vector.
___
**Notes:**
- Supports any size of array, fills non available fields with `na`.
- `",,"` Empty fields will be ignored.
___
**Usage:**
```
.from_String("1.1", fill_na=33))
.from_String("(1.1,, 3)") // 1.1 , 3.0, NaN // empty field will be ignored!!
```
back()
Create a new `Vector3` object in the form `(0, 0, -1)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.back()
```
front()
Create a new `Vector3` object in the form `(0, 0, 1)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.front()
```
up()
Create a new `Vector3` object in the form `(0, 1, 0)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.up()
```
down()
Create a new `Vector3` object in the form `(0, -1, 0)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.down()
```
left()
Create a new `Vector3` object in the form `(-1, 0, 0)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.left()
```
right()
Create a new `Vector3` object in the form `(1, 0, 0)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.right()
```
zero()
Create a new `Vector3` object in the form `(0, 0, 0)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.zero()
```
one()
Create a new `Vector3` object in the form `(1, 1, 1)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.one()
```
minus_one()
Create a new `Vector3` object in the form `(-1, -1, -1)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.minus_one()
```
unit_x()
Create a new `Vector3` object in the form `(1, 0, 0)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.unit_x()
```
unit_y()
Create a new `Vector3` object in the form `(0, 1, 0)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.unit_y()
```
unit_z()
Create a new `Vector3` object in the form `(0, 0, 1)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.unit_z()
```
nan()
Create a new `Vector3` object in the form `(na, na, na)`.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.nan()
```
random(max, min)
Generate a vector with random properties.
Parameters:
max (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Maximum defined range of the vector properties.
min (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Minimum defined range of the vector properties.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.random(.from(math.pi), .from(-math.pi))
```
random(max)
Generate a vector with random properties (min set to 0.0).
Parameters:
max (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Maximum defined range of the vector properties.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
.random(.from(math.pi))
```
method copy(this)
Copy a existing `Vector3`
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .one().copy()
```
method i_add(this, other)
Modify a instance of a vector by adding a vector to it.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other Vector.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_add(.up())
```
method i_add(this, value)
Modify a instance of a vector by adding a vector to it.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
value (float) : `float` Value.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_add(3.2)
```
method i_subtract(this, other)
Modify a instance of a vector by subtracting a vector to it.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other Vector.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_subtract(.down())
```
method i_subtract(this, value)
Modify a instance of a vector by subtracting a vector to it.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
value (float) : `float` Value.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_subtract(3)
```
method i_multiply(this, other)
Modify a instance of a vector by multiplying a vector with it.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other Vector.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_multiply(.left())
```
method i_multiply(this, value)
Modify a instance of a vector by multiplying a vector with it.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
value (float) : `float` value.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_multiply(3)
```
method i_divide(this, other)
Modify a instance of a vector by dividing it by another vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other Vector.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_divide(.forward())
```
method i_divide(this, value)
Modify a instance of a vector by dividing it by another vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
value (float) : `float` Value.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_divide(3)
```
method i_mod(this, other)
Modify a instance of a vector by modulo assignment with another vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other Vector.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_mod(.back())
```
method i_mod(this, value)
Modify a instance of a vector by modulo assignment with another vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
value (float) : `float` Value.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_mod(3)
```
method i_pow(this, exponent)
Modify a instance of a vector by modulo assignment with another vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
exponent (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Exponent Vector.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_pow(.up())
```
method i_pow(this, exponent)
Modify a instance of a vector by modulo assignment with another vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
exponent (float) : `float` Exponent Value.
Returns: `Vector3` Updated source vector.
___
**Usage:**
```
a = .from(1) , a.i_pow(2)
```
method length_squared(this)
Squared length of the vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1)
Returns: `float` The squared length of this vector.
___
**Usage:**
```
a = .one().length_squared()
```
method magnitude_squared(this)
Squared magnitude of the vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `float` The length squared of this vector.
___
**Usage:**
```
a = .one().magnitude_squared()
```
method length(this)
Length of the vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `float` The length of this vector.
___
**Usage:**
```
a = .one().length()
```
method magnitude(this)
Magnitude of the vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `float` The Length of this vector.
___
**Usage:**
```
a = .one().magnitude()
```
method normalize(this, magnitude, eps)
Normalize a vector with a magnitude of 1(optional).
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
magnitude (float) : `float` Value to manipulate the magnitude of normalization, (optional, default=1.0).
eps (float)
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .new(33, 50, 100).normalize() // (x=0.283, y=0.429, z=0.858)
a = .new(33, 50, 100).normalize(2) // (x=0.142, y=0.214, z=0.429)
```
method to_String(this, precision)
Converts source vector to a string format, in the form `"(x, y, z)"`.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
precision (string) : `string` Precision format to apply to values (optional, default='').
Returns: `string` Formated string in a `"(x, y, z)"` format.
___
**Usage:**
```
a = .one().to_String("#.###")
```
method to_Array(this)
Converts source vector to a array format.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `array` List of the vector properties.
___
**Usage:**
```
a = .new(1, 2, 3).to_Array()
```
method to_Vector2(this)
Converts source vector to a Vector2 in the form `x, y`.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector2` Generated new vector.
___
**Usage:**
```
a = .from(1).to_Vector2()
```
method to_Quaternion(this, w)
Converts source vector to a Quaternion in the form `x, y, z, w`.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Sorce vector.
w (float) : `float` Property of `w` new value.
Returns: `Quaternion` Generated new vector.
___
**Usage:**
```
a = .from(1).to_Quaternion(w=1)
```
method add(this, other)
Add a vector to source vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).add(.unit_z())
```
method add(this, value)
Add a value to each property of the vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
value (float) : `float` Value.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).add(2.0)
```
add(value, other)
Add each property of a vector to a base value as a new vector.
Parameters:
value (float) : `float` Value.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(2) , b = .add(1.0, a)
```
method subtract(this, other)
Subtract vector from source vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).subtract(.left())
```
method subtract(this, value)
Subtract a value from each property in source vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
value (float) : `float` Value.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).subtract(2.0)
```
subtract(value, other)
Subtract each property in a vector from a base value and create a new vector.
Parameters:
value (float) : `float` Value.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .subtract(1.0, .right())
```
method multiply(this, other)
Multiply a vector by another.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).multiply(.up())
```
method multiply(this, value)
Multiply each element in source vector with a value.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
value (float) : `float` Value.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).multiply(2.0)
```
multiply(value, other)
Multiply a value with each property in a vector and create a new vector.
Parameters:
value (float) : `float` Value.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .multiply(1.0, .new(1, 2, 1))
```
method divide(this, other)
Divide a vector by another.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).divide(.from(2))
```
method divide(this, value)
Divide each property in a vector by a value.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
value (float) : `float` Value.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).divide(2.0)
```
divide(value, other)
Divide a base value by each property in a vector and create a new vector.
Parameters:
value (float) : `float` Value.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .divide(1.0, .from(2))
```
method mod(this, other)
Modulo a vector by another.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).mod(.from(2))
```
method mod(this, value)
Modulo each property in a vector by a value.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
value (float) : `float` Value.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).mod(2.0)
```
mod(value, other)
Modulo a base value by each property in a vector and create a new vector.
Parameters:
value (float) : `float` Value.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .mod(1.0, .from(2))
```
method negate(this)
Negate a vector in the form `(zero - this)`.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .one().negate()
```
method pow(this, other)
Modulo a vector by another.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(2).pow(.from(3))
```
method pow(this, exponent)
Raise the vector elements by a exponent.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
exponent (float) : `float` The exponent to raise the vector by.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).pow(2.0)
```
pow(value, exponent)
Raise value into a vector raised by the elements in exponent vector.
Parameters:
value (float) : `float` Base value.
exponent (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` The exponent to raise the vector of base value by.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .pow(1.0, .from(2))
```
method sqrt(this)
Square root of the elements in a vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).sqrt()
```
method abs(this)
Absolute properties of the vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).abs()
```
method max(this)
Highest property of the vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `float` Highest value amongst the vector properties.
___
**Usage:**
```
a = .new(1, 2, 3).max()
```
method min(this)
Lowest element of the vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `float` Lowest values amongst the vector properties.
___
**Usage:**
```
a = .new(1, 2, 3).min()
```
method floor(this)
Floor of vector a.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .new(1.33, 1.66, 1.99).floor()
```
method ceil(this)
Ceil of vector a.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .new(1.33, 1.66, 1.99).ceil()
```
method round(this)
Round of vector elements.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .new(1.33, 1.66, 1.99).round()
```
method round(this, precision)
Round of vector elements to n digits.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
precision (int) : `int` Number of digits to round the vector elements.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .new(1.33, 1.66, 1.99).round(1) // 1.3, 1.7, 2
```
method fractional(this)
Fractional parts of vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1.337).fractional() // 0.337
```
method dot_product(this, other)
Dot product of two vectors.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other vector.
Returns: `float` Dot product.
___
**Usage:**
```
a = .from(2).dot_product(.left())
```
method cross_product(this, other)
Cross product of two vectors.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).cross_produc(.right())
```
method scale(this, scalar)
Scale vector by a scalar value.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
scalar (float) : `float` Value to scale the the vector by.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).scale(2)
```
method rescale(this, magnitude)
Rescale a vector to a new magnitude.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
magnitude (float) : `float` Value to manipulate the magnitude of normalization.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(20).rescale(1)
```
method equals(this, other)
Compares two vectors.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
other (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Other vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).equals(.one())
```
method sin(this)
Sine of vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).sin()
```
method cos(this)
Cosine of vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).cos()
```
method tan(this)
Tangent of vector.
Namespace types: TMath.Vector3
Parameters:
this (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .from(1).tan()
```
vmax(a, b)
Highest elements of the properties from two vectors.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .vmax(.one(), .from(2))
```
vmax(a, b, c)
Highest elements of the properties from three vectors.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
c (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .vmax(.new(0.1, 2.5, 3.4), .from(2), .from(3))
```
vmin(a, b)
Lowest elements of the properties from two vectors.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .vmin(.one(), .from(2))
```
vmin(a, b, c)
Lowest elements of the properties from three vectors.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
c (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .vmin(.one(), .from(2), .new(3.3, 2.2, 0.5))
```
distance(a, b)
Distance between vector `a` and `b`.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Target vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = distance(.from(3), .unit_z())
```
clamp(a, min, max)
Restrict a vector between a min and max vector.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
min (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Minimum boundary vector.
max (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Maximum boundary vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .clamp(a=.new(2.9, 1.5, 3.9), min=.from(2), max=.new(2.5, 3.0, 3.5))
```
clamp_magnitude(a, radius)
Vector with its magnitude clamped to a radius.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.object, vector with properties that should be restricted to a radius.
radius (float) : `float` Maximum radius to restrict magnitude of vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .clamp_magnitude(.from(21), 7)
```
lerp_unclamped(a, b, rate)
`Unclamped` linearly interpolates between provided vectors by a rate.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Target vector.
rate (float) : `float` Rate of interpolation, range(0 > 1) where 0 == source vector and 1 == target vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .lerp_unclamped(.from(1), .from(2), 1.2)
```
lerp(a, b, rate)
Linearly interpolates between provided vectors by a rate.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Target vector.
rate (float) : `float` Rate of interpolation, range(0 > 1) where 0 == source vector and 1 == target vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = lerp(.one(), .from(2), 0.2)
```
herp(start, start_tangent, end, end_tangent, rate)
Hermite curve interpolation between provided vectors.
Parameters:
start (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Start vector.
start_tangent (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Start vector tangent.
end (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` End vector.
end_tangent (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` End vector tangent.
rate (int) : `float` Rate of the movement from `start` to `end` to get position, should be range(0 > 1).
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
s = .new(0, 0, 0) , st = .new(0, 1, 1)
e = .new(1, 2, 2) , et = .new(-1, -1, 3)
h = .herp(s, st, e, et, 0.3)
```
___
**Reference:** en.m.wikibooks.org
herp_2(a, b, rate)
Hermite curve interpolation between provided vectors.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Target vector.
rate (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Rate of the movement per component from `start` to `end` to get position, should be range(0 > 1).
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
h = .herp_2(.one(), .new(0.1, 3, 2), 0.6)
```
noise(a)
3D Noise based on Morgan McGuire @morgan3d
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = noise(.one())
```
___
**Reference:**
- thebookofshaders.com
- www.shadertoy.com
rotate(a, axis, angle)
Rotate a vector around a axis.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
axis (string) : `string` The plane to rotate around, `option="x", "y", "z"`.
angle (float) : `float` Angle in radians.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .rotate(.from(3), 'y', math.toradians(45.0))
```
rotate_x(a, angle)
Rotate a vector on a fixed `x`.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
angle (float) : `float` Angle in radians.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .rotate_x(.from(3), math.toradians(90.0))
```
rotate_y(a, angle)
Rotate a vector on a fixed `y`.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
angle (float) : `float` Angle in radians.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .rotate_y(.from(3), math.toradians(90.0))
```
rotate_yaw_pitch(a, yaw, pitch)
Rotate a vector by yaw and pitch values.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
yaw (float) : `float` Angle in radians.
pitch (float) : `float` Angle in radians.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .rotate_yaw_pitch(.from(3), math.toradians(90.0), math.toradians(45.0))
```
project(a, normal, eps)
Project a vector off a plane defined by a normal.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
normal (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` The normal of the surface being reflected off.
eps (float) : `float` Minimum resolution to void division by zero (default=0.000001).
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .project(.one(), .down())
```
project_on_plane(a, normal, eps)
Projects a vector onto a plane defined by a normal orthogonal to the plane.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
normal (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` The normal of the surface being reflected off.
eps (float) : `float` Minimum resolution to void division by zero (default=0.000001).
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .project_on_plane(.one(), .left())
```
project_to_2d(a, camera_position, camera_target)
Project a vector onto a two dimensions plane.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
camera_position (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Camera position.
camera_target (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Camera target plane position.
Returns: `Vector2` Generated new vector.
___
**Usage:**
```
a = .project_to_2d(.one(), .new(2, 2, 3), .zero())
```
reflect(a, normal)
Reflects a vector off a plane defined by a normal.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
normal (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` The normal of the surface being reflected off.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .reflect(.one(), .right())
```
angle(a, b, eps)
Angle in degrees between two vectors.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Target vector.
eps (float) : `float` Minimum resolution to void division by zero (default=1.0e-15).
Returns: `float` Angle value in degrees.
___
**Usage:**
```
a = .angle(.one(), .up())
```
angle_signed(a, b, axis)
Signed angle in degrees between two vectors.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Target vector.
axis (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Axis vector.
Returns: `float` Angle value in degrees.
___
**Usage:**
```
a = .angle_signed(.one(), .left(), .down())
```
___
**Notes:**
- The smaller of the two possible angles between the two vectors is returned, therefore the result will never
be greater than 180 degrees or smaller than -180 degrees.
- If you imagine the from and to vectors as lines on a piece of paper, both originating from the same point,
then the /axis/ vector would point up out of the paper.
- The measured angle between the two vectors would be positive in a clockwise direction and negative in an
anti-clockwise direction.
___
**Reference:**
- github.com
angle2d(a, b)
2D angle between two vectors.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
b (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Target vector.
Returns: `float` Angle value in degrees.
___
**Usage:**
```
a = .angle2d(.one(), .left())
```
transform_Matrix(a, M)
Transforms a vector by the given matrix.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
M (matrix) : `matrix` A 4x4 matrix. The transformation matrix.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
mat = matrix.new(4, 0)
mat.add_row(0, array.from(0.0, 0.0, 0.0, 1.0))
mat.add_row(1, array.from(0.0, 0.0, 1.0, 0.0))
mat.add_row(2, array.from(0.0, 1.0, 0.0, 0.0))
mat.add_row(3, array.from(1.0, 0.0, 0.0, 0.0))
b = .transform_Matrix(.one(), mat)
```
transform_M44(a, M)
Transforms a vector by the given matrix.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
M (M44 type from RicardoSantos/CommonTypesMath/1) : `M44` A 4x4 matrix. The transformation matrix.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .transform_M44(.one(), .M44.new(0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0))
```
___
**Notes:**
- Type `M44` from `CommonTypesMath` library.
transform_normal_Matrix(a, M)
Transforms a vector by the given matrix.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
M (matrix) : `matrix` A 4x4 matrix. The transformation matrix.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
mat = matrix.new(4, 0)
mat.add_row(0, array.from(0.0, 0.0, 0.0, 1.0))
mat.add_row(1, array.from(0.0, 0.0, 1.0, 0.0))
mat.add_row(2, array.from(0.0, 1.0, 0.0, 0.0))
mat.add_row(3, array.from(1.0, 0.0, 0.0, 0.0))
b = .transform_normal_Matrix(.one(), mat)
```
transform_normal_M44(a, M)
Transforms a vector by the given matrix.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector.
M (M44 type from RicardoSantos/CommonTypesMath/1) : `M44` A 4x4 matrix. The transformation matrix.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .transform_normal_M44(.one(), .M44.new(0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0))
```
___
**Notes:**
- Type `M44` from `CommonTypesMath` library.
transform_Array(a, rotation)
Transforms a vector by the given Quaternion rotation value.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector. The source vector to be rotated.
rotation (float ) : `array` A 4 element array. Quaternion. The rotation to apply.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .transform_Array(.one(), array.from(0.2, 0.2, 0.2, 1.0))
```
___
**Reference:**
- referencesource.microsoft.com
transform_Quaternion(a, rotation)
Transforms a vector by the given Quaternion rotation value.
Parameters:
a (Vector3 type from RicardoSantos/CommonTypesMath/1) : `Vector3` Source vector. The source vector to be rotated.
rotation (Quaternion type from RicardoSantos/CommonTypesMath/1) : `array` A 4 element array. Quaternion. The rotation to apply.
Returns: `Vector3` Generated new vector.
___
**Usage:**
```
a = .transform_Quaternion(.one(), .Quaternion.new(0.2, 0.2, 0.2, 1.0))
```
___
**Notes:**
- Type `Quaternion` from `CommonTypesMath` library.
___
**Reference:**
- referencesource.microsoft.com
Mad_MATHLibrary "MAD_MATH"
This is a mathematical library where I store useful kernels, filters and selectors for the different types of computations.
This library also contains opensource code from other scripters.
Future extensions are very likely, there are some functions I would like to add, but I have to wait for approvals so i can include them.
Ehlers_EMA(_src, _length)
Calculates the Ehlers Exponential Moving Average (Ehlers_EMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers EMA
Returns: The Ehlers EMA value
Ehlers_Gaussian(_src, _length)
Calculates the Ehlers Gaussian Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Gaussian Filter
Returns: The Ehlers Gaussian Filter value
Ehlers_supersmoother(_src, _length)
Calculates the Ehlers Supersmoother
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Supersmoother
Returns: The Ehlers Supersmoother value
Ehlers_SMA_fast(_src, _length)
Calculates the Ehlers Simple Moving Average (SMA) Fast
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers SMA Fast
Returns: The Ehlers SMA Fast value
Ehlers_EMA_fast(_src, _length)
Calculates the Ehlers Exponential Moving Average (EMA) Fast
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers EMA Fast
Returns: The Ehlers EMA Fast value
Ehlers_RSI_fast(_src, _length)
Calculates the Ehlers Relative Strength Index (RSI) Fast
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers RSI Fast
Returns: The Ehlers RSI Fast value
Ehlers_Band_Pass_Filter(_src, _length)
Calculates the Ehlers BandPass Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers BandPass Filter
Returns: The Ehlers BandPass Filter value
Ehlers_Butterworth(_src, _length)
Calculates the Ehlers Butterworth Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Butterworth Filter
Returns: The Ehlers Butterworth Filter value
Ehlers_Two_Pole_Gaussian_Filter(_src, _length)
Calculates the Ehlers Two-Pole Gaussian Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Two-Pole Gaussian Filter
Returns: The Ehlers Two-Pole Gaussian Filter value
Ehlers_Two_Pole_Butterworth_Filter(_src, _length)
Calculates the Ehlers Two-Pole Butterworth Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Two-Pole Butterworth Filter
Returns: The Ehlers Two-Pole Butterworth Filter value
Ehlers_Band_Stop_Filter(_src, _length)
Calculates the Ehlers Band Stop Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Band Stop Filter
Returns: The Ehlers Band Stop Filter value
Ehlers_Smoother(_src)
Calculates the Ehlers Smoother
Parameters:
_src (float) : The source series for calculation
Returns: The Ehlers Smoother value
Ehlers_High_Pass_Filter(_src, _length)
Calculates the Ehlers High Pass Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers High Pass Filter
Returns: The Ehlers High Pass Filter value
Ehlers_2_Pole_High_Pass_Filter(_src, _length)
Calculates the Ehlers Two-Pole High Pass Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Two-Pole High Pass Filter
Returns: The Ehlers Two-Pole High Pass Filter value
pr(_src, _length)
pr Calculates the percentage rank (PR) of a value within a range.
Parameters:
_src (float) : The source value for which the percentage rank is calculated. It represents the value to be ranked within the range.
_length (simple int) : The _length of the range over which the percentage rank is calculated. It determines the number of bars considered for the calculation.
Returns: The percentage rank (PR) of the source value within the range, adjusted by adding 50 to the result.
smma(_src, _length)
Calculates the SMMA (Smoothed Moving Average)
Parameters:
_src (float) : The source series for calculation
_length (simple int)
Returns: The SMMA value
hullma(_src, _length)
Calculates the Hull Moving Average (HullMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the HullMA
Returns: The HullMA value
tma(_src, _length)
Calculates the Triple Moving Average (TMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the TMA
Returns: The TMA value
dema(_src, _length)
Calculates the Double Exponential Moving Average (DEMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the DEMA
Returns: The DEMA value
tema(_src, _length)
Calculates the Triple Exponential Moving Average (TEMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the TEMA
Returns: The TEMA value
w2ma(_src, _length)
Calculates the Normalized Double Moving Average (N2MA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the N2MA
Returns: The N2MA value
wma(_src, _length)
Calculates the Normalized Moving Average (NMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the NMA
Returns: The NMA value
nma(_open, _close, _length)
Calculates the Normalized Moving Average (NMA)
Parameters:
_open (float) : The open price series
_close (float) : The close price series
_length (simple int) : The _length for finding the highest and lowest values
Returns: The NMA value
lma(_src, _length)
Parameters:
_src (float)
_length (simple int)
zero_lag(_src, _length, gamma1, zl)
Calculates the Zero Lag Moving Average (ZeroLag)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the moving average
gamma1 (simple int) : The coefficient for calculating 'd'
zl (simple bool) : Boolean flag for applying Zero Lag
Returns: An array containing the ZeroLag Moving Average and a boolean flag indicating if it's flat
copyright HPotter, thanks for that great function
chebyshevI(src, len, ripple)
Calculates the Chebyshev Type I Filter
Parameters:
src (float) : The source series for calculation
len (int) : The length of the filter
ripple (float) : The ripple factor for the filter
Returns: The output of the Chebyshev Type I Filter
math from Pafnuti Lwowitsch Tschebyschow (1821–1894)
Thanks peacefulLizard50262 for the find and translation
chebyshevII(src, len, ripple)
Calculates the Chebyshev Type II Filter
Parameters:
src (float) : The source series for calculation
len (int) : The length of the filter
ripple (float) : The ripple factor for the filter
Returns: The output of the Chebyshev Type II Filter
math from Pafnuti Lwowitsch Tschebyschow (1821–1894)
Thanks peacefulLizard50262 for the find
wavetrend(_src, _n1, _n2)
Calculates the WaveTrend indicator
Parameters:
_src (float) : The source series for calculation
_n1 (simple int) : The period for the first EMA calculation
_n2 (simple int) : The period for the second EMA calculation
Returns: The WaveTrend value
f_getma(_type, _src, _length, ripple)
Calculates various types of moving averages
Parameters:
_type (simple string) : The type of indicator to calculate
_src (float) : The source series for calculation
_length (simple int) : The length for the moving average or indicator
ripple (simple float)
Returns: The calculated moving average or indicator value
f_getfilter(_type, _src, _length)
Calculates various types of filters
Parameters:
_type (simple string) : The type of indicator to calculate
_src (float) : The source series for calculation
_length (simple int) : The length for the moving average or indicator
Returns: The filtered value
f_getoszillator(_type, _src, _length)
Calculates various types of Deviations and other indicators
Parameters:
_type (simple string) : The type of indicator to calculate
_src (float) : The source series for calculation
_length (simple int) : The length for the moving average or indicator
Returns: The calculated moving average or indicator value
arraybrowser█ ARRAY BROWSER
Add you arrays to the array browser window and scroll them away left and right.
Flexible formatting options (see below).
Many thanks to @kaigouthro for his beautiful matrixautotable library. (import kaigouthro/matrixautotable/14)
How to use
Copy the "ARRAY BROWSER" commented code section below to your script and uncomment.
See DEMO section in the library for usage examples.
Basically: add() your arrays and draw() on barstate.islast.
If your script adds the arrays every calculation do not forget to clear() before adding.
Otherwise, since the arrays are added by reference, no need to add them on every bar, every time you draw() the actual values are retrieved.
Up to 10 arrays of each type (float/string/line/label/box) are supported (total 50 arrays).
Change offset in the input settings to scroll left/right.
Usage example:
import moebius1977/arraybrowser/1 as arraybrowser // this alias is used in the copied section, so better keep it
arbr.clear() // clears all rows and deletes the table
arbr.add(arrayFloat, format = "0.00") // adds an array with title
arbr.add(arrayInt) // adds an array without title
arbr.add(arrayTimes, "array of times 1", "date time") // format date and time so as to fit in the cell.
arbr.add(arrayTimes, "array of times 2", "{0, time, HH:mm}") // format date and time so as to fit in the cell.
arbr.add(arrayString) //
arbr.add(arrayLine, "arrayLines", "(x1, y1) (x2,y2)") // use your own format combining "x1", "y1", "x2", "y2"
arbr.add(arrayLabel, "arrayLabel", "txt") // only print label text, no coordinates
arbr.add(arrayBox, showIds = true) // show ID's for this array if input setting is "individually"
arbr.draw() // shows the table with arrays, use on barstate.islast
Formatting options
For float/int you can always use format string like "{0, time, HH:mm:ss}" or "{0.00}".
Additional options are
- --- Number formats ---
- "number"
- "0"
- "0.0"
- "0.00"
- "0.000"
- "0.0000"
- "0.00000"
- "0.000000"
- "0.0000000"
- --- Date formats ---
- "date"
- "date : time"
- "dd.MM"
- "dd"
- --- Time formats ---
- "time"
- "HH:mm"
- "mm:ss"
- "date time"
- "date, time"
- "date,time"
- "date\time"
For line and box : Empty `format` returns coordinates as "(x1, y1) - (x2, y2)". Otherwise "x1", "x2", "y1", "y2" in `format` string are replaced by values. (e.g. toS(line, "x1, x2") will only return x1 and x2 separated by comma).
For label : Empty `format` returns coordinates and text as "(x, y): text = text". Otherwise "x1", "y1", "txt" in `format` string are replaced by values. (e.g. toS(label, "txt") will only return text of the label)
JavaScript-style Debug ConsoleThis library provides a JavaScript-style debug console to Pine Coders. It supports the most commonly used utilities from the WHATWG Console Standard including the following:
• console.log
• console.debug
• console.info
• console.warn
• console.error
• console.assert
• console.count
• console.countReset
• console.group
• console.groupEnd
• console.clear
In addition to the WHATWG standard, this library also supports the following methods:
• console.show
• console.hide
FEATURES
• Follows the WHATWG Console Standard, which is widely adopted by all major JavaScript runtimes including browsers and Node.js.
• Provides an out-of-box UI with pre-configured theming, ensuring a clean and professional-looking console.
• Allows for easy UI customizations to fit your personal preferences.
• Has extremely simple import and initialization, making it easy to integrate with your existing codebase.
USAGE
1. Import this library:
import algotraderdev/Console/1
2. Initialize the console object:
var console = Console.new()
// You can also specify optional params to customize the look & feel.
var console = Console.new(
position = position.bottom_right,
max_rows = 50,
width = 0,
text_size = size.normal,
background_color = #000000CC,
timestamp_color = #AAAAAA,
info_message_color = #DDDDDD,
debug_message_color = #AAAAAA,
warn_message_color = #FFEB3B,
error_message_color = #ff3c00)
3. Use the console object to debug your code. Here are some examples:
// Basic logging
console.log('hello world!') // prints 'hello world'
console.warn('warn') // prints 'warn' in yellow
console.error('error') // prints 'error' in red
console.clear() // clears the console
// Assertion
console.assert(a.isEmpty(), 'array should be empty') // prints 'assertion failed: array should be empty' if the array is not empty
// Counter
console.count('fooFunction') // prints 'fooFunction: 1'
console.count('fooFunction') // prints 'fooFunction: 2'
console.countReset('fooFunction') // resets the counter
console.count('fooFunction') // prints 'fooFunction: 1'
// Group
console.log('A')
console.group()
console.log('B')
console.group()
console.log('C')
console.log('D')
console.groupEnd()
console.log('E')
console.groupEnd()
console.log('F')
// prints
// A
// B
// C
// D
// E
// F
// Hide and show
console.hide()
console.show()
biased_price_targetLibrary "biased_price_target"
Collection of functions that can be used for the calculation of biased price targets like stop loss and
take profit from a reference price using several methods that are already provided by the "distance_ratio" library plus
the 'HHLL'. Methods supported are percentagewise (PERC), atr-based (ATR), fixed profit (PROF), tick-based (TICKS),
risk reward ratio (RR), and highest high/lowest low (HHLL)
Position_controlLibrary "Position_control"
This is a library for defining positions and working with them.
f_calculateLeverage(_Leverage, _maintenance, _value, _direction)
Calculate the leverage used in a trade.
@description This function calculates the leverage used in a trade, based on the value of the trade, the maintenance margin, and the direction of the trade.
Parameters:
_Leverage (float) : The leverage used in the trade, as a floating point number.
_maintenance (float) : The maintenance margin percentage, as a floating point number.
_value (float) : The value of the trade, as a floating point number.
_direction (string) : The direction of the trade, either "long" or "short".
Returns: The leverage used in the trade, as a floating point number.
f_calculate_PL(_Position, _max_TP, _Position_index, _show_profit, _i_decimals_contracts, _i_decimals_prercent)
Calculate the profit or loss for a given trade.
@description This function calculates the profit or loss for a given trade, based on the position type, maximum take profit, position index, and whether to show the profit as a percentage or a value.
Parameters:
_Position (t_Position_type ) : An array of position types for the trade.
_max_TP (int) : The maximum take profit for the trade, as an integer value.
_Position_index (int) : The index of the position in the array, as an integer value.
_show_profit (bool) : A boolean value indicating whether to show the profit as a percentage or a value.
_i_decimals_contracts (int)
_i_decimals_prercent (int)
Returns: The profit or loss for the trade, as a floating point number.
f_drawposition(_Position, _Parameters, _Position_index)
draws a position on the chart
@description via sending in a typo of Position this function is able to drawout Stoploss, Entrybox, Takeprofits and the required labels with information
Parameters:
_Position (t_Position_type ) : array of type t_Position_type containing the position information.
_Parameters (t_drawing_parameters)
_Position_index (int) : the index of the current position.
Returns: None but boxes / lines / labels on the chart itself
t_TP_Variant
Fields:
TP_Type (series__string)
TP_Parameter_1 (series__integer)
TP_Parameter_2 (series__integer)
TP_Parameter_3 (series__float)
TP_Parameter_4 (series__float)
t_TPs
Fields:
TP_Price (series__float)
TP_Lot (series__float)
TP_Variant (|t_TP_Variant|#OBJ)
TP_Active (series__bool)
t_SLs
Fields:
SL_Price (series__float)
SL_Lot (series__float)
SL_Active (series__bool)
t_Position_type
Fields:
Lot (series__float)
Leverage (series__float)
Maintenance (series__float)
Starttime (series__integer)
Entry_Start (series__float)
Stoptime (series__integer)
Entry_Stop (series__float)
Entryprice (series__float)
TPs (array__|t_TPs|#OBJ)
SLs (array__|t_SLs|#OBJ)
t_drawing_parameters
Fields:
ShowPos (series__bool)
ShowLIQ (series__bool)
A_Colors (array__color)
Prolong_lines (series__bool)
Str_fontsize (series__string)
Textshift (series__integer)
Decimals_contracts (series__integer)
Decimals_price (series__integer)
Decimals_percent (series__integer)
bartime (series__integer)
Mad_StandardpartsLibrary "Mad_Standardparts"
This are my Standardparts used in upcoming scipts
roundTo(_value, _decimals)
Round a floating point value to a specified number of decimal places.
@description This function takes a floating point value and rounds it to a specified number of decimal places.
Parameters:
_value (float) : The floating point value to be rounded.
_decimals (int) : The number of decimal places to round to. Must be a non-negative integer.
Returns: The rounded value, as a floating point number.
clear_all()
Delete all drawings on the chart.
@description This function deletes all drawings on the chart, including lines, boxes, and labels.
Returns: None.
shifting(_value)
Create a string of spaces to shift text over by a specified amount.
@description This function takes an integer value and returns a string consisting of that many spaces, which can be used to shift text over in a PineScript chart.
Parameters:
_value (int) : The number of spaces to create in the output string.
Returns: A string consisting of the specified number of spaces.
fromLog(_value)
Convert a linear value to a logarithmic value.
@description This function takes a linear value and converts it to a logarithmic value, using the formula specified in the code.
Parameters:
_value (float)
Returns: The corresponding logarithmic value, as a floating point number.
toLog(_value)
Convert a logarithmic value to a linear value.
@description This function takes a logarithmic value and converts it to a linear value, using the formula specified in the code.
Parameters:
_value (float)
Returns: The corresponding linear value, as a floating point number.
f_getbartime()
Calculate the time per bar on the chart.
@description This function calculates the time per bar on the chart based on the first 100 bars.
Returns: The time per bar, as an integer value.
Metrics using Alternative Portfolio TheoryLibrary "APT_Metrics"
Portfolio metrics using alternative portfolio theory
metrics(init, cur, start, end, alpha)
Calculates APT metrics
Parameters:
init (float) : Starting Equity (strategy.initial)
cur (float)
start (int) : Start date (UNIX)
end (int) : End Date (UNIX)
alpha (float) : Confidence interval for DaR/CDaR. Defval = 0.05
Returns: Plots table with APT metrics
The metrics are shown in the bottom pane being applied to a buy-and-hold strategy.
PLEASE NOTE: This is the first draft of the library. Some calculations may be incorrect. If you spot any mistakes then please let me know and I will correct them as soon as possible. I am also open to suggestions on how to improve this.
At the moment this only works on the daily timeframe until I can find a way to universally calculate annualized volatility.
WebhookJsonMsgLibrary "WebhookJsonMsg"
This webhook json message library provides convenient functions for building JSON messages
Used to manage automatic transaction orders and positions
method buildWebhookJson(msg)
Builds the final JSON payload from a WebhookMessage type.
Namespace types: WebhookMessage
Parameters:
msg (WebhookMessage)
Returns: A JSON Payload.
Dict
Define some constant values
Fields:
OPEN_LONG (series string)
OPEN_SHORT (series string)
CLOSE_LONG (series string)
CLOSE_SHORT (series string)
LIMIT (series string)
MARKET (series string)
U_MARGIN (series string)
C_MARGIN (series string)
SPOT (series string)
WebhookMessage
Webhook message structure.
Fields:
strategyId (series string)
signalNo (series string)
symbol (series string)
symbolType (series string)
orderSide (series string)
price (series string)
orderType (series string)
takeProfitPrice (series string)
stopLossPrice (series string)
timestamp (series string)
accessKey (series string)