calculateKellyRatio(returns) Parameters: returns (array<float>): An array of floats representing the returns from bets. Returns: The calculated Kelly Ratio, which indicates the optimal bet size based on winning and losing probabilities.
calculateAdjustedKellyFraction(kellyRatio, riskTolerance, fedStance) Parameters: kellyRatio (float): The calculated Kelly Ratio. riskTolerance (float): A float representing the risk tolerance level. fedStance (string): A string indicating the Federal Reserve's stance ("dovish", "hawkish", or neutral). Returns: The adjusted Kelly Fraction, constrained within the bounds of [-1, 1].
calculateStdDev(returns) Parameters: returns (array<float>): An array of floats representing the returns. Returns: The standard deviation of the returns, or 0 if insufficient data.
calculateMaxDrawdown(returns) Parameters: returns (array<float>): An array of floats representing the returns. Returns: The maximum drawdown as a percentage.
calculateEV(avgWinReturn, winProb, avgLossReturn) Parameters: avgWinReturn (float): The average return from winning bets. winProb (float): The probability of winning a bet. avgLossReturn (float): The average return from losing bets. Returns: The calculated Expected Value of the bet.
calculateTailRatio(returns) Parameters: returns (array<float>): An array of floats representing the returns. Returns: The Tail Ratio, or na if the 5th percentile is zero to avoid division by zero.
calculateSharpeRatio(avgReturn, riskFreeRate, stdDev) Parameters: avgReturn (float): The average return of the investment. riskFreeRate (float): The risk-free rate of return. stdDev (float): The standard deviation of the investment's returns. Returns: The calculated Sharpe Ratio, or na if standard deviation is zero.
calculateDownsideDeviation(returns) Parameters: returns (array<float>): An array of floats representing the returns. Returns: The standard deviation of the downside returns, or 0 if no downside returns exist.
calculateSortinoRatio(avgReturn, downsideDeviation) Parameters: avgReturn (float): The average return of the investment. downsideDeviation (float): The standard deviation of the downside returns. Returns: The calculated Sortino Ratio, or na if downside deviation is zero.
calculateVaR(returns, confidenceLevel) Parameters: returns (array<float>): An array of floats representing the returns. confidenceLevel (float): A float representing the confidence level (e.g., 0.95 for 95% confidence). Returns: The Value at Risk at the specified confidence level.
calculateCVaR(returns, varValue) Parameters: returns (array<float>): An array of floats representing the returns. varValue (float): The Value at Risk threshold. Returns: The average Conditional Value at Risk, or na if no returns are below the threshold.
calculateExpectedPriceRange(currentPrice, ev, stdDev, confidenceLevel) Parameters: currentPrice (float): The current price of the asset. ev (float): The expected value (in percentage terms). stdDev (float): The standard deviation (in percentage terms). confidenceLevel (float): The confidence level for the price range (e.g., 1.96 for 95% confidence). Returns: A tuple containing the minimum and maximum expected prices.
calculateRollingStdDev(returns, window) Parameters: returns (array<float>): An array of floats representing the returns. window (int): An integer representing the rolling window size. Returns: An array of floats representing the rolling standard deviation of returns.
calculateRollingVariance(returns, window) Parameters: returns (array<float>): An array of floats representing the returns. window (int): An integer representing the rolling window size. Returns: An array of floats representing the rolling variance of returns.
calculateRollingMean(returns, window) Parameters: returns (array<float>): An array of floats representing the returns. window (int): An integer representing the rolling window size. Returns: An array of floats representing the rolling mean of returns.
calculateRollingCoefficientOfVariation(returns, window) Parameters: returns (array<float>): An array of floats representing the returns. window (int): An integer representing the rolling window size. Returns: An array of floats representing the rolling coefficient of variation of returns.
calculateRollingSumOfPercentReturns(returns, window) Parameters: returns (array<float>): An array of floats representing the returns. window (int): An integer representing the rolling window size. Returns: An array of floats representing the rolling sum of percent returns.
calculateRollingCumulativeProduct(returns, window) Parameters: returns (array<float>): An array of floats representing the returns. window (int): An integer representing the rolling window size. Returns: An array of floats representing the rolling cumulative product of returns.
calculateRollingCorrelation(priceReturns, volumeReturns, window) Parameters: priceReturns (array<float>): An array of floats representing the price returns. volumeReturns (array<float>): An array of floats representing the volume returns. window (int): An integer representing the rolling window size. Returns: An array of floats representing the rolling correlation.
calculateRollingPercentile(returns, window, percentile) Parameters: returns (array<float>): An array of floats representing the returns. window (int): An integer representing the rolling window size. percentile (int): An integer representing the desired percentile (0-100). Returns: An array of floats representing the rolling percentile of returns.
calculateRollingMaxMinPercentReturns(returns, window) Parameters: returns (array<float>): An array of floats representing the returns. window (int): An integer representing the rolling window size. Returns: A tuple containing two arrays: rolling max and rolling min percent returns.
calculateRollingPriceToVolumeRatio(price, volData, window) Parameters: price (array<float>): An array of floats representing the price data. volData (array<float>): An array of floats representing the volume data. window (int): An integer representing the rolling window size. Returns: An array of floats representing the rolling price-to-volume ratio.
determineMarketRegime(priceChanges) Parameters: priceChanges (array<float>): An array of floats representing the price changes. Returns: A string indicating the market regime ("Bull", "Bear", or "Neutral").
determineVolatilityRegime(price, window) Parameters: price (array<float>): An array of floats representing the price data. window (int): An integer representing the rolling window size. Returns: An array of floats representing the calculated volatility.
classifyVolatilityRegime(volatility) Parameters: volatility (array<float>): An array of floats representing the calculated volatility. Returns: A string indicating the volatility regime ("Low" or "High").
method percentPositive(thisArray) Returns the percentage of positive non-na values in this array. This method calculates the percentage of positive values in the provided array, ignoring NA values. Namespace types: array<float> Parameters: thisArray (array<float>)
_candleRange()
_PreviousCandleRange(barsback) Parameters: barsback (int): An integer representing how far back you want to get a range
_SmallBody(length) Parameters: length (simple int): Length of the slow EMA Returns: a series of bools, after checking if the candle body was less than body average.
_LongBody(length) Parameters: length (simple int)
bearWick() bearWick() function. Returns: a SERIES of FLOATS, checks if it's a blackBody(open > close), if it is, than check the difference between the high and open, else checks the difference between high and close.
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House rules.
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.