VonnyPublicLibrary
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @VonnyFX
// Last Updated August 21, 2022
// @version=5
// @description A collection functions commonly used within my scripts
library("VonnyPublicLibrary")

// --- BEGIN UTILITY FUNCTIONS {


// @function Calculate when a bullish condition occurs. (When you have two variables)
// @param float Enter first variable
// @param float Enter second variable
// @returns True the first bar of your bullish condition
export EntryBull(float _close, float _supertrend) =>
    bool(_close > _supertrend and _close[1] < _supertrend[1])


	
//-----------------------------------------------------------------------------------------------------------	
	
// @function Calculate when a bearish condition occurs. (When you have two variables)
// @param float Enter first variable
// @param float Enter second variable
// @returns True the first bar of your bearish condition
export EntryBear(float _close, float _supertrend) =>
    bool(_close < _supertrend and _close[1] > _supertrend[1])
    
    

//-----------------------------------------------------------------------------------------------------------

// @function Calculate the low of your bearish condition  
// @param bool bullish condition
// @param bool bearish condition
// @param bool candle buffer to prevent the script from crashing. Since were working with a Dynamic Length
// @param float Enter what you want to see the low off? Low of the bar OR Close of the bar
// @param float Enter what you want to see the low off? Low of the bar OR Open of the bar might see pointless but some times the Lowest open is lower then the Lowest Close
// @returns the Lowest point of your sell condition when ever your buy condition is triggered

export LowestPivot(bool _EntryBull, bool _EntryBear, bool _barDEX, float _lowRClose, float _lowROpen) =>
    _lookbackBuy = (ta.barssince(_EntryBull)) 
    _lookbackSell = (ta.barssince(_EntryBear)) 
    _lookback  = _lookbackBuy > _lookbackSell ? _lookbackBuy : _lookbackSell
    _lowLevel = _barDEX  ? ta.lowest(_lowRClose,_lookback ) : na
    _lowLevelOpen = _barDEX  ? ta.lowest(open,_lookback) : na
    _lowLevelX = _lowLevelOpen < _lowLevel ? _lowLevelOpen : _lowLevel
    float((_lowLevelX < _lowROpen) ? _lowLevelX : _lowROpen)

 
	
//-----------------------------------------------------------------------------------------------------------

// @function Calculate the high of your bullish condition 
// @param bool bullish condition
// @param bool bearish condition
// @param bool candle buffer to prevent the script from crashing. Since were working with a Dynamic Length
// @param float Enter what you want to see the high off? High of the bar OR Close of the bar
// @param float Enter what you want to see the high off? High of the bar OR Open of the bar might see pointless but some times the Highest Open is Higher then the Highest Close
// @returns the Highest point of your buy condition when ever your sell condition is triggered

export HighestPivot(bool _EntryBull, bool _EntryBear, bool _barDEX, float _highRClose, float _highROpen) =>
    _lookbackBuy = (ta.barssince(_EntryBull)) 
    _lookbackSell = (ta.barssince(_EntryBear)) 
    _lookback  = _lookbackBuy > _lookbackSell ? _lookbackBuy : _lookbackSell
    _highLevel = _barDEX  ? ta.highest(_highRClose,(_lookback )) : na
    _highLevelOpen = _barDEX  ? ta.highest(open,(_lookback )) : na
    _highLevelX = _highLevelOpen > _highLevel ? _highLevelOpen : _highLevel
    float((_highLevelX > _highROpen) ? _highLevelX : _highROpen)
    
    
    
//-----------------------------------------------------------------------------------------------------------

// @function Calculate how many bars since your bullish condition and bearish condition.
// @param bool enter bullish condition
// @param bool enter bearish condition
// @returns the condition with the most bars

export lookBack(bool _EntryBull, bool _EntryBear) =>
    _lookbackBuy = (ta.barssince(_EntryBull)) 
    _lookbackSell = (ta.barssince(_EntryBear)) 
    int(_lookbackBuy > _lookbackSell ? _lookbackBuy : _lookbackSell)
    

	
//-----------------------------------------------------------------------------------------------------------





