HTV_Library
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HyperTV_BRotem

//@version=5
library("HTV_LibraryV2")

//	┌─── CANDLE STICK ANALYSIS ───┐ {

// @function 'up_bar' checks true for every candle that closed above open price.
// @returns custom Series Bool
export up_bar()=> 
     (open < close)

// @function 'last_up_bar' checks true for every last candle that closed above open price.
// @returns custom Series Bool
export last_up_bar() =>
     open[1] < close[1]

// @function 'down_bar' checks true for every candle that closed below open price.
// @returns custom Series Bool
export down_bar() =>
     open > close

// @function 'last_down_bar' checks true for every last candle that closed below open price.
// @returns custom Series Bool
export last_down_bar() =>
     open[1] > close[1]

// @function 'TBR_Up' checks true for every last confirmed 2 Bar Reversal.
// @returns custom Series Bool
export TBR_Up() =>
     open[1] > close[1] and low > low[1] and ta.crossover(close, high[1])

// @function 'TBR_Down' checks true for every last confirmed 2 Bar Reversal.
// @returns custom Series Bool
export TBR_Down() =>
     open[1] < close[1] and high < high[1] and ta.crossunder(close, low[1])   

// @function 'TCR_Up' checks true for every last confirmed 3 Candle Reversal.
// @returns custom Series Bool
export TCR_Up() =>
     open[2] > close[2] and close[1] > open[2] and ta.crossover(open, close[1])

// @function 'TCR_Down' checks true for every last confirmed 3 Candle Reversal.
// @returns custom Series Bool
export TCR_Down() =>
     open[2] < close[2] and close[1] < open[2] and ta.crossunder(open, close[1])
//   ●═══───► ∴ ◄───═══● }

//	┌─── FIBONACCI SEQUENCE ───┐ {

// @function 'f_fib' gives a fibonacci number based on rising numericial order starting from 0
// @returns custom Series Bool
export f_fib(int _nth) =>
     _nth == 00 ? 0 : 
     _nth == 01 ? 1 :
     _nth == 02 ? 1 :
     _nth == 03 ? 2 :
     _nth == 04 ? 3 :
     _nth == 05 ? 5 :
     _nth == 06 ? 8 :
     _nth == 07 ? 13 :
     _nth == 08 ? 21 :
     _nth == 09 ? 34 :
     _nth == 10 ? 55 :
     _nth == 11 ? 89 :
     _nth == 12 ? 144 :
     _nth == 13 ? 233 :
     _nth == 14 ? 377 :
     _nth == 15 ? 610 :
     _nth == 16 ? 987 :
     _nth == 17 ? 1597 :
     _nth == 18 ? 2584 :
     _nth == 19 ? 4181 :
     _nth == 20 ? 6765 :
     _nth == 21 ? 10946 :
     _nth == 22 ? 17711 :
     _nth == 23 ? 28657 :
     _nth == 24 ? 46368 :
     _nth == 25 ? 75025 :
     na

//   ●═══───► ∴ ◄───═══● }

//	┌─── CUSTOM COLOR.RGB ───┐ {

// @function uses color.rgb(r,g,b,t) function 
// @returns literal color
export WHITE() =>
     color.rgb(255,255,255,0)
export WHITE_25T() =>
     color.rgb(255,255,255,25)
export WHITE_50T() =>
     color.rgb(255,255,255,50)
export WHITE_90T() =>
     color.rgb(255,255,255,90)

// @function uses color.rgb(r,g,b,t) function 
// @returns literal color
export BLACK() =>
     color.rgb(0,0,0,0)
export BLACK_25T() =>
     color.rgb(0,0,0,25)
export BLACK_50T() =>
     color.rgb(0,0,0,50)
export BLACK_90T() =>
     color.rgb(0,0,0,90)

// @function uses color.rgb(r,g,b,t) function 
// @returns literal color
export RED() =>
     color.rgb(255,0,100)
export RED_25T() =>
     color.rgb(255,0,100,25)
export RED_50T() =>
     color.rgb(255,0,100,50)
