PINE LIBRARY
IC optimiser lib

Library "IC optimiser lib"
Library for IC-based parameter optimization
findOptimalParam(testParams, icValues, currentParam, smoothing)
Find optimal parameter from array of IC values
Parameters:
testParams (array<float>): Array of parameter values being tested
icValues (array<float>): Array of IC values for each parameter (same size as testParams)
currentParam (float): Current parameter value (for smoothing)
smoothing (simple float): Smoothing factor (0-1, e.g., 0.2 means 20% new, 80% old)
Returns: [optimizedParam, bestIC, bestIndex] New parameter value, its IC, and array index
adaptiveParamWithStarvation(opt, testParams, icValues, smoothing, starvationThreshold, starvationJumpSize)
Adaptive parameter selection with starvation handling
Parameters:
opt (ICOptimizer): ICOptimizer object
testParams (array<float>): Array of parameter values
icValues (array<float>): Array of IC values for each parameter
smoothing (simple float): Normal smoothing factor
starvationThreshold (simple int): Number of updates before triggering starvation mode
starvationJumpSize (simple float): Jump size when in starvation (as fraction of range)
Returns: [newParam, bestIC] Updated parameter and IC
detectAndAdjustDomination(longCount, shortCount, currentLongLevel, currentShortLevel, dominationRatio, jumpSize, minLevel, maxLevel)
Detect signal imbalance and adjust parameters
Parameters:
longCount (int): Number of long signals in period
shortCount (int): Number of short signals in period
currentLongLevel (float): Current long threshold
currentShortLevel (float): Current short threshold
dominationRatio (simple int): Ratio threshold (e.g., 4 = 4:1 imbalance)
jumpSize (simple float): Size of adjustment
minLevel (simple float): Minimum allowed level
maxLevel (simple float): Maximum allowed level
Returns: [newLongLevel, newShortLevel, isDominated]
calcIC(signals, returns, lookback)
Parameters:
signals (float)
returns (float)
lookback (simple int)
classifyIC(currentIC, icWindow, goodPercentile, badPercentile)
Parameters:
currentIC (float)
icWindow (simple int)
goodPercentile (simple int)
badPercentile (simple int)
evaluateSignal(signal, forwardReturn)
Parameters:
signal (float)
forwardReturn (float)
updateOptimizerState(opt, signal, forwardReturn, currentIC, metaICPeriod)
Parameters:
opt (ICOptimizer)
signal (float)
forwardReturn (float)
currentIC (float)
metaICPeriod (simple int)
calcSuccessRate(successful, total)
Parameters:
successful (int)
total (int)
createICStatsTable(opt, paramName, normalSuccess, normalTotal)
Parameters:
opt (ICOptimizer)
paramName (string)
normalSuccess (int)
normalTotal (int)
initOptimizer(initialParam)
Parameters:
initialParam (float)
ICOptimizer
Fields:
currentParam (series float)
currentIC (series float)
metaIC (series float)
totalSignals (series int)
successfulSignals (series int)
goodICSignals (series int)
goodICSuccess (series int)
nonBadICSignals (series int)
nonBadICSuccess (series int)
goodICThreshold (series float)
badICThreshold (series float)
updateCounter (series int)
Library for IC-based parameter optimization
findOptimalParam(testParams, icValues, currentParam, smoothing)
Find optimal parameter from array of IC values
Parameters:
testParams (array<float>): Array of parameter values being tested
icValues (array<float>): Array of IC values for each parameter (same size as testParams)
currentParam (float): Current parameter value (for smoothing)
smoothing (simple float): Smoothing factor (0-1, e.g., 0.2 means 20% new, 80% old)
Returns: [optimizedParam, bestIC, bestIndex] New parameter value, its IC, and array index
adaptiveParamWithStarvation(opt, testParams, icValues, smoothing, starvationThreshold, starvationJumpSize)
Adaptive parameter selection with starvation handling
Parameters:
opt (ICOptimizer): ICOptimizer object
testParams (array<float>): Array of parameter values
icValues (array<float>): Array of IC values for each parameter
smoothing (simple float): Normal smoothing factor
starvationThreshold (simple int): Number of updates before triggering starvation mode
starvationJumpSize (simple float): Jump size when in starvation (as fraction of range)
Returns: [newParam, bestIC] Updated parameter and IC
detectAndAdjustDomination(longCount, shortCount, currentLongLevel, currentShortLevel, dominationRatio, jumpSize, minLevel, maxLevel)
Detect signal imbalance and adjust parameters
Parameters:
longCount (int): Number of long signals in period
shortCount (int): Number of short signals in period
currentLongLevel (float): Current long threshold
currentShortLevel (float): Current short threshold
dominationRatio (simple int): Ratio threshold (e.g., 4 = 4:1 imbalance)
jumpSize (simple float): Size of adjustment
minLevel (simple float): Minimum allowed level
maxLevel (simple float): Maximum allowed level
Returns: [newLongLevel, newShortLevel, isDominated]
calcIC(signals, returns, lookback)
Parameters:
signals (float)
returns (float)
lookback (simple int)
classifyIC(currentIC, icWindow, goodPercentile, badPercentile)
Parameters:
currentIC (float)
icWindow (simple int)
goodPercentile (simple int)
badPercentile (simple int)
evaluateSignal(signal, forwardReturn)
Parameters:
signal (float)
forwardReturn (float)
updateOptimizerState(opt, signal, forwardReturn, currentIC, metaICPeriod)
Parameters:
opt (ICOptimizer)
signal (float)
forwardReturn (float)
currentIC (float)
metaICPeriod (simple int)
calcSuccessRate(successful, total)
Parameters:
successful (int)
total (int)
createICStatsTable(opt, paramName, normalSuccess, normalTotal)
Parameters:
opt (ICOptimizer)
paramName (string)
normalSuccess (int)
normalTotal (int)
initOptimizer(initialParam)
Parameters:
initialParam (float)
ICOptimizer
Fields:
currentParam (series float)
currentIC (series float)
metaIC (series float)
totalSignals (series int)
successfulSignals (series int)
goodICSignals (series int)
goodICSuccess (series int)
nonBadICSignals (series int)
nonBadICSuccess (series int)
goodICThreshold (series float)
badICThreshold (series float)
updateCounter (series int)
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.