PINE LIBRARY
Cập nhật TradingHelperLib

Library "TradingHelperLib"
Trading Helper Library - Limit order, pip calculation and utility functions for trading bots
f_pipValue()
Calculates pip value based on symbol info
Returns: Pip value
f_pipsToPrice(pips)
Converts pip count to price difference
Parameters:
pips (float): Number of pips
Returns: Price difference
calcExpireBarCount(minutesToExpire)
Converts minutes to bar count based on timeframe
Parameters:
minutesToExpire (float): Duration in minutes
Returns: Bar count
calcLimitPrice(isLong, signalPrice, deviation, deviationType)
Calculates limit order price with deviation
Parameters:
isLong (bool): True for long, false for short
signalPrice (float): Signal price
deviation (float): Deviation amount
deviationType (string): Deviation type ("USDT" or "%")
Returns: Limit price
checkLimitFill(isLong, limitPrice)
Checks if limit order is filled
Parameters:
isLong (bool): True for long, false for short
limitPrice (float): Limit price to check
Returns: True if filled
f_multiplier(lvl, mode)
Calculates DCA multiplier based on level and mode
Parameters:
lvl (int): DCA level
mode (string): Multiplier mode ("Sabit", "Fibonacci", "Martingale", etc.)
Returns: Multiplier value
f_pctToPrice(pct, basePrice)
Converts percentage value to price difference
Parameters:
pct (float): Percentage value (e.g. 2.0 = 2%)
basePrice (float): Reference price
Returns: Price difference
f_priceChange_toPct(priceChange, basePrice)
Converts price change to percentage
Parameters:
priceChange (float): Price difference
basePrice (float): Reference price
Returns: Percentage value
calcMargin(notional, leverage)
Calculates margin from notional value
Parameters:
notional (float): Trade size (e.g. $1000)
leverage (int): Leverage value (e.g. 100)
Returns: Margin value
calcNotional(margin, leverage)
Calculates notional from margin
Parameters:
margin (float): Collateral value
leverage (int): Leverage value
Returns: Notional value
calcLiqPriceLongSimple(avgPrice, leverage)
Calculates simple liquidation price for Long position
Parameters:
avgPrice (float): Average entry price
leverage (int): Leverage value
Returns: Estimated liquidation price
calcLiqPriceShortSimple(avgPrice, leverage)
Calculates simple liquidation price for Short position
Parameters:
avgPrice (float): Average entry price
leverage (int): Leverage value
Returns: Estimated liquidation price
calcPnlLong(entryPrice, currentPrice, notional)
Calculates Long position PNL
Parameters:
entryPrice (float): Entry price
currentPrice (float): Current price
notional (float): Position size
Returns: PNL value
calcPnlShort(entryPrice, currentPrice, notional)
Calculates Short position PNL
Parameters:
entryPrice (float): Entry price
currentPrice (float): Current price
notional (float): Position size
Returns: PNL value
calcFee(notional, feeRate)
Calculates trading fee
Parameters:
notional (float): Trade size
feeRate (float): Fee rate in percentage (e.g. 0.1 = 0.1%)
Returns: Fee value
Trading Helper Library - Limit order, pip calculation and utility functions for trading bots
f_pipValue()
Calculates pip value based on symbol info
Returns: Pip value
f_pipsToPrice(pips)
Converts pip count to price difference
Parameters:
pips (float): Number of pips
Returns: Price difference
calcExpireBarCount(minutesToExpire)
Converts minutes to bar count based on timeframe
Parameters:
minutesToExpire (float): Duration in minutes
Returns: Bar count
calcLimitPrice(isLong, signalPrice, deviation, deviationType)
Calculates limit order price with deviation
Parameters:
isLong (bool): True for long, false for short
signalPrice (float): Signal price
deviation (float): Deviation amount
deviationType (string): Deviation type ("USDT" or "%")
Returns: Limit price
checkLimitFill(isLong, limitPrice)
Checks if limit order is filled
Parameters:
isLong (bool): True for long, false for short
limitPrice (float): Limit price to check
Returns: True if filled
f_multiplier(lvl, mode)
Calculates DCA multiplier based on level and mode
Parameters:
lvl (int): DCA level
mode (string): Multiplier mode ("Sabit", "Fibonacci", "Martingale", etc.)
Returns: Multiplier value
f_pctToPrice(pct, basePrice)
Converts percentage value to price difference
Parameters:
pct (float): Percentage value (e.g. 2.0 = 2%)
basePrice (float): Reference price
Returns: Price difference
f_priceChange_toPct(priceChange, basePrice)
Converts price change to percentage
Parameters:
priceChange (float): Price difference
basePrice (float): Reference price
Returns: Percentage value
calcMargin(notional, leverage)
Calculates margin from notional value
Parameters:
notional (float): Trade size (e.g. $1000)
leverage (int): Leverage value (e.g. 100)
Returns: Margin value
calcNotional(margin, leverage)
Calculates notional from margin
Parameters:
margin (float): Collateral value
leverage (int): Leverage value
Returns: Notional value
calcLiqPriceLongSimple(avgPrice, leverage)
Calculates simple liquidation price for Long position
Parameters:
avgPrice (float): Average entry price
leverage (int): Leverage value
Returns: Estimated liquidation price
calcLiqPriceShortSimple(avgPrice, leverage)
Calculates simple liquidation price for Short position
Parameters:
avgPrice (float): Average entry price
leverage (int): Leverage value
Returns: Estimated liquidation price
calcPnlLong(entryPrice, currentPrice, notional)
Calculates Long position PNL
Parameters:
entryPrice (float): Entry price
currentPrice (float): Current price
notional (float): Position size
Returns: PNL value
calcPnlShort(entryPrice, currentPrice, notional)
Calculates Short position PNL
Parameters:
entryPrice (float): Entry price
currentPrice (float): Current price
notional (float): Position size
Returns: PNL value
calcFee(notional, feeRate)
Calculates trading fee
Parameters:
notional (float): Trade size
feeRate (float): Fee rate in percentage (e.g. 0.1 = 0.1%)
Returns: Fee value
Phát hành các Ghi chú
v2Eklendi:
f_checkTPHit(curPrice, tpPrice, isLong, isActive)
Checks if TP price is hit
Parameters:
curPrice (float)
tpPrice (float)
isLong (bool)
isActive (bool)
f_calcSLPriceLong(avgPrice, slPct)
Calculates SL price for Long position
Parameters:
avgPrice (float)
slPct (float)
f_calcSLPriceShort(avgPrice, slPct)
Calculates SL price for Short position
Parameters:
avgPrice (float)
slPct (float)
f_calcBEPrice(avgPrice, beOffsetPct, isLong)
Calculates Breakeven price
Parameters:
avgPrice (float)
beOffsetPct (float)
isLong (bool)
f_checkBEActivation(trailPrice, avgPrice, beActPct, isLong)
Checks if BE activation condition is met
Parameters:
trailPrice (float)
avgPrice (float)
beActPct (float)
isLong (bool)
f_checkTSActivation(trailPrice, avgPrice, tsActPct, isLong)
Checks if TS activation condition is met
Parameters:
trailPrice (float)
avgPrice (float)
tsActPct (float)
isLong (bool)
f_calcTSValue(trailPrice, avgPrice, tsActPct, tsDevPct, isLong)
Calculates Trailing Stop value
Parameters:
trailPrice (float)
avgPrice (float)
tsActPct (float)
tsDevPct (float)
isLong (bool)
f_calcLiqPriceAdvanced(availableEquity, totalNotional, avgPrice, isLong)
Calculates Liquidation price
Parameters:
availableEquity (float)
totalNotional (float)
avgPrice (float)
isLong (bool)
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.