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

//@version=5

// @description: Library that contains my functions for using within strategies and indicators
library("MyLibrary")

// @function isHammer: Checks if current bar is hammer doji
// @param float fib: Fibonacci retracement value 
// @returns boolean: True if current bar is a hammer doji, and false if it is not
export isHammer(float fib=0.382) =>
	//TODO : add function body and return value here
	bullishFib = (low - high) * fib + high
	lowestBody = close < open ? close : open
	lowestBody >= bullishFib and (close > open)

// @function isShootingStar: Checks if current bar is shooting star doji 
// @param float fib: Fibonacci retracement value
// @returns boolean: True if current bar is a shooting star doji, and false if it is not
export isShootingStar(float fib=0.382) => 
	bearishFib = (high - low) * fib + low
	highestBody = close > open ? close : open
	highestBody <= bearishFib and (close < open)


// @function isBullishEngulfing: Checks if bullish engulfing candle pattern is present
// @returns boolean: True if previous candle is red, current candle is green, candle closes above previous open, and opens at/lower than previous close
export isBullishEngulfing() => 
	prevCandleRed = close[1] < open[1]
	greenCandle = close > open
	openAtBelowPrevClose = open <= close[1]
	closeAbovePrevOpen = close > open[1]

	prevCandleRed and greenCandle and openAtBelowPrevClose and closeAbovePrevOpen

// @function isBearishEngulfing: Checks if bearish engulfing candle pattern is present
// @returns boolean: True if previous candle is green, current candle is red, candle closes below previous open, and opens at/above previous close
export isBearishEngulfing() =>
	prevCandleGreen = close[1] > open[1]
	redCandle = close < open
	openAtAbovePrevClose = open >= close[1]
	closeBelowPrevOpen = close < open[1]

	prevCandleGreen and redCandle and openAtAbovePrevClose and closeBelowPrevOpen

// VWAP data variables
[vwap, upperSD1, lowerSD1] = ta.vwap(open, timeframe.change("1D"), 1)
[vwap2, upperSD2, lowerSD2] = ta.vwap(open, timeframe.change("1D"), 2)
[vwap3, upperSD3, lowerSD3] = ta.vwap(open, timeframe.change("1D"), 3)

// @function isAtUpperVWAPSD: Checks if current candle is touching the 2nd or 3rd upper VWAP standard deviation lines
// @returns boolean: True if current candle is touching the 2nd or 3rd upper VWAP standard deviation lines
export isAtUpperVWAPSD() => 
	isAtUpperSD2 = high >= upperSD2 and low <= upperSD2
	isAtUpperSD3 = high >= upperSD3 and low <= upperSD3

	isAtUpperSD2 or isAtUpperSD3

// @function isAtLowerVWAPSD: Checks if current candle is touching the 2nd or 3rd lower VWAP standard deviation lines
// @returns boolean: True if current candle is touching the 2nd or 3rd lower VWAP standard deviation lines
export isAtLowerVWAPSD() =>
	isAtLowerSD2 = high >= lowerSD2 and low <= lowerSD2
	isAtLowerSD3 = high >= lowerSD3 and low <= lowerSD3

	isAtLowerSD2 or isAtLowerSD3

// @function isAtVWAP: Checks if current candle is touching the VWAP 
// @returns boolean: True if current candle is touching the VWAP
export isAtVWAP() => 
	isAtVWAP = high >= vwap and low <= vwap

	isAtVWAP

// RSI variables
rsi = ta.rsi(close, 14)
export rsiOversold() =>
	rsi < 30

export rsiOverbought() =>
	rsi > 70
	