PINE LIBRARY
KC Institutional Core Library

KC Institutional Core Library v1.0
KCInstitutionalCore is a reusable Pine Script v6 utility library created to support structured technical-analysis workflows without duplicating common helper logic across multiple indicators and strategies.
The library provides transparent and independently reusable functions for:
The exported functions are deterministic utilities. They do not generate guaranteed trading signals, predict future price movement or execute trades.
Basic import example
Pine Script®
The detailed function documentation below explains every exported function, parameter and return value.
Library "KCInstitutionalCore"
Reusable Pine Script v6 utilities for timeframe context, score grading, premium/discount classification, alignment, risk-to-reward and position-size calculations. Designed as a transparent helper library for indicators and strategies.
clamp(value, minimum, maximum)
Restricts a numeric value to the supplied minimum and maximum boundaries.
Parameters:
value (float): Value to restrict.
minimum (float): Lower boundary.
maximum (float): Upper boundary.
Returns: The restricted value.
scoreToGrade(score)
Converts a numeric score into a concise quality grade.
Parameters:
score (float): Score expressed on a 0–100 scale.
Returns: A grade string from AA to D.
normalizeScore(rawScore, maximumScore)
Normalizes a raw score to a 0–100 scale.
Parameters:
rawScore (float): Current raw score.
maximumScore (float): Maximum possible raw score.
Returns: Normalized score from 0 to 100, or na when maximumScore is not positive.
rangeLocation(price, rangeHigh, rangeLow)
Classifies the current price inside a supplied dealing range.
Parameters:
price (float): Current or evaluated price.
rangeHigh (float): Upper boundary of the range.
rangeLow (float): Lower boundary of the range.
Returns: A tuple containing PREMIUM, DISCOUNT, or EQUILIBRIUM and the 0–100 range percentage.
riskReward(entry, stop, target)
Calculates reward-to-risk from entry, stop and target prices.
Parameters:
entry (float): Entry price.
stop (float): Stop-loss price.
target (float): Target price.
Returns: Absolute reward-to-risk ratio, or na when the stop distance is zero.
positionSize(accountSize, riskPercent, entry, stop, pointValue)
Estimates position size from account risk and stop distance.
Parameters:
accountSize (float): Account balance or planning capital.
riskPercent (float): Percentage of account risked.
entry (float): Entry price.
stop (float): Stop-loss price.
pointValue (float): Monetary value per price point for one unit.
Returns: Estimated units or lots according to the supplied pointValue, or na for invalid inputs.
tradeStyle(chartSeconds)
Maps chart duration in seconds to a general planning style.
Parameters:
chartSeconds (float): Chart timeframe duration in seconds, normally supplied with timeframe.in_seconds().
Returns: SCALP, INTRADAY, SWING, or POSITION.
adaptiveTimeframes(chartSeconds)
Suggests two broader context timeframes from the chart duration.
Parameters:
chartSeconds (float): Chart timeframe duration in seconds, normally supplied with timeframe.in_seconds().
Returns: A tuple containing primary and secondary context timeframe strings.
alignmentState(localBias, htfBias, mtfBias)
Summarizes local, higher-timeframe and multi-timeframe directional agreement.
Parameters:
localBias (int): Local direction: 1 bullish, -1 bearish, 0 neutral.
htfBias (int): Higher-timeframe direction: 1 bullish, -1 bearish, 0 neutral.
mtfBias (int): Broader alignment direction: 1 bullish, -1 bearish, 0 neutral.
Returns: BULL ALIGNED, BEAR ALIGNED, PARTIAL, CONFLICT, or NEUTRAL.
executionBlocker(direction, htfBias, mtfBias, location, structureConfirmed, liquidityConfirmed, newsBlocked)
Returns the first material execution blocker in a transparent priority order.
Parameters:
direction (int): Intended direction: 1 long, -1 short, 0 neutral.
htfBias (int): Higher-timeframe direction: 1 bullish, -1 bearish, 0 neutral.
mtfBias (int): Multi-timeframe direction: 1 bullish, -1 bearish, 0 neutral.
location (string): PREMIUM, DISCOUNT, or EQUILIBRIUM.
structureConfirmed (bool): True when the required structure event is confirmed.
liquidityConfirmed (bool): True when the required liquidity event is confirmed.
newsBlocked (bool): True when a manual news blackout is active.
Returns: A concise blocker description, or CLEAR when no listed blocker is active.
KCInstitutionalCore is a reusable Pine Script v6 utility library created to support structured technical-analysis workflows without duplicating common helper logic across multiple indicators and strategies.
The library provides transparent and independently reusable functions for:
- Score normalization and trade-quality grading
- Premium, Discount and Equilibrium classification
- Risk-to-reward calculation
- Risk-based position-size estimation
- Timeframe-aware trading-style classification
- Adaptive higher-timeframe selection
- Directional alignment analysis
- Execution-blocker identification
The exported functions are deterministic utilities. They do not generate guaranteed trading signals, predict future price movement or execute trades.
Basic import example
The detailed function documentation below explains every exported function, parameter and return value.
Library "KCInstitutionalCore"
Reusable Pine Script v6 utilities for timeframe context, score grading, premium/discount classification, alignment, risk-to-reward and position-size calculations. Designed as a transparent helper library for indicators and strategies.
clamp(value, minimum, maximum)
Restricts a numeric value to the supplied minimum and maximum boundaries.
Parameters:
value (float): Value to restrict.
minimum (float): Lower boundary.
maximum (float): Upper boundary.
Returns: The restricted value.
scoreToGrade(score)
Converts a numeric score into a concise quality grade.
Parameters:
score (float): Score expressed on a 0–100 scale.
Returns: A grade string from AA to D.
normalizeScore(rawScore, maximumScore)
Normalizes a raw score to a 0–100 scale.
Parameters:
rawScore (float): Current raw score.
maximumScore (float): Maximum possible raw score.
Returns: Normalized score from 0 to 100, or na when maximumScore is not positive.
rangeLocation(price, rangeHigh, rangeLow)
Classifies the current price inside a supplied dealing range.
Parameters:
price (float): Current or evaluated price.
rangeHigh (float): Upper boundary of the range.
rangeLow (float): Lower boundary of the range.
Returns: A tuple containing PREMIUM, DISCOUNT, or EQUILIBRIUM and the 0–100 range percentage.
riskReward(entry, stop, target)
Calculates reward-to-risk from entry, stop and target prices.
Parameters:
entry (float): Entry price.
stop (float): Stop-loss price.
target (float): Target price.
Returns: Absolute reward-to-risk ratio, or na when the stop distance is zero.
positionSize(accountSize, riskPercent, entry, stop, pointValue)
Estimates position size from account risk and stop distance.
Parameters:
accountSize (float): Account balance or planning capital.
riskPercent (float): Percentage of account risked.
entry (float): Entry price.
stop (float): Stop-loss price.
pointValue (float): Monetary value per price point for one unit.
Returns: Estimated units or lots according to the supplied pointValue, or na for invalid inputs.
tradeStyle(chartSeconds)
Maps chart duration in seconds to a general planning style.
Parameters:
chartSeconds (float): Chart timeframe duration in seconds, normally supplied with timeframe.in_seconds().
Returns: SCALP, INTRADAY, SWING, or POSITION.
adaptiveTimeframes(chartSeconds)
Suggests two broader context timeframes from the chart duration.
Parameters:
chartSeconds (float): Chart timeframe duration in seconds, normally supplied with timeframe.in_seconds().
Returns: A tuple containing primary and secondary context timeframe strings.
alignmentState(localBias, htfBias, mtfBias)
Summarizes local, higher-timeframe and multi-timeframe directional agreement.
Parameters:
localBias (int): Local direction: 1 bullish, -1 bearish, 0 neutral.
htfBias (int): Higher-timeframe direction: 1 bullish, -1 bearish, 0 neutral.
mtfBias (int): Broader alignment direction: 1 bullish, -1 bearish, 0 neutral.
Returns: BULL ALIGNED, BEAR ALIGNED, PARTIAL, CONFLICT, or NEUTRAL.
executionBlocker(direction, htfBias, mtfBias, location, structureConfirmed, liquidityConfirmed, newsBlocked)
Returns the first material execution blocker in a transparent priority order.
Parameters:
direction (int): Intended direction: 1 long, -1 short, 0 neutral.
htfBias (int): Higher-timeframe direction: 1 bullish, -1 bearish, 0 neutral.
mtfBias (int): Multi-timeframe direction: 1 bullish, -1 bearish, 0 neutral.
location (string): PREMIUM, DISCOUNT, or EQUILIBRIUM.
structureConfirmed (bool): True when the required structure event is confirmed.
liquidityConfirmed (bool): True when the required liquidity event is confirmed.
newsBlocked (bool): True when a manual news blackout is active.
Returns: A concise blocker description, or CLEAR when no listed blocker is active.
Pine腳本庫
秉持TradingView一貫精神,作者已將此Pine代碼以開源函式庫形式發佈,方便我們社群中的其他Pine程式設計師重複使用。向作者致敬!您可以在私人專案或其他開源發表中使用此函式庫,但在公開發表中重用此代碼須遵守社群規範。
Get exclusive analysis and trade setups on my Telegram channel: t.me/+ljltWsU9ex01YTQ0
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
Pine腳本庫
秉持TradingView一貫精神,作者已將此Pine代碼以開源函式庫形式發佈,方便我們社群中的其他Pine程式設計師重複使用。向作者致敬!您可以在私人專案或其他開源發表中使用此函式庫,但在公開發表中重用此代碼須遵守社群規範。
Get exclusive analysis and trade setups on my Telegram channel: t.me/+ljltWsU9ex01YTQ0
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。