export RED_90T() =>
     color.rgb(255,0,100,90)

// @function uses color.rgb(r,g,b,t) function 
// @returns literal color
export GREEN() =>
     color.rgb(0,185,150)
export GREEN_25T() =>
     color.rgb(0,185,150,25)
export GREEN_50T() =>
     color.rgb(0,185,150,50)
export GREEN_90T() =>
     color.rgb(0,185,150,90)

// @function uses color.rgb(r,g,b,t) function 
// @returns literal color
export BLUE() =>
     color.rgb(40,0,250,0)
export BLUE_25T() =>
     color.rgb(40,0,250,25)
export BLUE_50T() =>
     color.rgb(40,0,250,50)
export BLUE_90T() =>
     color.rgb(40,0,250,90)

// @function uses color.rgb(r,g,b,t) function 
// @returns literal color
export GREY() =>
     color.rgb(120,123,134,0)
export GREY_25T() =>
     color.rgb(120,123,134,25)
export GREY_50T() =>
     color.rgb(120,123,134,50)
export GREY_90T() =>
     color.rgb(120,123,134,90)

// @function uses color.rgb(r,g,b,t) function 
// @returns literal color
export NEON_YELLOW() =>
     color.rgb(255,255,0,0)
export NEON_YELLOW_25T() =>
     color.rgb(255,255,0,25)
export NEON_YELLOW_50T() =>
     color.rgb(255,255,0,50)
export NEON_YELLOW_90T() =>
     color.rgb(255,255,0,90)

// @function uses color.rgb(r,g,b,t) function 
// @returns literal color
export NEON_GREEN() =>
     color.rgb(0,255,100,0)
export NEON_GREEN_25T() =>
     color.rgb(0,255,100,25)
export NEON_GREEN_50T() =>
     color.rgb(0,255,100,50)
export NEON_GREEN_90T() =>
     color.rgb(0,255,100,90)

// @function uses color.rgb(r,g,b,t) function 
// @returns literal color
export NEON_PINK() =>
     color.rgb(255,0,255,0)
export NEON_PINK_25T() =>
     color.rgb(255,0,255,25)
export NEON_PINK_50T() =>
     color.rgb(255,0,255,50)
export NEON_PINK_90T() =>
     color.rgb(255,0,255,90)

// @function uses color.rgb(r,g,b,t) function 
// @returns literal color
export PURPLE() =>
     color.rgb(100,0,255,0)
export PURPLE_25T() =>
     color.rgb(100,0,235,50)
export PURPLE_50T() =>
     color.rgb(100,0,235,50)
export PURPLE_90T() =>
     color.rgb(100,0,235,90)
//    ●═══───► ∴ ◄───═══● }

//	┌─── MA TYPES ───┐ {

// @function Simple Moving Average Code
// @returns (Local Function)
export SMA(float source, int length) => 
    ta.sma(source, length)
// @function Exponential Moving Average Code
// @returns (Local Function)
export EMA(float source, int length) =>
    var _a0 = 2 / (length + 1)
    _sum = 0.0
    _sum := _a0 * source + (1 - _a0) * nz(_sum[1], source)
    _sum
// @function Weighted Moving Average Code
// @returns (Local Function)
export WMA(float source, int length) =>
    ta.wma(source, length)
// @function Volume Weighted Moving Average Code
// @returns (Local Function)
export VWMA(float source, int length) =>
    ta.vwma(source, length)
// @function Relative Moving Average Code
// @returns (Local Function)
export RMA(float source, int length) =>
    ta.rma(source, length)
// @function Hull Moving Average Code
// @returns (Local Function)
export HMA(float source, int length) =>
    ta.hma(source, length)
// @function Simple Triangular Moving Average Code
// @returns (Local Function)
export STMA(float source, int length) =>
    ta.sma(ta.sma(source, length), length)
// @function Exponential Triangular Moving Average Code
// @returns (Local Function)
export ETMA(float source, int length) =>
    ta.ema(ta.ema(source, length), length)

//    ●═══───► ∴ ◄───═══● }

plot(close)
