Library_All_In_One
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Wilson-IV

//@version=5

// @description: Contains several functions of Pinescript all in one Library. This reduce your coding. It will expands during time.
library(title = "Library_All_In_One", overlay = true)

//===============================================================================
//=== Functions - Indicators ===
//===============================================================================

// @function : fnRSI  -> Calculates the Relative Strength Index (RSI) 
// @param    : source -> close, open, high, etc...
// @param    : length -> RSI length
// @returns  : float  -> RSI

export fnRSI(series float source, simple int length) =>

    float up   = ta.rma(math.max(ta.change(source), 0), length)
    float down = ta.rma(-math.min(ta.change(source), 0), length)
    
    float RSI  = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

    RSI


// @function : fnTSI  -> Calculates the True Strength Index (TSI)
// @param    : source -> close, open, high, etc...
// @param    : length -> TSI length
// @returns  : float  -> TSI

export fnTSI(series float source, simple int length_Fast, simple int length_Slow) =>

    Momentum = source - source[1]
    
    TSI      = 100 * (ta.ema(ta.ema(Momentum, length_Fast), length_Slow)/ta.ema(ta.ema(math.abs(Momentum), length_Fast), length_Slow))
    
    TSI


//===============================================================================
//=== Functions - General ===
//===============================================================================

// @function : IsMidnight  -> Determines if it is midnight 0 O'clock
// @param    : timezone    -> Timezone
// @returns  : bool        -> True or False

export IsMidnight(simple string timezone) =>
    
    hour(time, timezone) == 0 and minute(time, timezone) == 0 ? true : false


// @function : Bullets -> Position of the bullets: above or below the chart
// @param    : source  -> Only low or high. Low if the position is below chart, high if the bullet is above the chart
// @returns  : float   -> position above or below the chart

export Bullets(series float source, simple float factor) =>
    
    float atr = ta.atr(30)
    
    float Position = source == high ? source + (atr * factor) : source - (atr * factor)



