PINE LIBRARY
KTUtils

Library "KTUtils"
Utility functions for technical analysis indicators, trend detection, and volatility confirmation.
MGz(close, length)
MGz
description Moving average smoother used for signal processing
Parameters:
close (float): float Price input (typically close)
length (int): int Length of smoothing period
Returns: float Smoothed value
atrConf(length)
atrConf
description Calculates Average True Range (ATR) for volatility confirmation
Parameters:
length (simple int): int Length for ATR calculation
Returns: float ATR value
f(input)
f
description Simple Moving Average with fixed length
Parameters:
input (float): float Input value
Returns: float Smoothed average
bcwSMA(s, l, m)
bcwSMA
description Custom smoothing function with weight multiplier
Parameters:
s (float): float Signal value
l (int): int Length of smoothing
m (int): int Weighting multiplier
Returns: float Smoothed output
MGxx(close, length)
MGxx
description Custom Weighted Moving Average (WMA) variant
Parameters:
close (float): float Price input
length (int): int Period length
Returns: float MGxx smoothed output
_PerChange(lengthTime)
_PerChange
description Measures percentage price change over a period and range deviation
Parameters:
lengthTime (int): int Period for change measurement
Returns: tuple<float,float,float> Measured change, high deviation, low deviation
dirmov(len)
dirmov
description Calculates directional movement components
Parameters:
len (simple int): int Lookback period
Returns: tuple<float,float> Plus and Minus DI values
adx(dilen, adxlen)
adx
description Calculates Average Directional Index (ADX)
Parameters:
dilen (simple int): int Length for DI calculation
adxlen (simple int): int Length for ADX smoothing
Returns: float ADX value
trChopAnalysis()
trChopAnalysis
description Identifies chop and trend phases based on True Range Bollinger Bands
Returns: tuple<float,bool,bool> TR SMA, chop state, trending state
wtiAnalysis(haclose, close, filterValue)
wtiAnalysis
description Wave Trend Indicator (WTI) with signal crossover logic
Parameters:
haclose (float): float Heikin-Ashi close
close (float): float Standard close
filterValue (simple int): int Smoothing length
Returns: tuple<float,float,bool,bool> WTI lines and direction states
basicTrend(hahigh, halow, close, open, filterValue)
basicTrend
description Determines trend direction based on HA high/low and close
Parameters:
hahigh (float): float Heikin-Ashi high
halow (float): float Heikin-Ashi low
close (float): float Standard close
open (float): float Standard open
filterValue (simple int): int Smoothing period
Returns: tuple<bool,bool> Uptrend, downtrend flags
metrics(close, filterValue)
metrics
description Common market metrics
Parameters:
close (float): float Price input
filterValue (int): int RSI smoothing length
Returns: tuple<float,float,float,float> VWMA, SMA10, RSI, smoothed RSI
piff(close, trend_change)
piff
description Price-Informed Forward Forecasting (PIFF) model for trend strength
Parameters:
close (float): float Price input
trend_change (float): float Change in trend
Returns: tuple<float,float,bool,bool,bool,bool> Percent change, flags for trend direction
getMACD()
getMACD
description Returns MACD, signal line, and histogram
Returns: tuple<float,float,float> MACD line, Signal line, Histogram
getStoch()
getStoch
description Returns K and D lines of Stochastic Oscillator
Returns: tuple<float,float> K and D lines
getKDJ()
getKDJ
description KDJ momentum oscillator
Returns: tuple<float,float,float,float> K, D, J, Average
getBBRatio()
getBBRatio
description Bollinger Band Ratio (BBR) and signal flags
Returns: tuple<float,float,float,float,bool,bool> Basis, Upper, Lower, BBR, BBR Up, BBR Down
getSupertrend()
getSupertrend
description Supertrend values and direction flags
Returns: tuple<float,int,bool,bool> Supertrend, Direction, Up, Down
Utility functions for technical analysis indicators, trend detection, and volatility confirmation.
MGz(close, length)
MGz
description Moving average smoother used for signal processing
Parameters:
close (float): float Price input (typically close)
length (int): int Length of smoothing period
Returns: float Smoothed value
atrConf(length)
atrConf
description Calculates Average True Range (ATR) for volatility confirmation
Parameters:
length (simple int): int Length for ATR calculation
Returns: float ATR value
f(input)
f
description Simple Moving Average with fixed length
Parameters:
input (float): float Input value
Returns: float Smoothed average
bcwSMA(s, l, m)
bcwSMA
description Custom smoothing function with weight multiplier
Parameters:
s (float): float Signal value
l (int): int Length of smoothing
m (int): int Weighting multiplier
Returns: float Smoothed output
MGxx(close, length)
MGxx
description Custom Weighted Moving Average (WMA) variant
Parameters:
close (float): float Price input
length (int): int Period length
Returns: float MGxx smoothed output
_PerChange(lengthTime)
_PerChange
description Measures percentage price change over a period and range deviation
Parameters:
lengthTime (int): int Period for change measurement
Returns: tuple<float,float,float> Measured change, high deviation, low deviation
dirmov(len)
dirmov
description Calculates directional movement components
Parameters:
len (simple int): int Lookback period
Returns: tuple<float,float> Plus and Minus DI values
adx(dilen, adxlen)
adx
description Calculates Average Directional Index (ADX)
Parameters:
dilen (simple int): int Length for DI calculation
adxlen (simple int): int Length for ADX smoothing
Returns: float ADX value
trChopAnalysis()
trChopAnalysis
description Identifies chop and trend phases based on True Range Bollinger Bands
Returns: tuple<float,bool,bool> TR SMA, chop state, trending state
wtiAnalysis(haclose, close, filterValue)
wtiAnalysis
description Wave Trend Indicator (WTI) with signal crossover logic
Parameters:
haclose (float): float Heikin-Ashi close
close (float): float Standard close
filterValue (simple int): int Smoothing length
Returns: tuple<float,float,bool,bool> WTI lines and direction states
basicTrend(hahigh, halow, close, open, filterValue)
basicTrend
description Determines trend direction based on HA high/low and close
Parameters:
hahigh (float): float Heikin-Ashi high
halow (float): float Heikin-Ashi low
close (float): float Standard close
open (float): float Standard open
filterValue (simple int): int Smoothing period
Returns: tuple<bool,bool> Uptrend, downtrend flags
metrics(close, filterValue)
metrics
description Common market metrics
Parameters:
close (float): float Price input
filterValue (int): int RSI smoothing length
Returns: tuple<float,float,float,float> VWMA, SMA10, RSI, smoothed RSI
piff(close, trend_change)
piff
description Price-Informed Forward Forecasting (PIFF) model for trend strength
Parameters:
close (float): float Price input
trend_change (float): float Change in trend
Returns: tuple<float,float,bool,bool,bool,bool> Percent change, flags for trend direction
getMACD()
getMACD
description Returns MACD, signal line, and histogram
Returns: tuple<float,float,float> MACD line, Signal line, Histogram
getStoch()
getStoch
description Returns K and D lines of Stochastic Oscillator
Returns: tuple<float,float> K and D lines
getKDJ()
getKDJ
description KDJ momentum oscillator
Returns: tuple<float,float,float,float> K, D, J, Average
getBBRatio()
getBBRatio
description Bollinger Band Ratio (BBR) and signal flags
Returns: tuple<float,float,float,float,bool,bool> Basis, Upper, Lower, BBR, BBR Up, BBR Down
getSupertrend()
getSupertrend
description Supertrend values and direction flags
Returns: tuple<float,int,bool,bool> Supertrend, Direction, Up, Down
Pine library
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 publications is governed by House Rules.
Eric Thies
Disclaimer
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.
Pine library
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 publications is governed by House Rules.
Eric Thies
Disclaimer
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.