PINE LIBRARY
VPQuantLib

Library "VPQuantLib"
Misc of math, position size and consolidation detection functions that can be used accross various scripts.
isPercentAboveReference(current, percent, reference, or_equal)
Checks if the current value is bigger (or equal) with the provided percent value to the reference
Parameters:
current (float): - what to check against the reference
percent (float): - what is the percent to check for difference
reference (float): - what to compare against
or_equal (bool): - enables checking for bigger or equal
Returns: true if the current is percent bigger (or equal) to the reference
isPercentBelowReference(current, percent, reference, or_equal)
Checks if the current value is smaller (or equal) with the provided percent value to the reference
Parameters:
current (float): - what to check against the reference
percent (float): - what is the percent to check for difference
reference (float): - what to compare against
or_equal (bool): - enables checking for smaller or equal
Returns: true if the current is percent smaller (or equal) to the reference
isInRange(current, reference, min_percent, max_percent, below)
Checks if the current value is greater/smaller than the reference value within the provided percent range
Parameters:
current (float): - what to check for being in range against the refenence
reference (float): - what to compare against
min_percent (float): - the min percent range border
max_percent (float): - the max percent range border
below (bool): - check if below or above the reference
return true if the current is bigger/smaller than the reference withing the [min, max] percent range provided
GetRiskBasedPositionSize(account_balance, equity_risk_perc, max_loss_per_share)
Calculates and returns the positins size based on risk of the equity
Parameters:
account_balance (float): - total account balance
equity_risk_perc (int): - percent of equity to risk in the trade
max_loss_per_share (float): - maximum loss per share (in currency, not in %) that we're willing to loose (calc based on the entry_price-stop_loss_price)
return number of shares to buy
CheckInRangeConsolidation(consolidation_period, allowed_consolidation_range, ref_high, ref_low, prev_bar_consolidaton, draw_consolidation_lines)
Checks if the current bar is in a consolidation range
Parameters:
consolidation_period (int): - the number of bars to consider for consolidation range calculation
allowed_consolidation_range (int): - the percentage range allowed for the current consolidation range to be considered valid
ref_high (float): - the reference high value to use for consolidation range calculation
ref_low (float): - the reference low value to use for consolidation range calculation
prev_bar_consolidaton (bool)
draw_consolidation_lines (bool): - a boolean indicating if consolidation range lines should be drawn on the chart
return a tuple of three values:
1. _curr_consolidation - a boolean indicating if the current bar is in consolidation range
2. _curr_consolidation_low - the current consolidation low value
3. _curr_consolidation_high - the current consolidation high value
FindBasicConsolidation(loopback_period, consolidation_length, ref_high, ref_low, draw_consolidation_lines)
Finds a basic consolidation areas, looking back 1000 bars to find the pivot of the trend and checks if the current bar is in consolidation area counting the
number of bars that have not broken the consolidation high/low levels
Parameters:
loopback_period (int): - the number of bars to look back to determine the high/low watermark
consolidation_length (int): - minimum number of bars required to establish a consolidation period
ref_high (float): - user input for high (can be based on the bar or wicks)
ref_low (float): - user input for high (can be based on the bar or wicks)
draw_consolidation_lines (bool): - enable/disable drawing of the consolidation lines
Returns: _pivot_point - pivot point
Misc of math, position size and consolidation detection functions that can be used accross various scripts.
isPercentAboveReference(current, percent, reference, or_equal)
Checks if the current value is bigger (or equal) with the provided percent value to the reference
Parameters:
current (float): - what to check against the reference
percent (float): - what is the percent to check for difference
reference (float): - what to compare against
or_equal (bool): - enables checking for bigger or equal
Returns: true if the current is percent bigger (or equal) to the reference
isPercentBelowReference(current, percent, reference, or_equal)
Checks if the current value is smaller (or equal) with the provided percent value to the reference
Parameters:
current (float): - what to check against the reference
percent (float): - what is the percent to check for difference
reference (float): - what to compare against
or_equal (bool): - enables checking for smaller or equal
Returns: true if the current is percent smaller (or equal) to the reference
isInRange(current, reference, min_percent, max_percent, below)
Checks if the current value is greater/smaller than the reference value within the provided percent range
Parameters:
current (float): - what to check for being in range against the refenence
reference (float): - what to compare against
min_percent (float): - the min percent range border
max_percent (float): - the max percent range border
below (bool): - check if below or above the reference
return true if the current is bigger/smaller than the reference withing the [min, max] percent range provided
GetRiskBasedPositionSize(account_balance, equity_risk_perc, max_loss_per_share)
Calculates and returns the positins size based on risk of the equity
Parameters:
account_balance (float): - total account balance
equity_risk_perc (int): - percent of equity to risk in the trade
max_loss_per_share (float): - maximum loss per share (in currency, not in %) that we're willing to loose (calc based on the entry_price-stop_loss_price)
return number of shares to buy
CheckInRangeConsolidation(consolidation_period, allowed_consolidation_range, ref_high, ref_low, prev_bar_consolidaton, draw_consolidation_lines)
Checks if the current bar is in a consolidation range
Parameters:
consolidation_period (int): - the number of bars to consider for consolidation range calculation
allowed_consolidation_range (int): - the percentage range allowed for the current consolidation range to be considered valid
ref_high (float): - the reference high value to use for consolidation range calculation
ref_low (float): - the reference low value to use for consolidation range calculation
prev_bar_consolidaton (bool)
draw_consolidation_lines (bool): - a boolean indicating if consolidation range lines should be drawn on the chart
return a tuple of three values:
1. _curr_consolidation - a boolean indicating if the current bar is in consolidation range
2. _curr_consolidation_low - the current consolidation low value
3. _curr_consolidation_high - the current consolidation high value
FindBasicConsolidation(loopback_period, consolidation_length, ref_high, ref_low, draw_consolidation_lines)
Finds a basic consolidation areas, looking back 1000 bars to find the pivot of the trend and checks if the current bar is in consolidation area counting the
number of bars that have not broken the consolidation high/low levels
Parameters:
loopback_period (int): - the number of bars to look back to determine the high/low watermark
consolidation_length (int): - minimum number of bars required to establish a consolidation period
ref_high (float): - user input for high (can be based on the bar or wicks)
ref_low (float): - user input for high (can be based on the bar or wicks)
draw_consolidation_lines (bool): - enable/disable drawing of the consolidation lines
Returns: _pivot_point - pivot point
Pine腳本庫
秉持TradingView一貫精神,作者已將此Pine代碼以開源函式庫形式發佈,方便我們社群中的其他Pine程式設計師重複使用。向作者致敬!您可以在私人專案或其他開源發表中使用此函式庫,但在公開發表中重用此代碼須遵守社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
Pine腳本庫
秉持TradingView一貫精神,作者已將此Pine代碼以開源函式庫形式發佈,方便我們社群中的其他Pine程式設計師重複使用。向作者致敬!您可以在私人專案或其他開源發表中使用此函式庫,但在公開發表中重用此代碼須遵守社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。