honest personal library
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Honestcowboy

//@version=5

// @description <library_description>
library("honestpersonallibrary", true)



// @function this will return the number 1,2 or 3 using the logic from Rob Smiths #thestrat which uses these type of bars for setups
// @returns The current candle's #theStrat number based on Rob Smith theStrat type of candles
export thestratnumber() =>
    stratnumber = 0
    if high<high[1] and low>low[1]
        stratnumber := 1
    if (high<high[1] and low<low[1]) or (high>high[1] and low>low[1])
        stratnumber := 2
    if (high>high[1] and low<low[1])
        stratnumber := 3
    [stratnumber]

// ---- Bar size calculations based on ZenLibrary scripts => all credits for this part goes the ZenAndTheArtOfTrading
// @function Gets the current candle's body size (in POINTS, divide by 10 to get pips)
// @returns The current candle's body size in POINTS
export getBodySize() => math.abs(close - open)>0?math.abs(close - open):0.000000000000000000000000000000000000001

// @function Gets the current candle's top wick size (in POINTS, divide by 10 to get pips)
// @returns The current candle's top wick size in POINTS
export getTopWickSize() => math.abs(high - (close > open ? close : open))

// @function Gets the current candle's bottom wick size (in POINTS, divide by 10 to get pips)
// @returns The current candle's bottom wick size in POINTS
export getBottomWickSize() => math.abs((close < open ? close : open) - low)

// @function Gets the current candle's body size as a percentage of its entire size including its wicks
// @returns The current candle's body size percentage
export getBodyPercent() => math.abs(open - close) / math.abs(high - low)

// @function This it to find pinbars with a very long wick compared to the body that are bearish
// @param float minTopMulitplier (default=4) The minimum number of times that the top wick has to be bigger than the candle body size
// @param float minBottomMultiplier (default=2) The minimum number of times that the bottom wick can fit in the top wick
// @returns a bool function true if current candle is withing the parameters
export strictBearPinBar(float minTopMulitplier = 4, float minBottomMultiplier = 2) => 
    topCheck        = getTopWickSize()>getBodySize()*minTopMulitplier
    bottomCheck     = getBottomWickSize()<getTopWickSize()/minBottomMultiplier
    bearPinbarCheck = topCheck and bottomCheck

// @function This it to find pinbars with a very long wick compared to the body that are bearish
// @param float minBottomMulitplier (default=4) The minimum number of times that the top wick has to be bigger than the candle body size
// @param float minTopMultiplier (default=2) The minimum number of times that the top wick can fit in the bottom wick
// @returns a bool function true if current candle is withing the parameters
export strictBullPinBar(float minBottomMulitplier = 4, float minTopMultiplier = 2) => 
    bottomCheck     = getBottomWickSize()>getBodySize()*minBottomMulitplier
    topCheck        = getTopWickSize()<getBottomWickSize()/minTopMultiplier
    bearPinbarCheck = topCheck and bottomCheck

// ================================== //
// ------> Pivot Boss Candles <------ //
// ================================== //
O = open
C = close
H = high
L = low
//

// @function This it to find doji within the pivot boss doji reversal system parameters
// @param float maxbodysize (default=0.1) The percentage body size candle can have
// @returns a bool function true if current candle is a doji candle
export PBDoji(float maxbodysize = 0.1) => 
    smallbody = getBodyPercent() <= maxbodysize
    


