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

//@version=5

// @description TODO: add library description here
library("DateLibrary", overlay=true)

// @function Calculates the all-time high of a series.
// @param val Series to use (high is used if no argument is supplied).
// @returns The all-time high for the series.
export hi(float val = high) =>
    var float ath = val
    ath := math.max(ath, val)

// @function Calculates the all-time low of a series.
// @param val Series to use (low is used if no argument is supplied).
// @returns The all-time low for the series.
export lo(float val = low) =>
    var float atl = val
    atl := math.min(atl, val)

plot(hi())
plot(lo())

//DO NOT MODIFY
wickTimesStart = timestamp(2016, 04, 16, 00, 00)
wickTimesEnd = timestamp(2016, 05, 01, 00, 00)
wickTimes() =>
    time >= wickTimesStart and time <= wickTimesEnd ? true : false





export window(string TradePeriod) =>
    FromYear = 2012
    ToYear = 2035
    FromMonth = 01
    FromDay = 01
    ToMonth = 01
    ToDay = 01
    switch TradePeriod
        '2012.04-now' =>
            FromMonth := 04
            FromDay := 10
        '2012.04-2021' =>
            FromMonth := 04
            FromDay := 10
            ToYear := 2021
        '2013-now' =>
            FromYear := 2013
            FromMonth := 01
            FromDay := 01
        '2014-now' =>
            FromYear := 2013
            FromMonth := 12
            FromDay := 30
        '2017-now' =>
            FromYear := 2017
        '2018-now' =>
            FromYear := 2018
        '2019-now' =>
            FromYear := 2019
        '2020-now' =>
            FromYear := 2020
        'ytd' =>
            FromYear := 2022
        '2012' =>
            FromMonth := 03
            FromYear := 2012
            ToYear := 2013
        '2013' =>
            FromYear := 2013
            ToYear := 2013
            ToMonth := 12
            ToDay := 30
        '2012-2014' =>
            FromYear := 2012
            ToYear := 2014
            FromMonth := 03
        '2012-2017' =>
            FromYear := 2012
            ToYear := 2017
            FromMonth := 03
        '2014-2019' =>
            FromYear := 2014
            ToYear := 2019
        '2018-2020' =>
            FromYear := 2018
            ToYear := 2020
        '2019-2020.08' =>
            FromYear := 2019
            ToYear := 2020
            ToMonth := 08
        '2014' =>
            FromYear := 2014
            ToYear := 2015
            ToDay := 24
        '2015' =>
            FromYear := 2015
            FromDay := 25
            ToYear := 2015
            ToMonth := 12
            ToDay := 26
        '2016' =>
            FromYear := 2015
            FromMonth := 12
            FromDay := 25
            ToYear := 2017
        '2017' =>
            FromYear := 2017
            FromDay := 07
            ToYear := 2017
            ToMonth := 12
            ToDay := 31
        '2018' =>
            FromYear := 2018
            ToYear := 2018
            ToMonth := 12
            ToDay := 24
        '2019' =>
            FromYear := 2018
            FromMonth := 12
            FromDay := 24
            ToYear := 2019
            ToMonth := 12
            ToDay := 24
        '2020' =>
            FromYear := 2019
            FromMonth := 12
            FromDay := 31
            ToYear := 2021
            ToMonth := 01
            ToDay := 01
        '2021' =>
            FromYear := 2020
            FromMonth := 12
            FromDay := 31
            ToYear := 2022
            ToMonth := 01
            ToDay := 01
        'tests' =>
            FromYear := 2021
            FromMonth := 10
            FromDay := 27
    time >= timestamp(FromYear, FromMonth, FromDay, 00, 00) and time <= timestamp(ToYear, ToMonth, ToDay, 23, 59) ? true : false
//DO NOT MODIFY

CloseBelow3d201201 = timestamp(2012, 03, 27, 23, 59)
GoldenExit201201 = timestamp(2012, 04, 20, 23, 59)

CloseBelow3d201202 = timestamp(2012, 04, 23, 23, 59)
GoldenExit201202 = timestamp(2012, 06, 01, 23, 59)

