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

//@version=5

// @description TODO: add library description here
library("Swiss_Pine_Libra")


// @function TODO: Creates an custom ADX, Di+, Di- so that a series may be used as Len 
// @param x TODO: iadx(len, smooth)  Len = Length(lookback)   Smoothing = DI Length
// @returns TODO: Returns [Diplus, Diminus, ADX]


export iadx(float len=21, float smooth=21) =>
    dmp = high-nz(high[1]) > nz(low[1])-low ? math.max(high-nz(high[1]), 0): 0
    dmm = nz(low[1])-low > high-nz(high[1]) ? math.max(nz(low[1])-low, 0): 0 
    str = 0.0 
    str := nz(str[1]) - (nz(str[1])/len) + ta.tr 
     
    sdmp = 0.0
    sdmp := nz(sdmp[1]) - (nz(sdmp[1])/len) + dmp 
     
    sdmm = 0.0 
    sdmm := nz(sdmm[1]) - (nz(sdmm[1])/len) + dmm 
     
    DIPlus = sdmp / str * 100 
    DIMinus = sdmm / str * 100 
    DX = math.abs(DIPlus-DIMinus) / (DIPlus+DIMinus)*100 
    ADX = ta.rma(DX, smooth) 
     
    [DIPlus, DIMinus, ADX]



// @function TODO: Used to find Min, Mid, Max values 
// @param x TODO: V1 = first value V2 = second value V3 = third value
// @returns TODO: MxP(Max) MnP(Min) MdP(Mid), and the 3 numbers rounded to an int(MxPP, MnPP, MdPP)


export compare(float v1,float v2,float v3) =>
    ahv = float(v1 > v2 ? v1 : v2)  // is v1 or 2 greater
    MxP = float(ahv > v3 ? ahv : v3)
    
    alv = float(v1 < v2 ? v1 : v2)  // is v1 or 2 lesser
    MnP = float(alv < v3 ? alv : v3)    // is alv result less then v3
    
    MdP = if MxP == v1                    //checks if MxP = v1 Value
        float(v2 > v3 ? v2 : v3)    //if true it checks if v2 is greater then v3 and returns the higher value
    else if MxP == v2                     // checks if MxP = v2 Value
        float(v1 > v3 ? v1 : v3)    //if true it checks if v1 is greater then v3 and returns the higher value
    else
        float(v1 > v2 ? v1 : v2)    // if both are false set MdP to greater of v1 or v2Value
    
    MnPP = int(math.round(MnP))
    MdPP = int(math.round(MdP))
    MxPP = int(math.round(MxP))
    
    [MxP, MdP, MnP, MxPP, MdPP, MnPP]
    
    
// @function TODO:custom function to get array averages and OHLC values
// @param x TODO: ID= the array you want to use for averaging
// @returns TODO: Returns a Tuple with [average, max, min]

export abc(float[] id) =>
    avg = array.avg(id)
    oPen = open > close[1] ? open + avg : close[1] + avg
    hIgh = high < high[1] ? low[1] + avg : high
    lOw = low > low[1] ? high[1] + avg : low
    cLose = open < close[1] ? close[1] + avg : open + avg
    average = math.avg(oPen, hIgh, lOw, cLose)
    max = math.max(oPen, hIgh, lOw, cLose)
    min = math.min(oPen, hIgh, lOw, cLose)
    [average, max, min]
    
    
    