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提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。