CloseBelow3d201203 = timestamp(2012, 10, 26, 23, 59)
GoldenExit201203 = timestamp(2012, 10, 29, 23, 59)

CloseBelow3d01 = timestamp(2013, 06, 29, 23, 59)
GoldenExit01 = timestamp(2013, 08, 22, 23, 59)

CloseBelow3d1 = timestamp(2014, 02, 17, 23, 59)
GoldenExit1 = timestamp(2014, 05, 27, 23, 59)

CloseBelow3d2 = timestamp(2014, 08, 13, 23, 59)
GoldenExit2 = timestamp(2015, 06, 17, 23, 59)

CloseBelow3d3 = timestamp(2015, 06, 23, 23, 59)
GoldenExit3 = timestamp(2015, 06, 29, 23, 59)

CloseBelow3d4 = timestamp(2015, 08, 19, 23, 59)
GoldenExit4 = timestamp(2015, 10, 15, 23, 59)

CloseBelow3d5 = timestamp(2016, 08, 27, 23, 59)
GoldenExit5 = timestamp(2016, 09, 05, 23, 59)

CloseBelow3d6 = timestamp(2016, 09, 20, 23, 59)
GoldenExit6 = timestamp(2016, 10, 11, 23, 59)

CloseBelow3d7 = timestamp(2018, 01, 30, 23, 59)
GoldenExit7 = timestamp(2018, 07, 23, 23, 59)

CloseBelow3d8 = timestamp(2018, 08, 01, 23, 59)
GoldenExit8 = timestamp(2019, 03, 16, 23, 59)

CloseBelow3d9 = timestamp(2019, 09, 21, 23, 59)
GoldenExit9 = timestamp(2020, 01, 15, 23, 59)

CloseBelow3d10 = timestamp(2020, 03, 09, 23, 59)
GoldenExit10 = timestamp(2020, 04, 29, 23, 59)

CloseBelow3d11 = timestamp(2020, 09, 23, 23, 59)
GoldenExit11 = timestamp(2020, 09, 26, 23, 59)

CloseBelow3d12 = timestamp(2021, 05, 12, 23, 59)
GoldenExit12 = timestamp(2021, 08, 07, 23, 59)

CloseBelow3d13 = timestamp(2021, 12, 05, 23, 59)
GoldenExit13 = timestamp(2022, 03, 28, 23, 59)

CloseBelow3d14 = timestamp(2022, 04, 09, 23, 59)
GoldenExit14 = timestamp(2023, 01, 01, 23, 59)





export BearishPeriod() =>
    time >= CloseBelow3d201201 and time <= GoldenExit201201 or time >= CloseBelow3d201202 and time <= GoldenExit201202 or time >= CloseBelow3d201203 and time <= GoldenExit201203
     or time >= CloseBelow3d01 and time <= GoldenExit01 or time >= CloseBelow3d1 and time <= GoldenExit1 or time >= CloseBelow3d2 and time <= GoldenExit2 or time >= CloseBelow3d3 and time <= GoldenExit3
     or time >= CloseBelow3d4 and time <= GoldenExit4 or time >= CloseBelow3d5 and time <= GoldenExit5 or time >= CloseBelow3d6 and time <= GoldenExit6 or time >= CloseBelow3d7 and time <= GoldenExit7
     or time >= CloseBelow3d8 and time <= GoldenExit8 or time >= CloseBelow3d9 and time <= GoldenExit9 or time >= CloseBelow3d10 and time <= GoldenExit10 or time >= CloseBelow3d11 and time <= GoldenExit11
     or time >= CloseBelow3d12 and time <= GoldenExit12
     or time >= CloseBelow3d13 and time <= GoldenExit13
     or time >= CloseBelow3d14 and time <= GoldenExit14
     ? true : false



// @function TODO: add function description here
// @param x TODO: add parameter x description here
// @returns TODO: add what function returns
export fun(float x) =>
	//TODO : add function body and return value here
	

	x