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

//@version=5

// @description TODO: This library is fibonacci calculator helper
library("AutoFiboRetrace")

// @function TODO: auto calculate fibnacci retrace by Highest and Lowest of Price
// @param FPeriod TODO: lenght of candle for find highest and lowest
// @param sourceLow TODO: source for find lowest value
// @param sourceHigh TODO: source for find highest value
// @param isUptrend : is uptrend
// @returns TODO: List of Level price
export autoCalculate(int FPeriod, float sourceLow, float sourceHigh, bool isUptrend) =>
    Fhigh=ta.highest(sourceHigh, FPeriod)
    Flow=ta.lowest(sourceLow, FPeriod)
    Diff = Fhigh-Flow
    FL_0 = isUptrend ? Fhigh :Flow
    FL_236 = isUptrend ? Fhigh - (Diff*0.236) : Flow + (Diff*0.236)
    FL_382 = isUptrend ? Fhigh - (Diff*0.382) : Flow + (Diff*0.382)
    FL_500 = isUptrend ? Fhigh - (Diff*0.500) : Flow + (Diff*0.500)
    FL_618 = isUptrend ? Fhigh - (Diff*0.618) : Flow + (Diff*0.618)
    FL_786 = isUptrend ? Fhigh - (Diff*0.786) : Flow + (Diff*0.786)
    FL_1000 = isUptrend ? Fhigh - (Diff*1.000) : Flow + (Diff*1.000)
    FL_1236 = isUptrend ? Fhigh - (Diff*1.236) : Flow + (Diff*1.236)
    FL_1382 = isUptrend ? Fhigh - (Diff*1.382) : Flow + (Diff*1.382)
    FL_1500 = isUptrend ? Fhigh - (Diff*1.500) : Flow + (Diff*1.500)
    FL_1618 = isUptrend ? Fhigh - (Diff*1.618) : Flow + (Diff*1.618)
    FL_1786 = isUptrend ? Fhigh - (Diff*1.786) : Flow + (Diff*1.786)
    FL_2 = isUptrend ? Fhigh - (Diff*2) : Flow + (Diff*2)
    [FL_0,FL_236, FL_382, FL_500, FL_618, FL_786, FL_1000, FL_1236, FL_1382, FL_1500, FL_1618, FL_1786, FL_2]

// @function TODO: calculate fibnacci retrace by fix high low value
// @param lowValue TODO: low value
// @param highValue TODO: high value
// @param isUptrend : is uptrend
// @returns TODO: List of Level price
export fixCalculate(float lowValue, float highValue, bool isUptrend) =>
    Fhigh=highValue
    Flow=lowValue
    Diff = Fhigh-Flow
    FL_0 = isUptrend ? Fhigh :Flow
    FL_236 = isUptrend ? Fhigh - (Diff*0.236) : Flow + (Diff*0.236)
    FL_382 = isUptrend ? Fhigh - (Diff*0.382) : Flow + (Diff*0.382)
    FL_500 = isUptrend ? Fhigh - (Diff*0.500) : Flow + (Diff*0.500)
    FL_618 = isUptrend ? Fhigh - (Diff*0.618) : Flow + (Diff*0.618)
    FL_786 = isUptrend ? Fhigh - (Diff*0.786) : Flow + (Diff*0.786)
    FL_1000 = isUptrend ? Fhigh - (Diff*1.000) : Flow + (Diff*1.000)
    FL_1236 = isUptrend ? Fhigh - (Diff*1.236) : Flow + (Diff*1.236)
    FL_1382 = isUptrend ? Fhigh - (Diff*1.382) : Flow + (Diff*1.382)
    FL_1500 = isUptrend ? Fhigh - (Diff*1.500) : Flow + (Diff*1.500)
    FL_1618 = isUptrend ? Fhigh - (Diff*1.618) : Flow + (Diff*1.618)
    FL_1786 = isUptrend ? Fhigh - (Diff*1.786) : Flow + (Diff*1.786)
    FL_2 = isUptrend ? Fhigh - (Diff*2) : Flow + (Diff*2)
    [FL_0,FL_236, FL_382, FL_500, FL_618, FL_786, FL_1000, FL_1236, FL_1382, FL_1500, FL_1618, FL_1786, FL_2]
    
