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

//@version=5

// @description This Library calculate the sl and tp amount in percentage
library("CalculatePercentageSlTp", true)

// @function this function calculates the sl value in percentage
// @param entry_price indicates the entry level
// @param sl_price indicates the stop loss level
// @returns stop loss in percentage
export sl_percentage(float entry_price, float sl_price) =>
	sl_percentage = math.abs((entry_price / sl_price) - 1)*100
	sl_percentage
	
// @function this function calculates the tp value in percentage
// @param entry_price indicates the entry level
// @param tp_price indicates the take profit level
// @returns take profit in percentage
export tp_percentage(float entry_price, float tp_price) =>
	tp_percentage = math.abs((entry_price / tp_price) - 1)*100
	tp_percentage

// @function this function calculates the sl level price
// @param entry_price indicates the entry level
// @param sl_percentage indicates the stop loss percentage
// @returns stop loss price in $
export sl_level(float entry_price, float sl_percentage) =>
	sl_value = entry_price * (1 - (sl_percentage/100))
	sl_value
	
// @function this function calculates the tp level price
// @param entry_price indicates the entry level
// @param tp_percentage indicates the take profit percentage
// @returns take profit price in $
export tp_level(float entry_price, float tp_percentage) =>
	tp_value = entry_price * (1 + (tp_percentage/100))
	tp_value