ottlibLibrary "ottlib"
█ OVERVIEW
This library contains functions for the calculation of the OTT (Optimized Trend Tracker) and its variants, originally created by Anıl Özekşi (Anil_Ozeksi). Special thanks to him for the concept and to Kıvanç Özbilgiç (KivancOzbilgic) and dg_factor (dg_factor) for adapting them to Pine Script.
█ WHAT IS "OTT"
The OTT (Optimized Trend Tracker) is a highly customizable and very effective trend-following indicator that relies on moving averages and a trailing stop at its core. Moving averages help reduce noise by smoothing out sudden price movements in the markets, while trailing stops assist in detecting trend reversals with precision. Initially developed as a noise-free trailing stop, the current variants of OTT range from rapid trend reversal detection to long-term trend confirmation, thanks to its extensive customizability.
It's well-known variants are:
OTT (Optimized Trend Tracker).
TOTT (Twin OTT).
OTT Channels.
RISOTTO (RSI OTT).
SOTT (Stochastic OTT).
HOTT & LOTT (Highest & Lowest OTT)
ROTT (Relative OTT)
FT (Original name is Fırsatçı Trend in Turkish which translates to Opportunist Trend)
█ LIBRARY FEATURES
This library has been prepared in accordance with the style, coding, and annotation standards of Pine Script version 5. As a result, explanations and examples will appear when users hover over functions or enter function parameters in the editor.
█ USAGE
Usage of this library is very simple. Just import it to your script with the code below and use its functions.
import ismailcarlik/ottlib/1 as ottlib
█ FUNCTIONS
• f_vidya(source, length, cmoLength)
Short Definition: Chande's Variable Index Dynamic Average (VIDYA).
Details: This function computes Chande's Variable Index Dynamic Average (VIDYA), which serves as the original moving average for OTT. The 'length' parameter determines the number of bars used to calculate the average of the given source. Lower values result in less smoothing of prices, while higher values lead to greater smoothing. While primarily used internally in this library, it has been made available for users who wish to utilize it as a moving average or use in custom OTT implementations.
Parameters:
source (float) : (series float) Series of values to process.
length (simple int) : (simple int) Number of bars to lookback.
cmoLength (simple int) : (simple int) Number of bars to lookback for calculating CMO. Default value is `9`.
Returns: (float) Calculated average of `source` for `length` bars back.
Example:
vidyaValue = ottlib.f_vidya(source = close, length = 20)
plot(vidyaValue, color = color.blue)
• f_mostTrail(source, multiplier)
Short Definition: Calculates trailing stop value.
Details: This function calculates the trailing stop value for a given source and the percentage. The 'multiplier' parameter defines the percentage of the trailing stop. Lower values are beneficial for catching short-term reversals, while higher values aid in identifying long-term trends. Although only used once internally in this library, it has been made available for users who wish to utilize it as a traditional trailing stop or use in custom OTT implementations.
Parameters:
source (float) : (series int/float) Series of values to process.
multiplier (simple float) : (simple float) Percent of trailing stop.
Returns: (float) Calculated value of trailing stop.
Example:
emaValue = ta.ema(source = close, length = 14)
mostValue = ottlib.f_mostTrail(source = emaValue, multiplier = 2.0)
plot(mostValue, color = emaValue >= mostValue ? color.green : color.red)
• f_ottTrail(source, multiplier)
Short Definition: Calculates OTT-specific trailing stop value.
Details: This function calculates the trailing stop value for a given source in the manner used in OTT. Unlike a traditional trailing stop, this function modifies the traditional trailing stop value from two bars prior by adjusting it further with half the specified percentage. The 'multiplier' parameter defines the percentage of the trailing stop. Lower values are beneficial for catching short-term reversals, while higher values aid in identifying long-term trends. Although primarily used internally in this library, it has been made available for users who wish to utilize it as a trailing stop or use in custom OTT implementations.
Parameters:
source (float) : (series int/float) Series of values to process.
multiplier (simple float) : (simple float) Percent of trailing stop.
Returns: (float) Calculated value of OTT-specific trailing stop.
Example:
vidyaValue = ottlib.f_vidya(source = close, length = 20)
ottValue = ottlib.f_ottTrail(source = vidyaValue, multiplier = 1.5)
plot(ottValue, color = vidyaValue >= ottValue ? color.green : color.red)
• ott(source, length, multiplier)
Short Definition: Calculates OTT (Optimized Trend Tracker).
Details: The OTT consists of two lines. The first, known as the "Support Line", is the VIDYA of the given source. The second, called the "OTT Line", is the trailing stop based on the Support Line. The market is considered to be in an uptrend when the Support Line is above the OTT Line, and in a downtrend when it is below.
Parameters:
source (float) : (series float) Series of values to process. Default value is `close`.
length (simple int) : (simple int) Number of bars to lookback. Default value is `2`.
multiplier (simple float) : (simple float) Percent of trailing stop. Default value is `1.4`.
Returns: ( [ float, float ]) Tuple of `supportLine` and `ottLine`.
Example:
= ottlib.ott(source = close, length = 2, multiplier = 1.4)
longCondition = ta.crossover(supportLine, ottLine)
shortCondition = ta.crossunder(supportLine, ottLine)
• tott(source, length, multiplier, bandsMultiplier)
Short Definition: Calculates TOTT (Twin OTT).
Details: TOTT consists of three lines: the "Support Line," which is the VIDYA of the given source; the "Upper Line," a trailing stop of the Support Line adjusted with an added multiplier; and the "Lower Line," another trailing stop of the Support Line, adjusted with a reduced multiplier. The market is considered in an uptrend if the Support Line is above the Upper Line and in a downtrend if it is below the Lower Line.
Parameters:
source (float) : (series float) Series of values to process. Default value is `close`.
length (simple int) : (simple int) Number of bars to lookback. Default value is `40`.
multiplier (simple float) : (simple float) Percent of trailing stop. Default value is `0.6`.
bandsMultiplier (simple float) : Multiplier for bands. Default value is `0.0006`.
Returns: ( [ float, float, float ]) Tuple of `supportLine`, `upperLine` and `lowerLine`.
Example:
= ottlib.tott(source = close, length = 40, multiplier = 0.6, bandsMultiplier = 0.0006)
longCondition = ta.crossover(supportLine, upperLine)
shortCondition = ta.crossunder(supportLine, lowerLine)
• ott_channel(source, length, multiplier, ulMultiplier, llMultiplier)
Short Definition: Calculates OTT Channels.
Details: OTT Channels comprise nine lines. The central line, known as the "Mid Line," is the OTT of the given source's VIDYA. The remaining lines are positioned above and below the Mid Line, shifted by specified multipliers.
Parameters:
source (float) : (series float) Series of values to process. Default value is `close`
length (simple int) : (simple int) Number of bars to lookback. Default value is `2`
multiplier (simple float) : (simple float) Percent of trailing stop. Default value is `1.4`
ulMultiplier (simple float) : (simple float) Multiplier for upper line. Default value is `0.01`
llMultiplier (simple float) : (simple float) Multiplier for lower line. Default value is `0.01`
Returns: ( [ float, float, float, float, float, float, float, float, float ]) Tuple of `ul4`, `ul3`, `ul2`, `ul1`, `midLine`, `ll1`, `ll2`, `ll3`, `ll4`.
Example:
= ottlib.ott_channel(source = close, length = 2, multiplier = 1.4, ulMultiplier = 0.01, llMultiplier = 0.01)
• risotto(source, length, rsiLength, multiplier)
Short Definition: Calculates RISOTTO (RSI OTT).
Details: RISOTTO comprised of two lines: the "Support Line," which is the VIDYA of the given source's RSI value, calculated based on the length parameter, and the "RISOTTO Line," a trailing stop of the Support Line. The market is considered in an uptrend when the Support Line is above the RISOTTO Line, and in a downtrend if it is below.
Parameters:
source (float) : (series float) Series of values to process. Default value is `close`.
length (simple int) : (simple int) Number of bars to lookback. Default value is `50`.
rsiLength (simple int) : (simple int) Number of bars used for RSI calculation. Default value is `100`.
multiplier (simple float) : (simple float) Percent of trailing stop. Default value is `0.2`.
Returns: ( [ float, float ]) Tuple of `supportLine` and `risottoLine`.
Example:
= ottlib.risotto(source = close, length = 50, rsiLength = 100, multiplier = 0.2)
longCondition = ta.crossover(supportLine, risottoLine)
shortCondition = ta.crossunder(supportLine, risottoLine)
• sott(source, kLength, dLength, multiplier)
Short Definition: Calculates SOTT (Stochastic OTT).
Details: SOTT is comprised of two lines: the "Support Line," which is the VIDYA of the given source's Stochastic value, based on the %K and %D lengths, and the "SOTT Line," serving as the trailing stop of the Support Line. The market is considered in an uptrend when the Support Line is above the SOTT Line, and in a downtrend when it is below.
Parameters:
source (float) : (series float) Series of values to process. Default value is `close`.
kLength (simple int) : (simple int) Stochastic %K length. Default value is `500`.
dLength (simple int) : (simple int) Stochastic %D length. Default value is `200`.
multiplier (simple float) : (simple float) Percent of trailing stop. Default value is `0.5`.
Returns: ( [ float, float ]) Tuple of `supportLine` and `sottLine`.
Example:
= ottlib.sott(source = close, kLength = 500, dLength = 200, multiplier = 0.5)
longCondition = ta.crossover(supportLine, sottLine)
shortCondition = ta.crossunder(supportLine, sottLine)
• hottlott(length, multiplier)
Short Definition: Calculates HOTT & LOTT (Highest & Lowest OTT).
Details: HOTT & LOTT are composed of two lines: the "HOTT Line", which is the OTT of the highest price's VIDYA, and the "LOTT Line", the OTT of the lowest price's VIDYA. A high price surpassing the HOTT Line can be considered a long signal, while a low price dropping below the LOTT Line may indicate a short signal.
Parameters:
length (simple int) : (simple int) Number of bars to lookback. Default value is `20`.
multiplier (simple float) : (simple float) Percent of trailing stop. Default value is `0.6`.
Returns: ( [ float, float ]) Tuple of `hottLine` and `lottLine`.
Example:
= ottlib.hottlott(length = 20, multiplier = 0.6)
longCondition = ta.crossover(high, hottLine)
shortCondition = ta.crossunder(low, lottLine)
• rott(source, length, multiplier)
Short Definition: Calculates ROTT (Relative OTT).
Details: ROTT comprises two lines: the "Support Line", which is the VIDYA of the given source, and the "ROTT Line", the OTT of the Support Line's VIDYA. The market is considered in an uptrend if the Support Line is above the ROTT Line, and in a downtrend if it is below. ROTT is similar to OTT, but the key difference is that the ROTT Line is derived from the VIDYA of two bars of Support Line, not directly from it.
Parameters:
source (float) : (series float) Series of values to process. Default value is `close`.
length (simple int) : (simple int) Number of bars to lookback. Default value is `200`.
multiplier (simple float) : (simple float) Percent of trailing stop. Default value is `0.1`.
Returns: ( [ float, float ]) Tuple of `supportLine` and `rottLine`.
Example:
= ottlib.rott(source = close, length = 200, multiplier = 0.1)
isUpTrend = supportLine > rottLine
isDownTrend = supportLine < rottLine
• ft(source, length, majorMultiplier, minorMultiplier)
Short Definition: Calculates Fırsatçı Trend (Opportunist Trend).
Details: FT is comprised of two lines: the "Support Line", which is the VIDYA of the given source, and the "FT Line", a trailing stop of the Support Line calculated using both minor and major trend values. The market is considered in an uptrend when the Support Line is above the FT Line, and in a downtrend when it is below.
Parameters:
source (float) : (series float) Series of values to process. Default value is `close`.
length (simple int) : (simple int) Number of bars to lookback. Default value is `30`.
majorMultiplier (simple float) : (simple float) Percent of major trend. Default value is `3.6`.
minorMultiplier (simple float) : (simple float) Percent of minor trend. Default value is `1.8`.
Returns: ( [ float, float ]) Tuple of `supportLine` and `ftLine`.
Example:
= ottlib.ft(source = close, length = 30, majorMultiplier = 3.6, minorMultiplier = 1.8)
longCondition = ta.crossover(supportLine, ftLine)
shortCondition = ta.crossunder(supportLine, ftLine)
█ CUSTOM OTT CREATION
Users can create custom OTT implementations using f_ottTrail function in this library. The example code which uses EMA of 7 period as moving average and calculates OTT based of it is below.
Source Code:
//@version=5
indicator("Custom OTT", shorttitle = "COTT", overlay = true)
import ismailcarlik/ottlib/1 as ottlib
src = input.source(close, title = "Source")
length = input.int(7, title = "Length", minval = 1)
multiplier = input.float(2.0, title = "Multiplier", minval = 0.1)
support = ta.ema(source = src, length = length)
ott = ottlib.f_ottTrail(source = support, multiplier = multiplier)
pSupport = plot(support, title = "Moving Average Line (Support)", color = color.blue)
pOtt = plot(ott, title = "Custom OTT Line", color = color.orange)
fillColor = support >= ott ? color.new(color.green, 60) : color.new(color.red, 60)
fill(pSupport, pOtt, color = fillColor, title = "Direction")
Result:
█ DISCLAIMER
Trading is risky and most of the day traders lose money eventually. This library and its functions are only for educational purposes and should not be construed as financial advice. Past performances does not guarantee future results.
Lott
HIGH and LOW Optimized Trend Tracker HOTT LOTTAnıl Özekşi's latest development on his precious OTT - Optimized Trend Tracker:
In this version, there are two lines of OTT which are derived from HIGHEST price values (HOTT) and LOVEST price values (LOTT) which were originally sourced to CLOSE values on default OTT.
Another significant difference is there is no Support Line (Moving Average) in this version.
The area between HOTT and LOTT is FLAT ZONE which developer advises to do nothing.
Bars will be highlighted to Turquoise when candles close over HOTT, means an UPTREND SIGNAL
and to Fuchia when candles begin closing under LOTT line to indicate a DOWNTREND SIGNAL.
FLAT ZONE is highlighted also to have the maximum concentration on sideways market conditions.
There are three quantitative parameters in this indicator:
The first parameter in the OTT indicator set by the two parameters is the period/length.
OTT lines will be much sensitive to trend movements if it is smaller.
And vice versa, will be less sensitive when it is longer.
As the period increases it will become less sensitive to little trends and price actions.
In this way, your choice of period, will be closely related to which of the sort of trends you are interested in.
The OTT percent parameter in OTT is an optimization coefficient. Just like in the period
small values are better at capturing short term fluctuations, while large values
will be more suitable for long-term trends.
The final adjustable quantitative parameter is HIGHEST and LOWEST length which is the source of calculations.
Anıl Özekşi generally works on 1 minute charts so I personally advise traders to optimize parameters to have more accurate signals. Just concentrate on FLAT price zones and indicator will do the rest in trends.
Built in Moving Average type defaultly set as VAR but users can choose from 10 different Moving Average types like:
SMA : Simple Moving Average
EMA : Exponential Moving Average
DEMA : Double Exponential Moving Average
WMA : Weighted Moving Average
TMA : Triangular Moving Average
VAR : Variable Index Dynamic Moving Average a.k.a. VIDYA
WWMA : Welles Wilder's Moving Average
ZLEMA : Zero Lag Exponential Moving Average
TSF : True Strength Force
HULL : Hull Moving Average