Library "QTA"
This is simple library for basic Quantitative Technical Analysis for retail investors. One example of it being used can be seen here (tradingview.com/script/eD2ris9K-Early-Test-Weekly-Seasonality-with-Dynamic-Kelly-Criterion/).

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

redCandle()

greenCandle()

_WhiteBody()

_BlackBody()

HighOpenDiff()

OpenLowDiff()

_isCloseAbovePreviousOpen(length)
  Parameters:
    length (int)

_isCloseBelowPrevious()

_isOpenGreaterThanPrevious()

_isOpenLessThanPrevious()

BodyHigh()

BodyLow()

_candleBody()

_BodyAvg(length)
  _BodyAvg function.
  Parameters:
    length (simple int): Required (recommended is 6).

_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.

bullWick()

barlength()

sumbarlength()

sumbull()

sumbear()

bull_vol()

bear_vol()

volumeFightMA()

volumeFightDelta()

weightedAVG_BullVolume()

weightedAVG_BearVolume()

VolumeFightDiff()

VolumeFightFlatFilter()

avg_bull_vol(userMA)
  avg_bull_vol(int) function.
  Parameters:
    userMA (int)

avg_bear_vol(userMA)
  avg_bear_vol(int) function.
  Parameters:
    userMA (int)

diff_vol(userMA)
  diff_vol(int) function.
  Parameters:
    userMA (int)

vol_flat(userMA)
  vol_flat(int) function.
  Parameters:
    userMA (int)

_isEngulfingBullish()

_isEngulfingBearish()

dojiup()

dojidown()

EveningStar()

MorningStar()

ShootingStar()

Hammer()

InvertedHammer()

BearishHarami()

BullishHarami()

BullishBelt()

BullishKicker()

BearishKicker()

HangingMan()

DarkCloudCover()
kelleyfinanceMATHstatisticstechindicator

Pineライブラリ

TradingViewの精神に則り、作者はPineコードをオープンソースライブラリとして公開し、コミュニティの他のPineプログラマーが再利用できるようにしました。作者に敬意を表します!このライブラリを個人的に、または他のオープンソースの投稿で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。

免責事項