PINE LIBRARY
업데이트됨 Vantage_LO1_Sizing

**Overview**
Position-sizing library for the LO1 breakout box day-trading strategy. Provides a unified recoup (opposite-add) sizing pipeline and dollar-risk/profit helpers. Extracting these functions into a library avoids Pine Script's function inlining, reducing compiled token count in the main strategy.
**Exported Type: RecoupSizingResult**
Holds the output of the 8-step sizing pipeline:
• Micro-level quantities (raw, DLL-capped, final)
• YM-level quantities (pre/post min-1-YM policy, proxy-capped)
• Risk gate values (projected loss, worst-case drawdown, pass/fail)
• Recoup scenario P&L (net outcome if T1 stops and recoup wins)
**Exported Functions**
`f_calcTradeRiskDollars(entry, stop, qty)` → float
Projected risk in dollars. Converts price distance to ticks via syminfo.mintick, then to dollars via syminfo.pointvalue.
`f_calcTradeProfitDollars(entry, tp, qty)` → float
Projected profit in dollars. Same tick-to-dollar conversion applied to the take-profit distance.
`f_computeRecoupSizing(...)` → RecoupSizingResult
8-step recoup sizing pipeline:
1. Raw micro qty from risk multiplier (CEILING)
2. Daily loss limit cap at micro level
3. Micro-to-YM conversion (FLOOR)
4. Minimum-1-YM policy
5. Proxy capacity cap
6. Micro-equivalent for risk gating
7. Worst-case projection (base stop + opposing flatten + recoup stop)
8. Risk gate pass/fail
Plus scenario P&L: net recoup outcome and T1-win profit.
**Usage**
import Vantage-Stack/Vantage_LO1_Sizing/1 as sz
float risk = sz.f_calcTradeRiskDollars(entry, stop, qty)
sz.RecoupSizingResult r = sz.f_computeRecoupSizing(baseQty, baseEntry, baseStop, recoupEntry, recoupStop,
recoupTP, multiplier, proxyMul, minOneYM, curLoss, maxLoss, maxProxy, t1TP, oppTP, oppFrac, oppRemoval)
======================
Library "Vantage_LO1_Sizing"
Position sizing library for LO1 breakout box strategy.
Extracts pure-computation functions to reduce compiled token count in the main script.
f_calcTradeRiskDollars(_entry, _stop, _qty)
Calculates projected risk in dollars for a position (qty × |entry−stop| in ticks × pointvalue).
Parameters:
_entry (float): Entry price
_stop (float): Stop-loss price
_qty (float): Position quantity (contracts)
Returns: Risk in dollars
f_calcTradeProfitDollars(_entry, _tp, _qty)
Calculates projected profit in dollars for a position (qty × |tp−entry| in ticks × pointvalue).
Parameters:
_entry (float): Entry price
_tp (float): Take-profit price
_qty (float): Position quantity (contracts)
Returns: Profit in dollars
f_computeRecoupSizing(baseQtyMicro, baseEntry, baseStop, recoupEntry, recoupStop, recoupTP, oppositeMultiplier, proxyQtyMul, minOneYMEnabled, currentLossDollars, maxDailyLossLimit, maxProxyCap, t1TPPrice, oppTPPrice, oppAddStopFrac, opposingRemovalEnabled)
Computes recoup (opposite-add) position sizing through an 8-step pipeline: raw micro qty, DLL cap, micro-to-YM conversion, min-1-YM policy, proxy cap, risk gating, worst-case projection, and recoup scenario P&L.
Parameters:
baseQtyMicro (int): T1 micro-contract quantity
baseEntry (float): T1 entry price
baseStop (float): T1 stop-loss price
recoupEntry (float): Recoup entry price
recoupStop (float): Recoup stop-loss price
recoupTP (float): Recoup take-profit price
oppositeMultiplier (float): Target risk multiplier for recoup vs T1 (e.g., 4.0)
proxyQtyMul (float): Micro-to-YM conversion factor (0 = no proxy)
minOneYMEnabled (bool): Force minimum 1 YM contract when proxy is active
currentLossDollars (float): Running session loss in dollars (0 for estimate mode)
maxDailyLossLimit (float): Daily loss limit in dollars (-1 = disabled)
maxProxyCap (int): Maximum proxy contracts cap (0 = unlimited)
t1TPPrice (float): T1 take-profit price (for scenario P&L calculation)
oppTPPrice (float): Opposing MYM TP price when T1 stops (for scenario profit calc)
oppAddStopFrac (float): Fraction of base risk for opposite MYM emergency flatten
opposingRemovalEnabled (bool): Whether opposing removal entry mode is active
Returns: RecoupSizingResult with quantities, risk values, and scenario P&L
RecoupSizingResult
Holds the complete output of the 8-step recoup sizing pipeline: micro/YM quantities, risk gate results, worst-case projections, and recoup-scenario P&L.
Fields:
microQtyRaw (series int)
microCapByDLL (series int)
microQtyCapped (series int)
ymQtyPre (series int)
ymQtyFinal (series int)
microEqForGate (series int)
projectedLossRecoup (series float)
dllRemaining (series float)
totalWorstCase (series float)
riskOK (series bool)
oppMYMLoss (series float)
didMinOneOverride (series bool)
dllForcedZero (series bool)
recoupScenarioNet (series float)
t1WinProfit (series float)
Position-sizing library for the LO1 breakout box day-trading strategy. Provides a unified recoup (opposite-add) sizing pipeline and dollar-risk/profit helpers. Extracting these functions into a library avoids Pine Script's function inlining, reducing compiled token count in the main strategy.
**Exported Type: RecoupSizingResult**
Holds the output of the 8-step sizing pipeline:
• Micro-level quantities (raw, DLL-capped, final)
• YM-level quantities (pre/post min-1-YM policy, proxy-capped)
• Risk gate values (projected loss, worst-case drawdown, pass/fail)
• Recoup scenario P&L (net outcome if T1 stops and recoup wins)
**Exported Functions**
`f_calcTradeRiskDollars(entry, stop, qty)` → float
Projected risk in dollars. Converts price distance to ticks via syminfo.mintick, then to dollars via syminfo.pointvalue.
`f_calcTradeProfitDollars(entry, tp, qty)` → float
Projected profit in dollars. Same tick-to-dollar conversion applied to the take-profit distance.
`f_computeRecoupSizing(...)` → RecoupSizingResult
8-step recoup sizing pipeline:
1. Raw micro qty from risk multiplier (CEILING)
2. Daily loss limit cap at micro level
3. Micro-to-YM conversion (FLOOR)
4. Minimum-1-YM policy
5. Proxy capacity cap
6. Micro-equivalent for risk gating
7. Worst-case projection (base stop + opposing flatten + recoup stop)
8. Risk gate pass/fail
Plus scenario P&L: net recoup outcome and T1-win profit.
**Usage**
import Vantage-Stack/Vantage_LO1_Sizing/1 as sz
float risk = sz.f_calcTradeRiskDollars(entry, stop, qty)
sz.RecoupSizingResult r = sz.f_computeRecoupSizing(baseQty, baseEntry, baseStop, recoupEntry, recoupStop,
recoupTP, multiplier, proxyMul, minOneYM, curLoss, maxLoss, maxProxy, t1TP, oppTP, oppFrac, oppRemoval)
======================
Library "Vantage_LO1_Sizing"
Position sizing library for LO1 breakout box strategy.
Extracts pure-computation functions to reduce compiled token count in the main script.
f_calcTradeRiskDollars(_entry, _stop, _qty)
Calculates projected risk in dollars for a position (qty × |entry−stop| in ticks × pointvalue).
Parameters:
_entry (float): Entry price
_stop (float): Stop-loss price
_qty (float): Position quantity (contracts)
Returns: Risk in dollars
f_calcTradeProfitDollars(_entry, _tp, _qty)
Calculates projected profit in dollars for a position (qty × |tp−entry| in ticks × pointvalue).
Parameters:
_entry (float): Entry price
_tp (float): Take-profit price
_qty (float): Position quantity (contracts)
Returns: Profit in dollars
f_computeRecoupSizing(baseQtyMicro, baseEntry, baseStop, recoupEntry, recoupStop, recoupTP, oppositeMultiplier, proxyQtyMul, minOneYMEnabled, currentLossDollars, maxDailyLossLimit, maxProxyCap, t1TPPrice, oppTPPrice, oppAddStopFrac, opposingRemovalEnabled)
Computes recoup (opposite-add) position sizing through an 8-step pipeline: raw micro qty, DLL cap, micro-to-YM conversion, min-1-YM policy, proxy cap, risk gating, worst-case projection, and recoup scenario P&L.
Parameters:
baseQtyMicro (int): T1 micro-contract quantity
baseEntry (float): T1 entry price
baseStop (float): T1 stop-loss price
recoupEntry (float): Recoup entry price
recoupStop (float): Recoup stop-loss price
recoupTP (float): Recoup take-profit price
oppositeMultiplier (float): Target risk multiplier for recoup vs T1 (e.g., 4.0)
proxyQtyMul (float): Micro-to-YM conversion factor (0 = no proxy)
minOneYMEnabled (bool): Force minimum 1 YM contract when proxy is active
currentLossDollars (float): Running session loss in dollars (0 for estimate mode)
maxDailyLossLimit (float): Daily loss limit in dollars (-1 = disabled)
maxProxyCap (int): Maximum proxy contracts cap (0 = unlimited)
t1TPPrice (float): T1 take-profit price (for scenario P&L calculation)
oppTPPrice (float): Opposing MYM TP price when T1 stops (for scenario profit calc)
oppAddStopFrac (float): Fraction of base risk for opposite MYM emergency flatten
opposingRemovalEnabled (bool): Whether opposing removal entry mode is active
Returns: RecoupSizingResult with quantities, risk values, and scenario P&L
RecoupSizingResult
Holds the complete output of the 8-step recoup sizing pipeline: micro/YM quantities, risk gate results, worst-case projections, and recoup-scenario P&L.
Fields:
microQtyRaw (series int)
microCapByDLL (series int)
microQtyCapped (series int)
ymQtyPre (series int)
ymQtyFinal (series int)
microEqForGate (series int)
projectedLossRecoup (series float)
dllRemaining (series float)
totalWorstCase (series float)
riskOK (series bool)
oppMYMLoss (series float)
didMinOneOverride (series bool)
dllForcedZero (series bool)
recoupScenarioNet (series float)
t1WinProfit (series float)
릴리즈 노트
v2 Updated rounding calcs릴리즈 노트
v3 Updated Rounding릴리즈 노트
v4 Updated Rounding릴리즈 노트
v5 Update Signature릴리즈 노트
v6 Updated Sizing Behavior릴리즈 노트
v7 Updated Sizing릴리즈 노트
v8 - Partial Exit Support릴리즈 노트
v9 Updated support for auto risk sizing 릴리즈 노트
v10 Updating Sizing Logic Updated:
f_computeRecoupSizing(baseQtyMicro, baseEntry, baseStop, recoupEntry, recoupStop, recoupTP, oppositeMultiplier, proxyQtyMul, minOneYMEnabled, currentLossDollars, maxDailyLossLimit, maxProxyCap, t1TPPrice, oppTPPrice, oppAddStopFrac, opposingRemovalEnabled, t1AlreadyClosed, useRoundUp)
Computes recoup (opposite-add) position sizing through an 8-step pipeline: raw micro qty, DLL cap, micro-to-YM conversion, min-1-YM policy, proxy cap, risk gating, worst-case projection, and recoup scenario P&L.
Parameters:
baseQtyMicro (int): T1 micro-contract quantity
baseEntry (float): T1 entry price
baseStop (float): T1 stop-loss price
recoupEntry (float): Recoup entry price
recoupStop (float): Recoup stop-loss price
recoupTP (float): Recoup take-profit price
oppositeMultiplier (float): Target risk multiplier for recoup vs T1 (e.g., 4.0)
proxyQtyMul (float): Micro-to-YM conversion factor (0 = no proxy)
minOneYMEnabled (bool): Force minimum 1 YM contract when proxy is active
currentLossDollars (float): Running session loss in dollars (0 for estimate mode)
maxDailyLossLimit (float): Daily loss limit in dollars (-1 = disabled)
maxProxyCap (int): Maximum proxy contracts cap (0 = unlimited)
t1TPPrice (float): T1 take-profit price (for scenario P&L calculation)
oppTPPrice (float): Opposing MYM TP price when T1 stops (for scenario profit calc)
oppAddStopFrac (float): Fraction of base risk for opposite MYM emergency flatten
opposingRemovalEnabled (bool): Whether opposing removal entry mode is active
t1AlreadyClosed (bool): Reserved for future use. All current call sites use false (default). Would be true only if recoup were re-sized after T1 close, which no current code path does.
useRoundUp (bool)
Returns: RecoupSizingResult with quantities, risk values, and scenario P&L
f_findBestPartialExit(baseQtyMicro, baseRisk, riskPerMicroRecoup, profitPerMicroRecoup, proxyQtyMul, currentLossDollars, maxDailyLossLimit, maxProxyCap, oppMYMLoss, t1AlreadyClosed, oppositeMultiplier, useRoundUp)
Finds the best partial exit configuration (how many opposing MYM to keep) that passes both risk and profit gates.
Scans k from 0 upward — first passing config wins (prefers full removal when it works).
Parameters:
baseQtyMicro (int): T1 qty (q)
baseRisk (float): T1 total risk in dollars
riskPerMicroRecoup (float): Recoup risk per micro contract
profitPerMicroRecoup (float): Recoup profit per micro contract
proxyQtyMul (float): Micro-to-YM conversion factor (0.10)
currentLossDollars (float): Running session loss in dollars
maxDailyLossLimit (float): Daily loss limit in dollars
maxProxyCap (int): Maximum proxy contracts cap (0 = unlimited)
oppMYMLoss (float): Opposing MYM emergency flatten loss per micro
t1AlreadyClosed (bool): Reserved for future use. All current call sites use false (recoup is sized at T1 entry time, not after close).
oppositeMultiplier (float): Target risk multiplier for recoup vs T1
useRoundUp (bool)
Returns: PartialExitResult with best k, adjusted YM qty, and gate results
f_scanPartialExitUpward(baseGreen, baseMatch, maxScanQty, longEntry, longStop, longTP, longTPOpp, shortEntry, shortStop, shortTP, shortTPOpp, oppositeMultiplier, proxyQtyMul, minOneYMEnabled, maxDailyLossLimit, maxProxyCap, oppAddStopFrac, opposingRemovalEnabled, matchPct, commBuffer, useRoundUp)
Scans upward from baseline quantities to find larger T1 sizes enabled by partial exit.
Replaces inline loops in the main script to reduce compiled token count.
Parameters:
baseGreen (int): Baseline bestQtyGreen from normal scan
baseMatch (int): Baseline bestQtyMatch from normal scan
maxScanQty (int): Maximum quantity to scan up to
longEntry (float): Long leg entry price
longStop (float): Long leg stop price
longTP (float): Long leg TP price
longTPOpp (float): Long leg opposing TP price
shortEntry (float): Short leg entry price
shortStop (float): Short leg stop price
shortTP (float): Short leg TP price
shortTPOpp (float): Short leg opposing TP price
oppositeMultiplier (float): Recoup qty multiplier
proxyQtyMul (float): Micro-to-YM conversion factor
minOneYMEnabled (bool): Min-1-YM toggle
maxDailyLossLimit (float): Daily loss limit
maxProxyCap (int): Max proxy contracts
oppAddStopFrac (float): Opposing stop fraction
opposingRemovalEnabled (bool): Whether opposing removal is active
matchPct (float): Match T1 profit percentage
commBuffer (float): Commission buffer dollars
useRoundUp (bool)
Returns: PartialExitScanResult with updated quantities and improvement flags
f_sizingWithPartialExit(baseQtyMicro, baseEntry, baseStop, recoupEntry, recoupStop, recoupTP, oppositeMultiplier, proxyQtyMul, minOneYMEnabled, currentLossDollars, maxDailyLossLimit, maxProxyCap, t1TPPrice, oppTPPrice, oppAddStopFrac, opposingRemovalEnabled, useRoundUp)
Runs recoup sizing and partial exit optimization in one call.
Combines f_computeRecoupSizing + f_findBestPartialExit to reduce token count at call sites.
Parameters:
baseQtyMicro (int): T1 micro quantity
baseEntry (float): T1 entry price
baseStop (float): T1 stop price
recoupEntry (float): Recoup entry price
recoupStop (float): Recoup stop price
recoupTP (float): Recoup TP price
oppositeMultiplier (float): Recoup qty multiplier
proxyQtyMul (float): Micro-to-YM conversion factor
minOneYMEnabled (bool): Min-1-YM toggle
currentLossDollars (float): Running session loss
maxDailyLossLimit (float): Daily loss limit
maxProxyCap (int): Max proxy contracts
t1TPPrice (float): T1 TP price
oppTPPrice (float): Opposing TP price
oppAddStopFrac (float): Opposing stop fraction
opposingRemovalEnabled (bool): Whether opposing removal is active
useRoundUp (bool)
Returns: [RecoupSizingResult, PartialExitResult] — PE result has found=false if not applicable
릴리즈 노트
v11 Rounding Fixes릴리즈 노트
v12 Updated Autosizing Method릴리즈 노트
v13 Updated Risk Sizing Method릴리즈 노트
Add slippage to sizing calculations파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.