PINE LIBRARY

ottlib

Actualizado
Library "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.




█ 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:

imagen

• 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:

imagen

• 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:

imagen

• 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:

imagen

• 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:

imagen

• 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:

imagen

• 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:

imagen

• 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:

imagen

• 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:

imagen

• 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:

imagen

• 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:

imagen


█ 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:


Result:
imagen


█ 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.
Notas de prensa
v2


█ UPDATES

  • Fixed `f_vidya()` function for more robust initialization by incorporating a conditional check to set the initial value to the Simple Moving Average (SMA) when previous VIDYA value is not available, ensuring more accurate calculations from the start. This change effectively handles edge cases where the length is set to 1, aligning the function closer to the standard VIDYA methodology and enhancing overall reliability.
  • Fixed an error at `risotto()` function that that involves calculation of `supportLine`.



█ NEW FUNCTIONS

• totto(source, length, multiplier, bandsMultiplier)
  Short Definition: Calculates TOTTO (Another version of Twin OTT).
  Details: TOTTO 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. It's very much like TOTT but difference comes from calculation of VIDYA which uses half of the given length and other lines uses the OTT of the Support Line's VIDYA for 2 bar length.

  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 `35`.
    multiplier (simple float): (simple float) Percent of trailing stop. Default value is `0.5`.
    bandsMultiplier (simple float): Multiplier for bands. Default value is `0.0006`.

  Returns: ([[]float, float, float[]]) Tuple of `supportLine`, `upperLine` and `lowerLine`.

  Example:

imagen


█ SPECIAL THANKS

Thanks to dg_factor for his precious bug reports and suggestions.
anilozeksihottlottoptimizedtrendtrackerOTTrisottorottsotttechindicatortott

Biblioteca Pine

Siguiendo fielmente el espíritu TradingView, el autor ha publicado este código Pine como una biblioteca de código abierto, permitiendo que otros programadores de Pine en nuestra comunidad lo utilicen de nuevo. ¡Olé por el autor! Puede utilizar esta biblioteca de forma privada o en otras publicaciones de código abierto, pero tenga en cuenta que la reutilización de este código en una publicación se rige por las Normas internas.


También en:

Exención de responsabilidad