// @function TODO: auto calculate fibnacci retrace by Highest and Lowest of Price
// @param FPeriod TODO: lenght of candle for find highest and lowest
// @param sourceLow TODO: source for find lowest value
// @param sourceHigh TODO: source for find highest value
// @returns TODO: List of Level price
export autoCalculateActionZone(int FPeriod, float sourceLow, float sourceHigh) =>
    Fhigh=ta.highest(sourceHigh, FPeriod)
    Flow=ta.lowest(sourceLow, FPeriod)
    Diff = Fhigh-Flow
    FL_0 = Flow
    FL_236 = Flow + (Diff*0.236)
    FL_382 = Flow + (Diff*0.382)
    FL_618 = Flow + (Diff*0.618)
    FL_786 = Flow + (Diff*0.786)
    FL_1000 = Flow + (Diff*1.000)
    [FL_0,FL_236, FL_382, FL_618, FL_786, FL_1000]

// @function TODO: calculate fibnacci retrace by fix high low value
// @param lowValue TODO: low value
// @param highValue TODO: high value
// @returns TODO: List of Level price
export fixCalculateActionZone(float lowValue, float highValue) =>
    Fhigh=highValue
    Flow=lowValue
    Diff = Fhigh-Flow
    FL_0 = Flow
    FL_236 = Flow + (Diff*0.236)
    FL_382 = Flow + (Diff*0.382)
    FL_618 = Flow + (Diff*0.618)
    FL_786 = Flow + (Diff*0.786)
    FL_1000 = Flow + (Diff*1.000)
    [FL_0,FL_236, FL_382, FL_618, FL_786, FL_1000]
    
// @function TODO: calculate fibnacci retrace by fix high low value
// @param lowValue TODO: low value
// @param highValue TODO: high value
// @returns TODO: List of Level price
export getSigmaFixCalculated(float lowValue, float highValue) =>
    Fhigh=highValue
    Flow=lowValue
    Diff = Fhigh-Flow
    FL_0 = Flow
    FL_236 = Flow + (Diff*0.236)
    FL_382 = Flow + (Diff*0.382)
    FL_618 = Flow + (Diff*0.618)
    FL_786 = Flow + (Diff*0.786)
    FL_1000 = Flow + (Diff*1.000)

    openP = ta.ema(FL_382, 26)
    closeP = ta.ema(FL_382, 12)
    highP = ta.highest(closeP, 4)
    lowP = ta.lowest(closeP, 4)

    [openP, highP, lowP, closeP]

// @function TODO: auto calculate fibnacci retrace by Highest and Lowest of Price
// @param FPeriod TODO: lenght of candle for find highest and lowest
// @param sourceLow TODO: source for find lowest value
// @param sourceHigh TODO: source for find highest value
// @returns TODO: List of Level price
export getSigmaAutoCalculate(int FPeriod, float sourceLow, float sourceHigh) =>
    Fhigh=ta.highest(sourceHigh, FPeriod)
    Flow=ta.lowest(sourceLow, FPeriod)
    Diff = Fhigh-Flow
    FL_0 = Flow
    FL_236 = Flow + (Diff*0.236)
    FL_382 = Flow + (Diff*0.382)
    FL_618 = Flow + (Diff*0.618)
    FL_786 = Flow + (Diff*0.786)
    FL_1000 = Flow + (Diff*1.000)

    openP = ta.ema(FL_382, 26)
    closeP = ta.ema(FL_382, 12)
    highP = ta.highest(closeP, 4)
    lowP = ta.lowest(closeP, 4)

    [openP, highP, lowP, closeP]
