Hurst Exponent (Dubuc's variation method)Library "Hurst"
hurst(length, samples, hi, lo)
Estimate the Hurst Exponent using Dubuc's variation method
Parameters:
length : The length of the history window to use. Large values do not cause lag.
samples : The number of scale samples to take within the window. These samples are then used for regression. The minimum value is 2 but 3+ is recommended. Large values give more accurate results but suffer from a performance penalty.
hi : The high value of the series to analyze.
lo : The low value of the series to analyze.
The Hurst Exponent is a measure of fractal dimension, and in the context of time series it may be interpreted as indicating a mean-reverting market if the value is below 0.5 or a trending market if the value is above 0.5. A value of exactly 0.5 corresponds to a random walk.
There are many definitions of fractal dimension and many methods for its estimation. Approaches relying on calculation of an area, such as the Box Counting Method, are inappropriate for time series data, because the units of the x-axis (time) do match the units of the y-axis (price). Other approaches such as Detrended Fluctuation Analysis are useful for nonstationary time series but are not exactly equivalent to the Hurst Exponent.
This library implements Dubuc's variation method for estimating the Hurst Exponent. The technique is insensitive to x-axis units and is therefore useful for time series. It will give slightly different results to DFA, and the two methods should be compared to see which estimator fits your trading objectives best.
Original Paper:
Dubuc B, Quiniou JF, Roques-Carmes C, Tricot C. Evaluating the fractal dimension of profiles. Physical Review A. 1989;39(3):1500-1512. DOI: 10.1103/PhysRevA.39.1500
Review of various Hurst Exponent estimators for time-series data, including Dubuc's method:
www.intechopen.com
Techindicator
Traders_Reality_LibLibrary "Traders_Reality_Lib"
This library contains common elements used in Traders Reality scripts
calcPvsra(pvsraVolume, pvsraHigh, pvsraLow, pvsraClose, pvsraOpen, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor, darkGreyCandleColor, lightGrayCandleColor)
calculate the pvsra candle color and return the color as well as an alert if a vector candle has apperared.
Situation "Climax"
Bars with volume >= 200% of the average volume of the 10 previous chart TFs, or bars
where the product of candle spread x candle volume is >= the highest for the 10 previous
chart time TFs.
Default Colors: Bull bars are green and bear bars are red.
Situation "Volume Rising Above Average"
Bars with volume >= 150% of the average volume of the 10 previous chart TFs.
Default Colors: Bull bars are blue and bear are violet.
Parameters:
pvsraVolume : the instrument volume series (obtained from request.sequrity)
pvsraHigh : the instrument high series (obtained from request.sequrity)
pvsraLow : the instrument low series (obtained from request.sequrity)
pvsraClose : the instrument close series (obtained from request.sequrity)
pvsraOpen : the instrument open series (obtained from request.sequrity)
redVectorColor : red vector candle color
greenVectorColor : green vector candle color
violetVectorColor : violet/pink vector candle color
blueVectorColor : blue vector candle color
darkGreyCandleColor : regular volume candle down candle color - not a vector
lightGrayCandleColor : regular volume candle up candle color - not a vector
@return
adr(length, barsBack)
Parameters:
length : how many elements of the series to calculate on
barsBack : starting possition for the length calculation - current bar or some other value eg last bar
@return adr the adr for the specified lenght
adrHigh(adr, fromDo)
Calculate the ADR high given an ADR
Parameters:
adr : the adr
fromDo : boolean flag, if false calculate traditional adr from high low of today, if true calcualte from exchange midnight
@return adrHigh the position of the adr high in price
adrLow(adr, fromDo)
Parameters:
adr : the adr
fromDo : boolean flag, if false calculate traditional adr from high low of today, if true calcualte from exchange midnight
@return adrLow the position of the adr low in price
splitSessionString(sessXTime)
given a session in the format 0000-0100:23456 split out the hours and minutes
Parameters:
sessXTime : the session time string usually in the format 0000-0100:23456
@return
calcSessionStartEnd(sessXTime, gmt)
calculate the start and end timestamps of the session
Parameters:
sessXTime : the session time string usually in the format 0000-0100:23456
gmt : the gmt offset string usually in the format GMT+1 or GMT+2 etc
@return
drawOpenRange(sessXTime, sessXcol, showOrX, gmt)
draw open range for a session
Parameters:
sessXTime : session string in the format 0000-0100:23456
sessXcol : the color to be used for the opening range box shading
showOrX : boolean flag to toggle displaying the opening range
gmt : the gmt offset string usually in the format GMT+1 or GMT+2 etc
@return void
drawSessionHiLo(sessXTime, show_rectangleX, show_labelX, sessXcolLabel, sessXLabel, gmt, sessionLineStyle)
Parameters:
sessXTime : session string in the format 0000-0100:23456
show_rectangleX : show the session high and low lines
show_labelX : show the session label
sessXcolLabel : the color to be used for the hi/low lines and label
sessXLabel : the session label text
gmt : the gmt offset string usually in the format GMT+1 or GMT+2 etc
sessionLineStyle : the line stile for the session high low lines
@return void
calcDst()
calculate market session dst on/off flags
@return indicating if DST is on or off for a particular region
timestampPreviousDayOfWeek(previousDayOfWeek, hourOfDay, gmtOffset, oneWeekMillis)
Timestamp any of the 6 previous days in the week (such as last Wednesday at 21 hours GMT)
Parameters:
previousDayOfWeek : Monday or Satruday
hourOfDay : the hour of the day when psy calc is to start
gmtOffset : the gmt offset string usually in the format GMT+1 or GMT+2 etc
oneWeekMillis : the amount if time for a week in milliseconds
@return the timestamp of the psy level calculation start time
getdayOpen()
get the daily open - basically exchange midnight
@return the daily open value which is float price
newBar(res)
new_bar: check if we're on a new bar within the session in a given resolution
Parameters:
res : the desired resolution
@return true/false is a new bar for the session has started
toPips(val)
to_pips Convert value to pips
Parameters:
val : the value to convert to pips
@return the value in pips
rLabel(ry, rtext, rstyle, rcolor, valid, labelXOffset)
a function that draws a right aligned lable for a series during the current bar
Parameters:
ry : series float the y coordinate of the lable
rtext : the text of the label
rstyle : the style for the lable
rcolor : the color for the label
valid : a boolean flag that allows for turning on or off a lable
labelXOffset : how much to offset the label from the current position
rLabelOffset(ry, rtext, rstyle, rcolor, valid, labelXOffset)
a function that draws a right aligned lable for a series during the current bar
Parameters:
ry : series float the y coordinate of the lable
rtext : the text of the label
rstyle : the style for the lable
rcolor : the color for the label
valid : a boolean flag that allows for turning on or off a lable
labelXOffset : how much to offset the label from the current position
rLabelLastBar(ry, rtext, rstyle, rcolor, valid, labelXOffset)
a function that draws a right aligned lable for a series only on the last bar
Parameters:
ry : series float the y coordinate of the lable
rtext : the text of the label
rstyle : the style for the lable
rcolor : the color for the label
valid : a boolean flag that allows for turning on or off a lable
labelXOffset : how much to offset the label from the current position
drawLine(xSeries, res, tag, xColor, xStyle, xWidth, xExtend, isLabelValid, labelXOffset, validTimeFrame)
a function that draws a line and a label for a series
Parameters:
xSeries : series float the y coordinate of the line/label
res : the desired resolution controlling when a new line will start
tag : the text for the lable
xColor : the color for the label
xStyle : the style for the line
xWidth : the width of the line
xExtend : extend the line
isLabelValid : a boolean flag that allows for turning on or off a label
labelXOffset : how much to offset the label from the current position
validTimeFrame : a boolean flag that allows for turning on or off a line drawn
drawLineDO(xSeries, res, tag, xColor, xStyle, xWidth, xExtend, isLabelValid, labelXOffset, validTimeFrame)
a function that draws a line and a label for the daily open series
Parameters:
xSeries : series float the y coordinate of the line/label
res : the desired resolution controlling when a new line will start
tag : the text for the lable
xColor : the color for the label
xStyle : the style for the line
xWidth : the width of the line
xExtend : extend the line
isLabelValid : a boolean flag that allows for turning on or off a label
labelXOffset : how much to offset the label from the current position
validTimeFrame : a boolean flag that allows for turning on or off a line drawn
drawPivot(pivotLevel, res, tag, pivotColor, pivotLabelColor, pivotStyle, pivotWidth, pivotExtend, isLabelValid, validTimeFrame, levelStart, pivotLabelXOffset)
draw a pivot line - the line starts one day into the past
Parameters:
pivotLevel : series of the pivot point
res : the desired resolution
tag : the text to appear
pivotColor : the color of the line
pivotLabelColor : the color of the label
pivotStyle : the line style
pivotWidth : the line width
pivotExtend : extend the line
isLabelValid : boolean param allows to turn label on and off
validTimeFrame : only draw the line and label at a valid timeframe
levelStart : basically when to start drawing the levels
pivotLabelXOffset : how much to offset the label from its current postion
@return the pivot line series
getPvsraFlagByColor(pvsraColor, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor, lightGrayCandleColor)
convert the pvsra color to an internal code
Parameters:
pvsraColor : the calculated pvsra color
redVectorColor : the user defined red vector color
greenVectorColor : the user defined green vector color
violetVectorColor : the user defined violet vector color
blueVectorColor : the user defined blue vector color
lightGrayCandleColor : the user defined regular up candle color
@return pvsra internal code
updateZones(pvsra, direction, boxArr, maxlevels, pvsraHigh, pvsraLow, pvsraOpen, pvsraClose, transperancy, zoneupdatetype, zonecolor, zonetype, borderwidth, coloroverride, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor, lightGrayCandleColor)
a function that draws the unrecovered vector candle zones
Parameters:
pvsra : internal code
direction : above or below the current pa
boxArr : the array containing the boxes that need to be updated
maxlevels : the maximum number of boxes to draw
pvsraHigh : the pvsra high value series
pvsraLow : the pvsra low value series
pvsraOpen : the pvsra open value series
pvsraClose : the pvsra close value series
transperancy : the transparencfy of the vecor candle zones
zoneupdatetype : the zone update type
zonecolor : the zone color if overriden
zonetype : the zone type
borderwidth : the width of the border
coloroverride : if the color overriden
redVectorColor : the user defined red vector color
greenVectorColor : the user defined green vector color
violetVectorColor : the user defined violet vector color
blueVectorColor : the user defined blue vector color
lightGrayCandleColor : the user defined regular up candle color
cleanarr(arr)
clean an array from na values
Parameters:
arr : the array to clean
@return if the array was cleaned
calcPsyLevels(oneWeekMillis, showPsylevels, psyType, sydDST)
calculate the psy levels
4 hour res based on how mt4 does it
mt4 code
int Li_4 = iBarShift(NULL, PERIOD_H4, iTime(NULL, PERIOD_W1, Li_0)) - 2 - Offset;
ObjectCreate("PsychHi", OBJ_TREND, 0, Time , iHigh(NULL, PERIOD_H4, iHighest(NULL, PERIOD_H4, MODE_HIGH, 2, Li_4)), iTime(NULL, PERIOD_W1, 0), iHigh(NULL, PERIOD_H4,
iHighest(NULL, PERIOD_H4, MODE_HIGH, 2, Li_4)));
so basically because the session is 8 hours and we are looking at a 4 hour resolution we only need to take the highest high an lowest low of 2 bars
we use the gmt offset to adjust the 0000-0800 session to Sydney open which is at 2100 during dst and at 2200 otherwize. (dst - spring foward, fall back)
keep in mind sydney is in the souther hemisphere so dst is oposite of when london and new york go into dst
Parameters:
oneWeekMillis : a constant value
showPsylevels : should psy levels be calculated
psyType : the type of Psylevels - crypto or forex
sydDST : is Sydney in DST
@return
RS_TD_Library_2Library "RS_TD_Library_2"
TradingView Library for showing option prices on the chart
Here is a simple way to draw options to an underlying asset on the chart. At the top right there is a table with the summary of the corresponding premiums. A tooltip shows the corresponding buy/sell prices for each option.
showTable(sumShortPut, sumLongPut, sumShortCall, sumLongCall, sumTotal, smallLayout)
Shows the table of profit/loss of all options to the given underlying
Parameters:
sumShortPut : Sum of all short put options
sumLongPut : Sum of all long put options
sumShortCall : Sum of all short call options
sumLongCall : Sum of all long call options
sumTotal : Sum of all kind of options
smallLayout : Usage of a small table layout
debugging_labelOnEachBar(_text)
Shows a debugging label on each bar
Parameters:
_text : Text to show on the label
showLine(date1, date2, strike, color)
Prints a line at the strike of the option
Parameters:
date1 : Buying date of the option
date2 : Selling date of the option
strike : Strike of the option
color : Color of the line
showLabel(date, strike, color, tooltip)
Prints a label at the strike of the option
Parameters:
date : Buying/Selling date of the option
strike : Strike of the option
color : Color of the line
tooltip : ToolTip of the option with the detailed prices
LibIndicadoresUteisLibrary "LibIndicadoresUteis"
Collection of useful indicators. This collection does not do any type of plotting on the graph, as the methods implemented can and should be used to get the return of mathematical formulas, in a way that speeds up the development of new scripts. The current version contains methods for stochastic return, slow stochastic, IFR, leverage calculation for B3 futures market, leverage calculation for B3 stock market, bollinger bands and the range of change.
estocastico(PeriodoEstocastico)
Returns the value of stochastic
Parameters:
PeriodoEstocastico : Period for calculation basis
Returns: Float with the stochastic value of the period
estocasticoLento(PeriodoEstocastico, PeriodoMedia)
Returns the value of slow stochastic
Parameters:
PeriodoEstocastico : Stochastic period for calculation basis
PeriodoMedia : Average period for calculation basis
Returns: Float with the value of the slow stochastic of the period
ifrInvenenado(PeriodoIFR, OrigemIFR)
Returns the value of the RSI/IFR Poisoned of Guima
Parameters:
PeriodoIFR : RSI/IFR period for calculation basis
OrigemIFR : Source of RSI/IFR for calculation basis
Returns: Float with the RSI/IFR value for the period
calculoAlavancagemFuturos(margem, alavancagemMaxima)
Returns the number of contracts to work based on margin
Parameters:
margem : Margin for contract unit
alavancagemMaxima : Maximum number of contracts to work
Returns: Integer with the number of contracts suggested for trading
calculoAlavancagemAcoes(alavancagemMaxima)
Returns the number of batches to work based on the margin
Parameters:
alavancagemMaxima : Maximum number of batches to work
Returns: Integer with the amount of lots suggested for trading
bandasBollinger(periodoBB, origemBB, desvioPadrao)
Returns the value of bollinger bands
Parameters:
periodoBB : Period of bollinger bands for calculation basis
origemBB : Origin of bollinger bands for calculation basis
desvioPadrao : Standard Deviation of bollinger bands for calculation basis
Returns: Two-position array with upper and lower band values respectively
theRoc(periodoROC, origemROC)
Returns the value of Rate Of Change
Parameters:
periodoROC : Period for calculation basis
origemROC : Source of calculation basis
Returns: Float with the value of Rate Of Change
KernelFunctionsLibrary "KernelFunctions"
This library provides non-repainting kernel functions for Nadaraya-Watson estimator implementations. This allows for easy substitution/comparison of different kernel functions for one another in indicators. Furthermore, kernels can easily be combined with other kernels to create newer, more customized kernels. Compared to Moving Averages (which are really just simple kernels themselves), these kernel functions are more adaptive and afford the user an unprecedented degree of customization and flexibility.
rationalQuadratic(_src, _lookback, _relativeWeight, _startAtBar)
Rational Quadratic Kernel - An infinite sum of Gaussian Kernels of different length scales.
Parameters:
_src : The source series.
_lookback : The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
_relativeWeight : Relative weighting of time frames. Smaller values result in a more stretched-out curve, and larger values will result in a more wiggly curve. As this value approaches zero, the longer time frames will exert more influence on the estimation. As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel.
_startAtBar : Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
Returns: yhat The estimated values according to the Rational Quadratic Kernel.
gaussian(_src, _lookback, _startAtBar)
Gaussian Kernel - A weighted average of the source series. The weights are determined by the Radial Basis Function (RBF).
Parameters:
_src : The source series.
_lookback : The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
_startAtBar : Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
Returns: yhat The estimated values according to the Gaussian Kernel.
periodic(_src, _lookback, _period, _startAtBar)
Periodic Kernel - The periodic kernel (derived by David Mackay) allows one to model functions that repeat themselves exactly.
Parameters:
_src : The source series.
_lookback : The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
_period : The distance between repititions of the function.
_startAtBar : Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
Returns: yhat The estimated values according to the Periodic Kernel.
locallyPeriodic(_src, _lookback, _period, _startAtBar)
Locally Periodic Kernel - The locally periodic kernel is a periodic function that slowly varies with time. It is the product of the Periodic Kernel and the Gaussian Kernel.
Parameters:
_src : The source series.
_lookback : The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
_period : The distance between repititions of the function.
_startAtBar : Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
Returns: yhat The estimated values according to the Locally Periodic Kernel.
inChart - LibLibrary "inChart"
determine if price value is between chart high + x% and low - x% on the visible chart.
inChart()
taLibrary "ta"
This library is a Pine Script™ programmer’s tool containing calcs for my oscillators and some helper functions.
buoyancy(src, targetPeriod, maxLookback)
Calculates buoyancy using a target of `src` summed over `targetPeriod` bars, not searching back farther than `maxLookback` bars. See:
Parameters:
src : (series float) The source value that is summed to constitute the target.
targetPeriod : (series int) The qty of bars to sum `src` for in order to calculate the target.
maxLookback : (simple int) The maximum number of bars back the function will search.
Returns: (series float) Buoyancy: the gap between the avg distance of past up and dn bars added to reach the target, divided by the max distance reached. Returns zero when an error condition occurs.
efficientWork(length)
Calculates Efficient Work on `length` bars. See:
Parameters:
length : (simple int) The length of the ALMA used to calculate the result.
Returns: (series float) A -1 to +1 value representing the efficiency of price travel, bar to bar.
ma(type, src, length)
Returns the `type` MA of the `src` over the `length`.
Parameters:
type : (simple string) The type of MA required (uses constants that must be defined earlier in the script).
src : (series float) The source value used to calculate the MA.
length : (simple int) The length value used to calculate the MA.
Returns: (series float) The MA value.
divergenceChannel(divergence, hiSrc, loSrc, breachHiSrc, breachLoSrc)
Calculates the levels and states of divergence channels, which are created when divergences occur.
Parameters:
divergence : (series bool) `true` on divergences, which can be defined any way. On breached channels it creates a new channel, otherwise, channel levels are expanded.
hiSrc : (series float) The price source used to set the channel's hi level when a divergence occurs.
loSrc : (series float) The price source used to set the channel's lo level when a divergence occurs.
breachHiSrc : (series float) The price source that must breach over the channel's `channelHi` level for a breach to occur.
breachLoSrc : (series float) The price source that must breach under the channel's `channelLo` level for a breach to occur.
Returns: A tuple containing the following values:
sourceStrToFloat(srcString)
Converts the name of a source in the `srcString` to its numerical equivalent.
Parameters:
srcString : (series string) The string representing the name of the source value to be returned.
Returns: (series float) The source's value.
TR_Base_LibLibrary "TR_Base_Lib"
TODO: add library description here
SetHighLowArray()
ChangeHighLowArray()
ShowLabel(_Text, _X, _Y, _Style, _Size, _Yloc, _Color)
TODO: Function to display labels
Parameters:
_Text : TODO: text (series string) Label text.
_X : TODO: x (series int) Bar index.
_Y : TODO: y (series int/float) Price of the label position.
_Style : TODO: style (series string) Label style.
_Size : TODO: size (series string) Label size.
_Yloc : TODO: yloc (series string) Possible values are yloc.price, yloc.abovebar, yloc.belowbar.
_Color : TODO: color (series color) Color of the label border and arrow
Returns: TODO: No return values
GetColor(_Index)
TODO: Function to take out 12 colors in order
Parameters:
_Index : TODO: color number.
Returns: TODO: color code
Tbl_position(_Pos)
TODO: Table display position function
Parameters:
_Pos : TODO: position.
Returns: TODO: Table position
Tbl_position_JP(_Pos)
TODO: テーブル表示位置 日本語表示位置を定数に変換
Parameters:
_Pos : TODO: 日本語表示位置
Returns: TODO: _result:表示位置の定数を返す
TfInMinutes(_Tf)
TODO: 足変換、TimeFrameを分に変換
Parameters:
_Tf : TODO: TimeFrame文字
Returns: TODO: _result:TimeFrameを分に変換した値、_chartTf:チャートのTimeFrameを分に変換した値
TfName_JP(_tf)
TODO: TimeFrameを日本語足名に変換して返す関数 引数がブランクの時はチャートの日本語足名を返す
Parameters:
_tf : TODO: TimeFrame文字
Returns: TODO: _result:日本語足名
DeleteLine()
TODO: Delete Line
Parameters:
: TODO: No parameter
Returns: TODO: No return value
DeleteLabel()
TODO: Delete Label
Parameters:
: TODO: No parameter
Returns: TODO: No return value
SupportResitanceAndTrendLibrary "SupportResitanceAndTrend"
Contains utilities for finding key levels of support, resistance and direction of trend.
superTrendPlus(multiple, h, l, atr, closeBars)
A more flexible version of SuperTrend that allows for supplying the series used and sensitivity adjustment by confirming close bars.
Parameters:
multiple : The multiple to apply to the average true range.
h : The high values.
l : The low values.
atr : The average true range values.
closeBars : The number of bars to confirm a change in trend.
Returns:
superTrend(multiple, period, mode, closeBars)
superTrendPlus with simplified parameters.
Parameters:
multiple : The multiple to apply to the average true range.
period : The number of bars to measure.
mode : The type of moving average to use with the true range.
closeBars : The number of bars to confirm a change in trend.
Returns:
superTrendCleaned(multiple, period, mode, closeBars, maxDeviation)
superTrendPlus with default compensation for extreme volatility.
Parameters:
multiple : The multiple to apply to the average true range.
period : The number of bars to measure.
mode : The type of moving average to use with the true range.
closeBars : The number of bars to confirm a change in trend.
maxDeviation : The optional standard deviation level to use when cleaning the series. The default is the value of the provided level.
Returns:
stochSR()
Identifies support and resistance levels by when a stochastic RSI reverses.
Returns:
stochAVWAP()
Identifies anchored VWAP levels by when a stochastic RSI reverses.
Returns:
MovingAveragesLibrary "MovingAverages"
vawma(len, src, volumeDefault)
VAWMA = VWMA and WMA combined. Simply put, this attempts to determine the average price per share over time weighted heavier for recent values. Uses a triangular algorithm to taper off values in the past (same as WMA does).
Parameters:
len : The number of bars to measure with.
src : The series to measure from. Default is 'hlc3'.
volumeDefault : The default value to use when a chart has no (N/A) volume.
Returns: The volume adjusted triangular weighted moving average of the series.
cma(n, D, C, compound)
Coefficient Moving Avereage (CMA) is a variation of a moving average that can simulate SMA or WMA with the advantage of previous data.
Parameters:
n : The number of bars to measure with.
D : The series to measure from. Default is 'close'.
C : The coefficient to use when averaging. 0 behaves like SMA, 1 behaves like WMA.
compound : When true (default is false) will use a compounding method for weighting the average.
ema(len, src)
Same as ta.ema(src,len) but properly ignores NA values.
Parameters:
len : The number of samples to derive the average from.
src : The series to measure from. Default is 'close'.
wma(len, src, startingWeight)
Same as ta.wma(src,len) but properly ignores NA values.
Parameters:
len : The number of samples to derive the average from.
src : The series to measure from. Default is 'close'.
startingWeight : The weight to begin with when calculating the average. Higher numbers will decrease the bias.
vwma(len, src, volumeDefault)
Same as ta.vwma(src,len) but properly ignores NA values.
Parameters:
len : The number of bars to measure with.
src : The series to measure from. Default is 'hlc3'.
volumeDefault : The default value to use when a chart has no (N/A) volume.
get(type, len, src)
Generates a moving average based upon a 'type'.
Parameters:
type : The type of moving average to generate. Values allowed are: SMA, EMA, WMA, VWMA and VAWMA.
len : The number of bars to measure with.
src : The series to measure from. Default is 'close'.
Returns: The moving average series requested.
DataCleanerLibrary "DataCleaner"
outlierLevel(src, len, level)
Gets the (standard deviation) outlier level for a given series.
Parameters:
src : The series to average and add a multiple of the standard deviation to.
len : The The number of bars to measure.
level : The positive or negative multiple of the standard deviation to apply to the average. A positive number will be the upper boundary and a negative number will be the lower boundary.
Returns: The average of the series plus the multiple of the standard deviation.
naOutliers(src, len, maxDeviation)
Returns only values that are within the maximum deviation.
Parameters:
src : The series to filter results from.
len : The The number of bars to measure.
maxDeviation : The maximum deviation before considered an outlier.
normalize(src, len, maxDeviation, baseline)
Returns the source value adjusted by its standard deviation.
Parameters:
src : The series to measure.
len : The number of bars to measure the standard deviation.
maxDeviation : The maximum deviation before considered an outlier.
baseline : The value considered to be at center. Typically zero.
cleanUsing(src, result, len, maxDeviation)
Returns an array representing the result series with (outliers provided by the source) removed.
Parameters:
src : The source series to read from.
result : The result series.
len : The maximum size of the resultant array.
maxDeviation : The positive or negative multiple of the standard deviation to apply to the average. A positive number will be the upper boundary and a negative number will be the lower boundary.
Returns: An array containing the cleaned series.
clean(src, len, maxDeviation)
Returns an array representing the source series with outliers removed.
Parameters:
src : The source series to read from.
len : The maximum size of the resultant array.
maxDeviation : The positive or negative multiple of the standard deviation to apply to the average. A positive number will be the upper boundary and a negative number will be the lower boundary.
Returns: An array containing the cleaned series.
cleanArray(src, maxDeviation)
Returns an array representing the source array with outliers removed.
Parameters:
src : The source series to read from.
maxDeviation : The positive or negative multiple of the standard deviation to apply to the average. A positive number will be the upper boundary and a negative number will be the lower boundary.
Returns: An array containing the cleaned series.
naArrayOutliers(src, maxDeviation)
Returns an array representing the source array with outliers removed.
Parameters:
src : The array to set outliers to N/A.
maxDeviation : The maximum deviation before considered an outlier.
Returns: True if there were any outliers; otherwise false.
outlierLevelAdjusted(src, len, level, maxDeviation)
Gets the (standard deviation) outlier level for a given series after a single pass of removing any outliers.
Parameters:
src : The series to average and add a multiple of the standard deviation to.
len : The The number of bars to measure.
level : The positive or negative multiple of the standard deviation to apply to the average. A positive number will be the upper boundary and a negative number will be the lower boundary.
maxDeviation : The optional standard deviation level to use when cleaning the series. The default is the value of the provided level.
Returns: The average of the series plus the multiple of the standard deviation.
obvFilterThis library comes with everything you need to add an On Balance Volume (OBV) filter to your strategy.
getOnBalanceVolumeFilter(source, maType, fastMaLength, fastMaLength)
Get the fast and slow moving average for on balance volume
Parameters:
source : hook this up to an 'input.source' input
maType : Choose from EMA, SMA, RMA, or WMA
fastMaLength : int smoothing length for fast moving average
fastMaLength : int smoothing length for fast moving average int smoothing length for slow moving average
Returns: Tuple with fast obv moving average and slow obv moving average
Add this to your strategy
▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾ ▾
import jordanfray/obvFilter/1 as obv
obvSource = input.source(defval=close, title="OBV Source", group="On Balance Volume Filter")
obvMaType = input.string(defval="EMA", title="OBV Smoothing Type", options = , group="On Balance Volume Filter")
fastMaLength = input.int(title = "Fast OBV MA Length", defval = 9, minval = 2, maxval = 200, group="On Balance Volume Filter")
slowMaLength = input.int(title = "Slow OBV MA Length", defval = 21, minval = 1, maxval = 200, group="On Balance Volume Filter")
= obv.getOnBalanceVolumeFilter(obvSource, obvMaType, fastMaLength, slowMaLength)
Moving Averages ProxyLibrary "MovingAveragesProxy"
Moving Averages Proxy - Library of all moving averages spread out in different libraries
rvwap(_src, fixedTfInput, minsInput, hoursInput, daysInput, minBarsInput)
Calculates the Rolling VWAP (customized VWAP developed by the team of TradingView)
Parameters:
_src : (float) Source. Default: close
fixedTfInput : (bool) Use a fixed time period. Default: false
minsInput : (int) Minutes. Default: 0
hoursInput : (int) Hours. Default: 0
daysInput : (int) Days. Default: 1
minBarsInput : (int) Bars. Default: 10
Returns: (float) Rolling VWAP
correlationMa(src, len, factor)
Correlation Moving Average
Parameters:
src : (float) Source. Default: close
len : (int) Length
factor : (float) Factor. Default: 1.7
Returns: (float) Correlation Moving Average
regma(src, len, lambda)
Regularized Exponential Moving Average
Parameters:
src : (float) Source. Default: close
len : (int) Length
lambda : (float) Lambda. Default: 0.5
Returns: (float) Regularized Exponential Moving Average
repma(src, len)
Repulsion Moving Average
Parameters:
src : (float) Source. Default: close
len : (int) Length
Returns: (float) Repulsion Moving Average
epma(src, length, offset)
End Point Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
offset : (float) Offset. Default: 4
Returns: (float) End Point Moving Average
lc_lsma(src, length)
1LC-LSMA (1 line code lsma with 3 functions)
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) 1LC-LSMA Moving Average
aarma(src, length)
Adaptive Autonomous Recursive Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Adaptive Autonomous Recursive Moving Average
alsma(src, length)
Adaptive Least Squares
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Adaptive Least Squares
ahma(src, length)
Ahrens Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Ahrens Moving Average
adema(src)
Ahrens Moving Average
Parameters:
src : (float) Source. Default: close
Returns: (float) Moving Average
autol(src, lenDev)
Auto-Line
Parameters:
src : (float) Source. Default: close
lenDev : (int) Length for standard deviation
Returns: (float) Auto-Line
fibowma(src, length)
Fibonacci Weighted Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Moving Average
fisherlsma(src, length)
Fisher Least Squares Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Moving Average
leoma(src, length)
Leo Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Moving Average
linwma(src, period, weight)
Linear Weighted Moving Average
Parameters:
src : (float) Source. Default: close
period : (int) Length
weight : (int) Weight
Returns: (float) Moving Average
mcma(src, length)
McNicholl Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Moving Average
srwma(src, length)
Square Root Weighted Moving Average
Parameters:
src : (float) Source. Default: close
length : (int) Length
Returns: (float) Moving Average
EDSMA(src, len)
Ehlers Dynamic Smoothed Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: EDSMA smoothing.
dema(x, t)
Double Exponential Moving Average.
Parameters:
x : Series to use ('close' is used if no argument is supplied).
t : Lookback length to use.
Returns: DEMA smoothing.
tema(src, len)
Triple Exponential Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: TEMA smoothing.
smma(src, len)
Smoothed Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: SMMA smoothing.
hullma(src, len)
Hull Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: Hull smoothing.
frama(x, t)
Fractal Reactive Moving Average.
Parameters:
x : Series to use ('close' is used if no argument is supplied).
t : Lookback length to use.
Returns: FRAMA smoothing.
kama(x, t)
Kaufman's Adaptive Moving Average.
Parameters:
x : Series to use ('close' is used if no argument is supplied).
t : Lookback length to use.
Returns: KAMA smoothing.
vama(src, len)
Volatility Adjusted Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: VAMA smoothing.
donchian(len)
Donchian Calculation.
Parameters:
len : Lookback length to use.
Returns: Average of the highest price and the lowest price for the specified look-back period.
Jurik(src, len)
Jurik Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: JMA smoothing.
xema(src, len)
Optimized Exponential Moving Average.
Parameters:
src : Series to use ('close' is used if no argument is supplied).
len : Lookback length to use.
Returns: XEMA smoothing.
ehma(src, len)
EHMA - Exponential Hull Moving Average
Parameters:
src : Source
len : Period
Returns: Exponential Hull Moving Average (EHMA)
covwema(src, len)
Coefficient of Variation Weighted Exponential Moving Average (COVWEMA)
Parameters:
src : Source
len : Period
Returns: Coefficient of Variation Weighted Exponential Moving Average (COVWEMA)
covwma(src, len)
Coefficient of Variation Weighted Moving Average (COVWMA)
Parameters:
src : Source
len : Period
Returns: Coefficient of Variation Weighted Moving Average (COVWMA)
eframa(src, len, FC, SC)
Ehlrs Modified Fractal Adaptive Moving Average (EFRAMA)
Parameters:
src : Source
len : Period
FC : Lower Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
SC : Upper Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
Returns: Ehlrs Modified Fractal Adaptive Moving Average (EFRAMA)
etma(src, len)
Exponential Triangular Moving Average (ETMA)
Parameters:
src : Source
len : Period
Returns: Exponential Triangular Moving Average (ETMA)
rma(src, len)
RMA - RSI Moving average
Parameters:
src : Source
len : Period
Returns: RSI Moving average (RMA)
thma(src, len)
THMA - Triple Hull Moving Average
Parameters:
src : Source
len : Period
Returns: Triple Hull Moving Average (THMA)
vidya(src, len)
Variable Index Dynamic Average (VIDYA)
Parameters:
src : Source
len : Period
Returns: Variable Index Dynamic Average (VIDYA)
zsma(src, len)
Zero-Lag Simple Moving Average (ZSMA)
Parameters:
src : Source
len : Period
Returns: Zero-Lag Simple Moving Average (ZSMA)
zema(src, len)
Zero-Lag Exponential Moving Average (ZEMA)
Parameters:
src : Source
len : Period
Returns: Zero-Lag Exponential Moving Average (ZEMA)
evwma(src, len)
EVWMA - Elastic Volume Weighted Moving Average
Parameters:
src : Source
len : Period
Returns: Elastic Volume Weighted Moving Average (EVWMA)
tt3(src, len, a1_t3)
Tillson T3
Parameters:
src : Source
len : Period
a1_t3 : Tillson T3 Volume Factor
Returns: Tillson T3
gma(src, len)
GMA - Geometric Moving Average
Parameters:
src : Source
len : Period
Returns: Geometric Moving Average (GMA)
wwma(src, len)
WWMA - Welles Wilder Moving Average
Parameters:
src : Source
len : Period
Returns: Welles Wilder Moving Average (WWMA)
cma(src, len)
Corrective Moving average (CMA)
Parameters:
src : Source
len : Period
Returns: Corrective Moving average (CMA)
edma(src, len)
Exponentially Deviating Moving Average (MZ EDMA)
Parameters:
src : Source
len : Period
Returns: Exponentially Deviating Moving Average (MZ EDMA)
rema(src, len)
Range EMA (REMA)
Parameters:
src : Source
len : Period
Returns: Range EMA (REMA)
sw_ma(src, len)
Sine-Weighted Moving Average (SW-MA)
Parameters:
src : Source
len : Period
Returns: Sine-Weighted Moving Average (SW-MA)
mama(src, len)
MAMA - MESA Adaptive Moving Average
Parameters:
src : Source
len : Period
Returns: MESA Adaptive Moving Average (MAMA)
fama(src, len)
FAMA - Following Adaptive Moving Average
Parameters:
src : Source
len : Period
Returns: Following Adaptive Moving Average (FAMA)
hkama(src, len)
HKAMA - Hilbert based Kaufman's Adaptive Moving Average
Parameters:
src : Source
len : Period
Returns: Hilbert based Kaufman's Adaptive Moving Average (HKAMA)
getMovingAverage(type, src, len, lsmaOffset, inputAlmaOffset, inputAlmaSigma, FC, SC, a1_t3, fixedTfInput, daysInput, hoursInput, minsInput, minBarsInput, lambda, volumeWeighted, gamma_aarma, smooth, linweight, volatility_lookback, jurik_phase, jurik_power)
Abstract proxy function that invokes the calculation of a moving average according to type
Parameters:
type : (string) Type of moving average
src : (float) Source of series (close, high, low, etc.)
len : (int) Period of loopback to calculate the average
lsmaOffset : (int) Offset for Least Squares MA
inputAlmaOffset : (float) Offset for ALMA
inputAlmaSigma : (float) Sigma for ALMA
FC : (int) Lower Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
SC : (int) Upper Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
a1_t3 : (float) Tillson T3 Volume Factor
fixedTfInput : (bool) Use a fixed time period in Rolling VWAP
daysInput : (int) Days in Rolling VWAP
hoursInput : (int) Hours in Rolling VWAP
minsInput : (int) Minutrs in Rolling VWAP
minBarsInput : (int) Bars in Rolling VWAP
lambda : (float) Regularization Constant in Regularized EMA
volumeWeighted : (bool) Apply volume weighted calculation in selected moving average
gamma_aarma : (float) Gamma for Adaptive Autonomous Recursive Moving Average
smooth : (float) Smooth for Adaptive Least Squares
linweight : (float) Weight for Volume Weighted Moving Average
volatility_lookback : (int) Loopback for Volatility Adjusted Moving Average
jurik_phase : (int) Phase for Jurik Moving Average
jurik_power : (int) Power for Jurik Moving Average
Returns: (float) Moving average
TALibrary "TA"
General technical analysis functions
div_bull(pS, iS, cp_length_after, cp_length_before, pivot_length, lookback, no_broken, pW, iW, hidW, regW)
Test for bullish divergence
Parameters:
pS : Price series (float)
iS : Indicator series (float)
cp_length_after : Bars after current (divergent) pivot low to be considered a valid pivot (optional int)
cp_length_before : Bars before current (divergent) pivot low to be considered a valid pivot (optional int)
pivot_length : Bars before and after prior pivot low to be considered valid pivot (optional int)
lookback : Bars back to search for prior pivot low (optional int)
no_broken : Flag to only consider divergence valid if the pivot-to-pivot trendline is unbroken (optional bool)
pW : Weight of change in price, used in degree of divergence calculation (optional float)
iW : Weight of change in indicator, used in degree of divergence calculation (optional float)
hidW : Weight of hidden divergence, used in degree of divergence calculation (optional float)
regW : Weight of regular divergence, used in degree of divergence calculation (optional float)
Returns:
flag = true if divergence exists (bool)
degree = degree (strength) of divergence (float)
type = 1 = regular, 2 = hidden (int)
lx1 = x coordinate 1 (int)
ly1 = y coordinate 1 (float)
lx2 = x coordinate 2 (int)
ly2 = y coordinate 2 (float)
div_bear(pS, iS, cp_length_after, cp_length_before, pivot_length, lookback, no_broken, pW, iW, hidW, regW)
Test for bearish divergence
Parameters:
pS : Price series (float)
iS : Indicator series (float)
cp_length_after : Bars after current (divergent) pivot high to be considered a valid pivot (optional int)
cp_length_before : Bars before current (divergent) pivot highto be considered a valid pivot (optional int)
pivot_length : Bars before and after prior pivot high to be considered valid pivot (optional int)
lookback : Bars back to search for prior pivot high (optional int)
no_broken : Flag to only consider divergence valid if the pivot-to-pivot trendline is unbroken (optional bool)
pW : Weight of change in price, used in degree of divergence calculation (optional float)
iW : Weight of change in indicator, used in degree of divergence calculation (optional float)
hidW : Weight of hidden divergence, used in degree of divergence calculation (optional float)
regW : Weight of regular divergence, used in degree of divergence calculation (optional float)
Returns:
flag = true if divergence exists (bool)
degree = degree (strength) of divergence (float)
type = 1 = regular, 2 = hidden (int)
lx1 = x coordinate 1 (int)
ly1 = y coordinate 1 (float)
lx2 = x coordinate 2 (int)
ly2 = y coordinate 2 (float)
KlintLibraryLibrary "KlintLibrary"
GetDecimals()
this is my library, for my own use
thanks for reading
Tosch Stacked EMAs (Fibonacci)Library "Tosch_Stacked_EMAs (Fibonacci)"
stacked()
Returns true if all EMAs are stacked, either way.
bullish()
Returns true if the EMAs are stacked bullish, false otherwise
emas()
Returns the EMA values for lengths 5, 8, 13, 21, 34, 55, 89
Chaikin Money Flow - LibraryLibrary "Chaikin Money Flow"
cmf()
Developed by Marc Chaikin, Chaikin Money Flow measures the amount of Money Flow Volume over a specific period.
Money Flow Volume forms the basis for the Accumulation Distribution Line. Instead of a cumulative total of
Money Flow Volume, Chaikin Money Flow simply sums Money Flow Volume for a specific look-back period, typically
20 or 21 days. The resulting indicator fluctuates above/below the zero line just like an oscillator. Chartists
weigh the balance of buying or selling pressure with the absolute level of Chaikin Money Flow. Chartists can
also look for crosses above or below the zero line to identify changes on money flow.
The Accumulation Distribution Line was developed by Marc Chaikin to measure the cumulative flow of money into and
out of an index or security. The Accumulation/Distribution Line can be compared to the OBV (On Balance Volume),
which adds or subtracts volume depending on the closing price. Marc Chaikin chose a different approach, instead
of relying on the closing price, he used CLV (Close Location Value).
Demand IndexLibrary "DemandIndex"
di()
The Demand Index is a complex technical indicator that uses price and volume to assess buying and selling pressure affecting a security.
James Sibbet established six rules for using Demand Index when the technical indicator was originally published. While traders may use variations of these rules, they serve as a great baseline for using the indicator in practice.
The six rules are as follows:
A divergence between the Demand Index and price is a bearish indication.
Prices often rally to new highs following an extreme peak in the Demand Index.
Higher prices with a low Demand Index often indicate a top in the market.
The Demand Index moving through the zero line suggests a change in trend.
The Demand Index remaining near the zero line indicates weak price movement that won’t last long.
A long-term divergence between the Demand Index and price predicts a major top or bottom.
Traders should use the Demand Index in conjunction with other technical indicators and chart patterns to maximize their odds of success.
L_Index_4khansoloLibrary "L_Index_4khansolo"
countrySelect()
colorPositron()
indexName()
indexRSI()
maRSI()
colorRSIfull()
rsiColor()
rsiFillColor()
rsiCompartments()
fiatIndexer()
colorMACD()
indexMACD()
colour()
BoxLine_LibLibrary "BoxLine_Lib"
personal Library for line and box built in functions
lineXY(x)
get x1,y1,x2,y2 in a tuple
Parameters:
x : TODO: line
Returns: tuple of x1,y1,x2,y2
line(x)
Create line with only the y1 value(when line == na) or all
when line != na set x1,y1,x2,y2 individually just 1 or all
- use just the line value to set the x2 to current bar or time will set to time
- will auto pick xloc.bar_index or xloc.bar_time if not used
Parameters:
x : (line line,int x1,float y1,int x2,float y2,
string xloc,string extend,color color,string style,int width)
Returns: Line
boxXY(x)
get left,top,right,bottom in a tuple
Parameters:
x : box
Returns: tuple of left,top,right,bottom
box(x)
Create line with only the top,bottom value(when line == na) or all
when box != na set left,top,right,bottom individually just 1 or all
- use just the box value to set the right to current bar or time will set to time
- if right is above a number that a bar_index wouldnt be
Parameters:
x : box box,int left,float top,int right,
float bottom,color border_color, int border_width,
string border_style,string extend,string xloc,
color bgcolor,string text,string text_size, color text_color,
string text_halign,string text_valign,string text_wrap)
Returns: TODO: Box
DegreeALineLibrary "DegreeALine"
TODO: add library description here
Degree(x1, y1, x2, y2)
TODO: add function description here
Parameters:
x1 : First X coordinate of a line, index of the bar where the line starts.
y1 : First Y coordinate of a line, price on the price scale.
x2 : Second X coordinate of a line, index of the bar where the line ends.
y2 : Second Y coordinate of a line, price on the price scale.
Returns: Degree Of Line
lib_hlmLibrary "lib_hlm"
Ichimoku trend line and plotting tools.
HLM(Period)
Optionless Ichimoku/Donchian trend line calculation.
Parameters:
Period : The period for the trend line calculation.
Returns: The midpoint of the highest high and the lowest low.
HLM_Offset(offset, currentIsZero, intoPast)
Standardized language for plotting offsets.
Parameters:
offset : The offset number to use.
currentIsZero : `true` for ichimoku counting. `false` for natural language
intoPast : `true` if projecting backwards. `false` if projecting forwards.
Returns: The offset adjusted by counting style and direction.
TK()
Calculates the Ichimoku Tenkan and Kijun lines.
Returns: {tenkan, kijun}
SenkouSpans(period_1, period_2, period_3)
Calculates the Ichimoku Senkou Span A and Senkou Span B values.
Parameters:
period_1 : default=9
period_2 : default=26
period_3 : default=52
Returns: {senkou_a, senkou_b}
Ichimoku_Cloud(period_1, period_2, period_3)
Calculate the Ichimoku cloud value and offsets.
Parameters:
period_1 : default=9
period_2 : default=26
period_3 : default=52
Returns: {senkou_a, senkou_b, cloud_offset}
Chikou_Span()
Gets the chikou span and offsets.
Returns: {chikou, chikou_offset}
Ichimoku(enabled)
Get the values for the full, default Ichimoku system, including plotting offsets. Common toggle for all values.
Parameters:
enabled : `true` will return plottable values. `false` will return only na's (turns off plotting).
Returns: {tenkan, kijun, senkou_a, senkou_b, cloud_offset, chikou, chikou_offset}
Ichimoku_Line_Colors()
Get a set of colors with a common transparency for Ichimoku.
Returns: {tenkan_color, kijun_color, senkou_a_color, senkou_b_color, chikou_color}
Ichimoku_Cloud_Color()
Determines the cloud color and applies transparency (Ichimoku).
Returns: the dominant lines color with applied transparency
Ichimoku_Colors()
Gets a full set of default ichimoku colors with cloud color based on the input senkou values.
Returns: {tenkan_color, kijun_color, senkou_a_color, senkou_b_color, chikou_color, cloud_color}