PINE LIBRARY
업데이트됨 SWLib_Core

Library "SWLib_Core"
f_pctToPrice(pct, basePrice)
Parameters:
pct (float): Percentage value (e.g., 2.0 = 2%)
basePrice (float): Reference price
Returns: Price difference
f_pipsToPrice(pips, pipVal)
Parameters:
pips (float): Number of pips (e.g., 100 pips)
pipVal (float): Price value of 1 pip (XAUUSD: 0.01)
Returns: Price difference
f_toPrice(value, basePrice, isForex, pipVal)
Parameters:
value (float): Distance value (% or pip)
basePrice (float): Reference price (for percentage mode)
isForex (bool): Is Forex mode
pipVal (float): Pip value (for Forex mode)
Returns: Price difference
f_lotToNotional(lots, price, contractSize)
Parameters:
lots (float): Lot amount (e.g., 0.01)
price (float): Instrument price
contractSize (float): Contract size (XAUUSD: 100)
Returns: Position value in Dollars
f_lotToMargin(lots, price, contractSize, leverage)
Parameters:
lots (float): Lot amount
price (float): Price
contractSize (float): Contract size
leverage (int): Leverage
Returns: Required margin (USD)
f_calcFee(notional, useFee, feePercent)
Parameters:
notional (float): Trade volume
useFee (bool): Is fee active
feePercent (float): Fee percentage
Returns: Calculated fee
f_calcAvgPrice(oldAvg, oldNotional, newPrice, newNotional)
Parameters:
oldAvg (float): Current average price
oldNotional (float): Current position volume
newPrice (float): New entry price
newNotional (float): New entry volume
Returns: New weighted average price
f_multiplier(lvl, dcaMode)
Parameters:
lvl (int): Current DCA level
dcaMode (string): DCA mode ('Adım', '2x', 'Kapalı', 'Seçim Adımlı')
Returns: Multiplier value
f_unrealizedPnL(isLong, avgPrice, totalNotional, currentPrice)
Parameters:
isLong (bool): Long or Short
avgPrice (float): Average entry price
totalNotional (float): Total volume
currentPrice (float): Current price
Returns: Unrealized PnL
f_totalUnrealizedPnL(avgLongPrice, totalLongNotional, avgShortPrice, totalShortNotional, currentPrice)
Parameters:
avgLongPrice (float)
totalLongNotional (float)
avgShortPrice (float)
totalShortNotional (float)
currentPrice (float)
f_liqPrice_Long(avgPrice, totalNotional, availableEquity)
Parameters:
avgPrice (float): Long average price
totalNotional (float): Long total volume
availableEquity (float): Available equity (balance + realized PNL - fee - short margin)
Returns: Estimated liquidation price
f_liqPrice_Short(avgPrice, totalNotional, availableEquity)
Parameters:
avgPrice (float): Short average price
totalNotional (float): Short total volume
availableEquity (float): Available equity
Returns: Estimated liquidation price
f_calcTPLevels_Long(avgPrice, tp1_pct, tp2_pct, tp3_pct)
Parameters:
avgPrice (float): Average entry price
tp1_pct (float): TP1 percentage
tp2_pct (float): TP2 percentage
tp3_pct (float): TP3 percentage
Returns: TPVisuals structure
f_calcTPLevels_Short(avgPrice, tp1_pct, tp2_pct, tp3_pct)
Parameters:
avgPrice (float): Average entry price
tp1_pct (float): TP1 percentage
tp2_pct (float): TP2 percentage
tp3_pct (float): TP3 percentage
Returns: TPVisuals structure
f_calcTPLevels_Long_Unified(avgPrice, tp1_val, tp2_val, tp3_val, isForex, pipVal)
Parameters:
avgPrice (float): Average entry price
tp1_val (float): TP1 distance (% or pip)
tp2_val (float): TP2 distance
tp3_val (float): TP3 distance
isForex (bool): Is Forex (pip) mode
pipVal (float): Pip value (for Forex)
Returns: TPVisuals structure
f_calcTPLevels_Short_Unified(avgPrice, tp1_val, tp2_val, tp3_val, isForex, pipVal)
Parameters:
avgPrice (float)
tp1_val (float)
tp2_val (float)
tp3_val (float)
isForex (bool)
pipVal (float)
f_calcSL_Long(avgPrice, level, cfg, trailHigh)
Parameters:
avgPrice (float)
level (int)
cfg (SLConfig)
trailHigh (float)
f_calcSL_Short(avgPrice, level, cfg, trailLow)
Parameters:
avgPrice (float)
level (int)
cfg (SLConfig)
trailLow (float)
f_calcSL_Long_Unified(avgPrice, level, cfg, trailHigh, isForex, pipVal)
Parameters:
avgPrice (float)
level (int)
cfg (SLConfig)
trailHigh (float)
isForex (bool): if true pip based, else % based
pipVal (float): Forex pip value (for Forex mode)
Returns: [sl_fixed, sl_trail] tuple
f_calcSL_Short_Unified(avgPrice, level, cfg, trailLow, isForex, pipVal)
Parameters:
avgPrice (float)
level (int)
cfg (SLConfig)
trailLow (float)
isForex (bool)
pipVal (float)
f_effectiveSL(isLong, slFixed, slTrail)
Parameters:
isLong (bool): True if Long
slFixed (float): Fixed SL
slTrail (float): Trailing SL (can be na)
Returns: Effective SL price
f_calcEquity(walletBalance, totalRealizedPnL, latchedPnL_L, latchedPnL_S, unrealizedTotal)
Parameters:
walletBalance (float)
totalRealizedPnL (float)
latchedPnL_L (float)
latchedPnL_S (float)
unrealizedTotal (float)
f_calcFreeMargin(equity, totalLongNotional, totalShortNotional, leverage)
Parameters:
equity (float)
totalLongNotional (float)
totalShortNotional (float)
leverage (int)
f_availableEquityForLiq(walletBalance, totalRealizedPnL, latchedPnL_L, latchedPnL_S, totalFees, useFee, otherSideNotional, leverage)
Parameters:
walletBalance (float)
totalRealizedPnL (float)
latchedPnL_L (float)
latchedPnL_S (float)
totalFees (float)
useFee (bool)
otherSideNotional (float)
leverage (int)
Returns: Available equity
f_shouldForceFullExit(posNotional, exitAmount, leverage, minThreshold)
Parameters:
posNotional (float): Current position volume
exitAmount (float): Amount to exit
leverage (int): Leverage
minThreshold (float): Minimum position size (USDT)
Returns: true if full close required
f_calcExitPnL(isLong, avgPrice, exitPrice, exitAmount)
Parameters:
isLong (bool): Is Long
avgPrice (float): Average price
exitPrice (float): Exit price
exitAmount (float): Exit amount
Returns: PnL value
f_isApproachingSL(isLong, priceExtreme, slPrice, avgPrice, approachPct)
Parameters:
isLong (bool): Is Long
priceExtreme (float): Low (Long) or High (Short)
slPrice (float): SL price
avgPrice (float): Average price
approachPct (float): Approach threshold percentage
Returns: true if approaching
f_isApproachingLiq(isLong, priceExtreme, liqPrice, avgPrice, approachPct)
Parameters:
isLong (bool)
priceExtreme (float)
liqPrice (float)
avgPrice (float)
approachPct (float)
f_isApproachingSL_Unified(isLong, priceExtreme, slPrice, avgPrice, approachVal, isForex, pipVal)
Parameters:
isLong (bool)
priceExtreme (float)
slPrice (float)
avgPrice (float)
approachVal (float)
isForex (bool)
pipVal (float)
f_isApproachingLiq_Unified(isLong, priceExtreme, liqPrice, avgPrice, approachVal, isForex, pipVal)
Parameters:
isLong (bool)
priceExtreme (float)
liqPrice (float)
avgPrice (float)
approachVal (float)
isForex (bool)
pipVal (float)
f_forexUsedMargin(lots, price, contractSize, leverage)
Parameters:
lots (float): Lot amount
price (float): Price
contractSize (float): Contract size
leverage (int): Leverage
Returns: Used margin (USD)
f_forexFreeMargin(equity, usedMarginL, usedMarginS)
Parameters:
equity (float)
usedMarginL (float)
usedMarginS (float)
f_forexPnL(isLong, entryPrice, exitPrice, lots, contractSize, pipVal)
Parameters:
isLong (bool): Is Long
entryPrice (float): Entry price
exitPrice (float): Exit price
lots (float): Lot amount
contractSize (float): Contract size
pipVal (float): Pip value
Returns: PnL (USD)
f_calcPivots(method, h, l, c)
Parameters:
method (string): Pivot method ('Geleneksel', 'Fibonacci', 'Woodie', 'Camarilla')
h (float): Previous High
l (float): Previous Low
c (float): Previous Close
Returns: [PP, R1, R2, R3, S1, S2, S3]
f_getPrice(inlinePrice, currentClose)
Parameters:
inlinePrice (float)
currentClose (float)
f_stackOffset(h, l)
Parameters:
h (float)
l (float)
TPConfig
Fields:
tp1_pct (series float)
tp1_port (series float)
tp1_reverse (series bool)
tp2_active (series bool)
tp2_pct (series float)
tp2_port (series float)
tp3_active (series bool)
tp3_pct (series float)
tp3_port (series float)
DCATPConfig
Fields:
tp1_pct (series float)
tp1_port (series float)
tp2_pct (series float)
tp2_port (series float)
tp3_pct (series float)
tp3_port (series float)
SLConfig
Fields:
l1_pct (series float)
dca_pct (series float)
useBE (series bool)
be_act_pct (series float)
be_offset_pct (series float)
useTS (series bool)
ts_act_pct (series float)
ts_dev_pct (series float)
PositionConfig
Fields:
baseAmount (series float)
leverage (series int)
maxLevel (series int)
dcaMode (series string)
selectionStep (series int)
useFee (series bool)
feePercent (series float)
PositionState
Fields:
level (series int)
signalCounter (series int)
avgPrice (series float)
lastEntryPrice (series float)
totalNotional (series float)
peakNotional (series float)
pctLeft (series float)
tpStage (series int)
tpStageDCA (series int)
accumulatedPnL (series float)
TradeStats
Fields:
slCountWin (series int)
slCountLoss (series int)
liqCount (series int)
maxDcaHit (series int)
maxVol (series float)
maxLoss (series float)
grossLoss (series float)
totalFees (series float)
totalVolume (series float)
tradeCount (series int)
peakEquity (series float)
maxDrawdown (series float)
maxDrawdownPct (series float)
currentDrawdownPct (series float)
approachSL (series int)
approachLiq (series int)
TPVisuals
Fields:
tp1 (series float)
tp2 (series float)
tp3 (series float)
SLState
Fields:
slFixed (series float)
slTrail (series float)
trailExtreme (series float)
ForexConfig
Fields:
pipValue (series float)
contractSize (series float)
baseLot (series float)
isForex (series bool)
f_pctToPrice(pct, basePrice)
Parameters:
pct (float): Percentage value (e.g., 2.0 = 2%)
basePrice (float): Reference price
Returns: Price difference
f_pipsToPrice(pips, pipVal)
Parameters:
pips (float): Number of pips (e.g., 100 pips)
pipVal (float): Price value of 1 pip (XAUUSD: 0.01)
Returns: Price difference
f_toPrice(value, basePrice, isForex, pipVal)
Parameters:
value (float): Distance value (% or pip)
basePrice (float): Reference price (for percentage mode)
isForex (bool): Is Forex mode
pipVal (float): Pip value (for Forex mode)
Returns: Price difference
f_lotToNotional(lots, price, contractSize)
Parameters:
lots (float): Lot amount (e.g., 0.01)
price (float): Instrument price
contractSize (float): Contract size (XAUUSD: 100)
Returns: Position value in Dollars
f_lotToMargin(lots, price, contractSize, leverage)
Parameters:
lots (float): Lot amount
price (float): Price
contractSize (float): Contract size
leverage (int): Leverage
Returns: Required margin (USD)
f_calcFee(notional, useFee, feePercent)
Parameters:
notional (float): Trade volume
useFee (bool): Is fee active
feePercent (float): Fee percentage
Returns: Calculated fee
f_calcAvgPrice(oldAvg, oldNotional, newPrice, newNotional)
Parameters:
oldAvg (float): Current average price
oldNotional (float): Current position volume
newPrice (float): New entry price
newNotional (float): New entry volume
Returns: New weighted average price
f_multiplier(lvl, dcaMode)
Parameters:
lvl (int): Current DCA level
dcaMode (string): DCA mode ('Adım', '2x', 'Kapalı', 'Seçim Adımlı')
Returns: Multiplier value
f_unrealizedPnL(isLong, avgPrice, totalNotional, currentPrice)
Parameters:
isLong (bool): Long or Short
avgPrice (float): Average entry price
totalNotional (float): Total volume
currentPrice (float): Current price
Returns: Unrealized PnL
f_totalUnrealizedPnL(avgLongPrice, totalLongNotional, avgShortPrice, totalShortNotional, currentPrice)
Parameters:
avgLongPrice (float)
totalLongNotional (float)
avgShortPrice (float)
totalShortNotional (float)
currentPrice (float)
f_liqPrice_Long(avgPrice, totalNotional, availableEquity)
Parameters:
avgPrice (float): Long average price
totalNotional (float): Long total volume
availableEquity (float): Available equity (balance + realized PNL - fee - short margin)
Returns: Estimated liquidation price
f_liqPrice_Short(avgPrice, totalNotional, availableEquity)
Parameters:
avgPrice (float): Short average price
totalNotional (float): Short total volume
availableEquity (float): Available equity
Returns: Estimated liquidation price
f_calcTPLevels_Long(avgPrice, tp1_pct, tp2_pct, tp3_pct)
Parameters:
avgPrice (float): Average entry price
tp1_pct (float): TP1 percentage
tp2_pct (float): TP2 percentage
tp3_pct (float): TP3 percentage
Returns: TPVisuals structure
f_calcTPLevels_Short(avgPrice, tp1_pct, tp2_pct, tp3_pct)
Parameters:
avgPrice (float): Average entry price
tp1_pct (float): TP1 percentage
tp2_pct (float): TP2 percentage
tp3_pct (float): TP3 percentage
Returns: TPVisuals structure
f_calcTPLevels_Long_Unified(avgPrice, tp1_val, tp2_val, tp3_val, isForex, pipVal)
Parameters:
avgPrice (float): Average entry price
tp1_val (float): TP1 distance (% or pip)
tp2_val (float): TP2 distance
tp3_val (float): TP3 distance
isForex (bool): Is Forex (pip) mode
pipVal (float): Pip value (for Forex)
Returns: TPVisuals structure
f_calcTPLevels_Short_Unified(avgPrice, tp1_val, tp2_val, tp3_val, isForex, pipVal)
Parameters:
avgPrice (float)
tp1_val (float)
tp2_val (float)
tp3_val (float)
isForex (bool)
pipVal (float)
f_calcSL_Long(avgPrice, level, cfg, trailHigh)
Parameters:
avgPrice (float)
level (int)
cfg (SLConfig)
trailHigh (float)
f_calcSL_Short(avgPrice, level, cfg, trailLow)
Parameters:
avgPrice (float)
level (int)
cfg (SLConfig)
trailLow (float)
f_calcSL_Long_Unified(avgPrice, level, cfg, trailHigh, isForex, pipVal)
Parameters:
avgPrice (float)
level (int)
cfg (SLConfig)
trailHigh (float)
isForex (bool): if true pip based, else % based
pipVal (float): Forex pip value (for Forex mode)
Returns: [sl_fixed, sl_trail] tuple
f_calcSL_Short_Unified(avgPrice, level, cfg, trailLow, isForex, pipVal)
Parameters:
avgPrice (float)
level (int)
cfg (SLConfig)
trailLow (float)
isForex (bool)
pipVal (float)
f_effectiveSL(isLong, slFixed, slTrail)
Parameters:
isLong (bool): True if Long
slFixed (float): Fixed SL
slTrail (float): Trailing SL (can be na)
Returns: Effective SL price
f_calcEquity(walletBalance, totalRealizedPnL, latchedPnL_L, latchedPnL_S, unrealizedTotal)
Parameters:
walletBalance (float)
totalRealizedPnL (float)
latchedPnL_L (float)
latchedPnL_S (float)
unrealizedTotal (float)
f_calcFreeMargin(equity, totalLongNotional, totalShortNotional, leverage)
Parameters:
equity (float)
totalLongNotional (float)
totalShortNotional (float)
leverage (int)
f_availableEquityForLiq(walletBalance, totalRealizedPnL, latchedPnL_L, latchedPnL_S, totalFees, useFee, otherSideNotional, leverage)
Parameters:
walletBalance (float)
totalRealizedPnL (float)
latchedPnL_L (float)
latchedPnL_S (float)
totalFees (float)
useFee (bool)
otherSideNotional (float)
leverage (int)
Returns: Available equity
f_shouldForceFullExit(posNotional, exitAmount, leverage, minThreshold)
Parameters:
posNotional (float): Current position volume
exitAmount (float): Amount to exit
leverage (int): Leverage
minThreshold (float): Minimum position size (USDT)
Returns: true if full close required
f_calcExitPnL(isLong, avgPrice, exitPrice, exitAmount)
Parameters:
isLong (bool): Is Long
avgPrice (float): Average price
exitPrice (float): Exit price
exitAmount (float): Exit amount
Returns: PnL value
f_isApproachingSL(isLong, priceExtreme, slPrice, avgPrice, approachPct)
Parameters:
isLong (bool): Is Long
priceExtreme (float): Low (Long) or High (Short)
slPrice (float): SL price
avgPrice (float): Average price
approachPct (float): Approach threshold percentage
Returns: true if approaching
f_isApproachingLiq(isLong, priceExtreme, liqPrice, avgPrice, approachPct)
Parameters:
isLong (bool)
priceExtreme (float)
liqPrice (float)
avgPrice (float)
approachPct (float)
f_isApproachingSL_Unified(isLong, priceExtreme, slPrice, avgPrice, approachVal, isForex, pipVal)
Parameters:
isLong (bool)
priceExtreme (float)
slPrice (float)
avgPrice (float)
approachVal (float)
isForex (bool)
pipVal (float)
f_isApproachingLiq_Unified(isLong, priceExtreme, liqPrice, avgPrice, approachVal, isForex, pipVal)
Parameters:
isLong (bool)
priceExtreme (float)
liqPrice (float)
avgPrice (float)
approachVal (float)
isForex (bool)
pipVal (float)
f_forexUsedMargin(lots, price, contractSize, leverage)
Parameters:
lots (float): Lot amount
price (float): Price
contractSize (float): Contract size
leverage (int): Leverage
Returns: Used margin (USD)
f_forexFreeMargin(equity, usedMarginL, usedMarginS)
Parameters:
equity (float)
usedMarginL (float)
usedMarginS (float)
f_forexPnL(isLong, entryPrice, exitPrice, lots, contractSize, pipVal)
Parameters:
isLong (bool): Is Long
entryPrice (float): Entry price
exitPrice (float): Exit price
lots (float): Lot amount
contractSize (float): Contract size
pipVal (float): Pip value
Returns: PnL (USD)
f_calcPivots(method, h, l, c)
Parameters:
method (string): Pivot method ('Geleneksel', 'Fibonacci', 'Woodie', 'Camarilla')
h (float): Previous High
l (float): Previous Low
c (float): Previous Close
Returns: [PP, R1, R2, R3, S1, S2, S3]
f_getPrice(inlinePrice, currentClose)
Parameters:
inlinePrice (float)
currentClose (float)
f_stackOffset(h, l)
Parameters:
h (float)
l (float)
TPConfig
Fields:
tp1_pct (series float)
tp1_port (series float)
tp1_reverse (series bool)
tp2_active (series bool)
tp2_pct (series float)
tp2_port (series float)
tp3_active (series bool)
tp3_pct (series float)
tp3_port (series float)
DCATPConfig
Fields:
tp1_pct (series float)
tp1_port (series float)
tp2_pct (series float)
tp2_port (series float)
tp3_pct (series float)
tp3_port (series float)
SLConfig
Fields:
l1_pct (series float)
dca_pct (series float)
useBE (series bool)
be_act_pct (series float)
be_offset_pct (series float)
useTS (series bool)
ts_act_pct (series float)
ts_dev_pct (series float)
PositionConfig
Fields:
baseAmount (series float)
leverage (series int)
maxLevel (series int)
dcaMode (series string)
selectionStep (series int)
useFee (series bool)
feePercent (series float)
PositionState
Fields:
level (series int)
signalCounter (series int)
avgPrice (series float)
lastEntryPrice (series float)
totalNotional (series float)
peakNotional (series float)
pctLeft (series float)
tpStage (series int)
tpStageDCA (series int)
accumulatedPnL (series float)
TradeStats
Fields:
slCountWin (series int)
slCountLoss (series int)
liqCount (series int)
maxDcaHit (series int)
maxVol (series float)
maxLoss (series float)
grossLoss (series float)
totalFees (series float)
totalVolume (series float)
tradeCount (series int)
peakEquity (series float)
maxDrawdown (series float)
maxDrawdownPct (series float)
currentDrawdownPct (series float)
approachSL (series int)
approachLiq (series int)
TPVisuals
Fields:
tp1 (series float)
tp2 (series float)
tp3 (series float)
SLState
Fields:
slFixed (series float)
slTrail (series float)
trailExtreme (series float)
ForexConfig
Fields:
pipValue (series float)
contractSize (series float)
baseLot (series float)
isForex (series bool)
릴리즈 노트
v2파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.