// @function his it to find pinbars within the pivot boss wick reversal system parameters
// @param float wick_multiplier (default=2.5) The minimum number of times that the bottom wick has to be bigger than the candle body size
// @param float body_percentage (default=0.25) The percentage range from top of the candle the close has to close in.
// @returns a bool function true if current candle is within the wick reversal parameters
export PBWickRevBull(float wick_multiplier = 2.5, float body_percentage = 0.25) => 
    PBWickRevBull = (C > O) and (O - L) >= ((C - O) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
   (C < O) and (C - L) >= ((O - C) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
   (C == O and C != H) and (H - L) >= ((H - C) * wick_multiplier) and (H - C) <= ((H - L) * body_percentage) or
   (O == H and C == H) and (H - L) >= ta.sma((H - L), 50)

// @function This it to find pinbars within the pivot boss wick reversal system parameters
// @param float wick_multiplier (default=2.5) The minimum number of times that the top wick has to be bigger than the candle body size
// @param float body_percentage (default=0.25) The percentage range from bottom of the candle the close has to close in.
// @returns a bool function true if current candle is within the wick reversal paramaters
export PBWickRevBear(float wick_multiplier = 2.5, float body_percentage = 0.25) => 
    PBWickRevBear = (C < O) and (H - O) >= ((O - C) * wick_multiplier) and (C - L) <= ((H - L) * body_percentage) or
   (C > O) and (H - C) >= ((C - O) * wick_multiplier) and (C - L) <= ((H -L) * body_percentage) or
   (C == O and not C == L) and (H - L) >= ((C - L) * wick_multiplier) and (C - L) <= ((H - L) * body_percentage) or
   (O == L and C == L) and (H - L) >= ta.sma((H - L), 50)

// @function This it to find pivot boss extreme bullish reversals within the system parameters.
// @param float minbodysize (default=0.5) This is the minimum percentage change the body has to be of the total candle.
// @param float maxbodysize (default=0.85) This is the maximum percentage change the body can be of the total candle
// @param float barsback (default=50) The amount of candles the script will look back to find average candle size.
// @param float bodymultiplier (default=2) The multiplier amount the extreme candle has to be bigger than an average candle.
// @returns a bool function true if current candle is within the pivot boss extreme bullish reversal parameters.
export PBExtremeRevBull(float minbodysize = 0.5, float maxbodysize = 0.85, int barsback = 50, float bodymultiplier = 2) => 
    mybodysize = math.abs(C - O)
    AverageBody = ta.sma(mybodysize, barsback)
    mycandlesize = (H - L)
    AverageCandle = ta.sma(mycandlesize, barsback)
    Elongsignal = ((O[1] - C[1]) >= (minbodysize * (H[1] - L[1]))) and ((O[1] - C[1]) <= (maxbodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((O[1] - C[1]) >  AverageBody) and (C > O) and (C[1] < O[1])

// @function This it to find pivot boss extreme bearish reversals within the system parameters.
// @param float minbodysize (default=0.5) This is the minimum percentage change the body has to be of the total candle.
// @param float maxbodysize (default=0.85) This is the maximum percentage change the body can be of the total candle
// @param float barsback (default=50) The amount of candles the script will look back to find average candle size.
// @param float bodymultiplier (default=2) The multiplier amount the extreme candle has to be bigger than an average candle.
// @returns a bool function true if current candle is within the pivotboss extreme bearish reversal parameters
export PBExtremeRevBear(float minbodysize = 0.5, float maxbodysize = 0.85, int barsback = 50, float bodymultiplier = 2) => 
    mybodysize = math.abs(C - O)
    AverageBody = ta.sma(mybodysize, barsback)
    mycandlesize = (H - L)
    AverageCandle = ta.sma(mycandlesize, barsback)
    Eshortsignal = ((C[1] - O[1]) >= (minbodysize * (H[1] - L[1]))) and ((C[1] - O[1]) <= (maxbodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((C[1] - O[1]) >  AverageBody) and (O > C) and (C[1] > O[1])

// @function This it to find pivot boss outside bullish reversals within the system parameters.
// @param float barsback (default=50) The amount of candles the script will look back to find average candle size.
// @param float barmultiplier (default=2) The multiplier amount the extreme candle has to be bigger than an average candle.
// @returns a bool function true if current candle is within the pivot boss outside bullish reversal parameters.
export PBOutsideRevBull(int barsback = 50, float barmultiplier = 2) => 
    mycandlesize   = (H - L)
    AverageCandle1 = ta.sma(mycandlesize, barsback)
    Olongsignal = L < L[1] and C > H[1] and (H - L) >= AverageCandle1 * barmultiplier

// @function This it to find pivot boss outside bearish reversals within the system parameters.
// @param float barsback (default=50) The amount of candles the script will look back to find average candle size.
// @param float barmultiplier (default=2) The multiplier amount the extreme candle has to be bigger than an average candle.
// @returns a bool function true if current candle is within the pivot boss outside bearish reversal parameters.
export PBOutsideRevBear(int barsback = 50, float barmultiplier = 2) => 
    mycandlesize   = (H - L)
    AverageCandle1 = ta.sma(mycandlesize, barsback)
    Oshortsignal = H > H[1] and C < L[1] and (H - L) >= AverageCandle1 * barmultiplier
    
    
// @function This it to find pivot boss bullish doji reversal.
// @param float percentage (default=0.1) The maximum percentage body size the doji can have.
// @returns a bool function true if current candle is within the pivot boss bullish doji reversal parameters.
export PBDojiRevBull(float percentage = 0.1) => 
    candleSize = H[1] - L[1]
    candleBodySize = math.abs(C[1] - O[1])
    sma10 = ta.sma(close, 10)
    Dlongsignal = (candleBodySize <= candleSize * percentage and C > H[1] and H[1] < sma10 and C > O)  or (C > H[2] and C[1] <= H[2] and candleBodySize[1] <= candleSize[1] * percentage and C > O and H[2] < sma10)

// @function This it to find pivot boss bullish doji reversal
// @param float percentage (default=0.1) The maximum percentage body size the doji can have.
// @returns a bool function true if current candle is within the pivot boss bearish doji reversal parameters.
export PBDojiRevBear(float percentage = 0.1) => 
    candleSize = H[1] - L[1]
    candleBodySize = math.abs(C[1] - O[1])
    sma10 = ta.sma(close, 10)
    Dshortsignal = (candleBodySize <= candleSize * percentage and C < L[1] and L[1] > sma10 and C < O)  or (C < L[2] and C[1] >= L[2] and candleBodySize[1] <= candleSize[1] * percentage and C < O and L[2] > sma10)
