PINE LIBRARY
Lib_SW_Alerts

Library "Lib_SW_Alerts"
buildCode(action, cfg)
Parameters:
action (string): Action code (e.g., 'ENTER-LONG', 'EXIT-SHORT', etc.)
cfg (BotConfig): Bot configuration
Returns: Formatted code string
buildMPTPSL(tpsl)
Parameters:
tpsl (AlertTPSL): TP/SL configuration
Returns: JSON string (,"takeProfits":[...],"stopLoss":{...})
enterLong(cfg, amount, tpsl)
Parameters:
cfg (BotConfig): Bot configuration
amount (float): Trade amount (USDT)
tpsl (AlertTPSL): TP/SL configuration (for MP mode, if na not added)
Returns: JSON string
enterShort(cfg, amount, tpsl)
Parameters:
cfg (BotConfig): Bot configuration
amount (float): Trade amount (USDT)
tpsl (AlertTPSL): TP/SL configuration (for MP mode)
Returns: JSON string
exitLong(cfg)
Parameters:
cfg (BotConfig): Bot configuration
Returns: JSON string
exitShort(cfg)
Parameters:
cfg (BotConfig): Bot configuration
Returns: JSON string
exitLongPartial(cfg, totalNotional, pctClose)
Parameters:
cfg (BotConfig): Bot configuration
totalNotional (float): Current total position volume
pctClose (float): Percentage to close (100 = full)
Returns: JSON string
exitShortPartial(cfg, totalNotional, pctClose)
Parameters:
cfg (BotConfig): Bot configuration
totalNotional (float): Current total position volume
pctClose (float): Percentage to close
Returns: JSON string
buildTPSL_Normal(tp1_pct, tp1_port, tp2_pct, tp2_port, tp3_pct, tp3_port, sl_pct)
Parameters:
tp1_pct (float)
tp1_port (float)
tp2_pct (float)
tp2_port (float)
tp3_pct (float)
tp3_port (float)
sl_pct (float)
buildTPSL_DCA(dca_tp1_pct, dca_tp1_port, dca_tp2_pct, dca_tp2_port, dca_tp3_pct, dca_tp3_port, dca_sl_pct)
Parameters:
dca_tp1_pct (float)
dca_tp1_port (float)
dca_tp2_pct (float)
dca_tp2_port (float)
dca_tp3_pct (float)
dca_tp3_port (float)
dca_sl_pct (float)
selectTPSL(level, normalTPSL, dcaTPSL)
Parameters:
level (int): Current DCA level
normalTPSL (AlertTPSL): Normal entry TP/SL
dcaTPSL (AlertTPSL): DCA entry TP/SL
Returns: Appropriate AlertTPSL
formatPnL(pnl)
Parameters:
pnl (float): PnL value
Returns: Formatted string
formatPct(pct)
Parameters:
pct (float): Percentage value
Returns: Formatted string
formatPrice(price)
Parameters:
price (float): Price value
Returns: Formatted string
buildEntryLabel(isLong, level, price, amount, leverage)
Parameters:
isLong (bool): Is Long
level (int): DCA level
price (float): Entry price
amount (float): Trade amount
leverage (int): Leverage
Returns: (emoji) Level - price - amount
buildTPLabel(isLong, tpNum, price, pnl, isDCA)
Parameters:
isLong (bool): Is Long
tpNum (int): TP number (1, 2, 3)
price (float): Exit price
pnl (float): PnL value
isDCA (bool): Is DCA TP
Returns: Formatted label string
buildSLLabel(isLong, price, pnl, isTrailing)
Parameters:
isLong (bool)
price (float)
pnl (float)
isTrailing (bool)
buildForceExitLabel(isLong, price, pnl)
Parameters:
isLong (bool)
price (float)
pnl (float)
buildSwingLabel(isLong, price, pnl)
Parameters:
isLong (bool)
price (float)
pnl (float)
swb_secretPart(cfg)
Parameters:
cfg (SWBotConfig)
swb_base(cfg, action)
Parameters:
cfg (SWBotConfig): SWBot configuration
action (string): Action type ('BUY', 'SELL', 'CLOSE_LONG', etc.)
Returns: JSON start
swb_buy(cfg, lotSize, slPrice)
Parameters:
cfg (SWBotConfig): SWBot configuration
lotSize (float): Lot amount
slPrice (float): SL price (if na, SL not added)
Returns: JSON string
swb_sell(cfg, lotSize, slPrice)
Parameters:
cfg (SWBotConfig): SWBot configuration
lotSize (float): Lot amount
slPrice (float): SL price (if na, SL not added)
Returns: JSON string
swb_buy_tpsl(cfg, lotSize, slPips, tpPips)
Parameters:
cfg (SWBotConfig)
lotSize (float)
slPips (float): SL distance (pips)
tpPips (float): TP distance (pips)
Returns: JSON string
swb_sell_tpsl(cfg, lotSize, slPips, tpPips)
Parameters:
cfg (SWBotConfig)
lotSize (float)
slPips (float)
tpPips (float)
swb_closeLong(cfg)
Parameters:
cfg (SWBotConfig)
swb_closeShort(cfg)
Parameters:
cfg (SWBotConfig)
swb_closeLongPartial(cfg, lotToClose)
Parameters:
cfg (SWBotConfig)
lotToClose (float): Lot amount to close
swb_closeShortPartial(cfg, lotToClose)
Parameters:
cfg (SWBotConfig)
lotToClose (float)
swb_amendLong(cfg, slPrice, tpPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float): New SL price
tpPrice (float): New TP price
swb_amendShort(cfg, slPrice, tpPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float)
tpPrice (float)
swb_amendSLLong(cfg, slPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float)
swb_amendSLShort(cfg, slPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float)
swb_amendTrailingLong(cfg, slPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float): SL price (broker trailing start point)
swb_amendTrailingShort(cfg, slPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float)
exchA_openLong(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigA): configuration
qtyInCoin (float): Trade amount in Coin
exchA_openShort(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigA)
qtyInCoin (float)
exchA_closeLong(cfg)
Parameters:
cfg (ExchangeConfigA)
exchA_closeShort(cfg)
Parameters:
cfg (ExchangeConfigA)
exchA_closeLongPartial(cfg, pct)
Parameters:
cfg (ExchangeConfigA)
pct (float)
exchA_closeShortPartial(cfg, pct)
Parameters:
cfg (ExchangeConfigA)
pct (float)
exchB_base(cfg)
Parameters:
cfg (ExchangeConfigB)
exchB_openLong(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigB)
qtyInCoin (float)
exchB_openShort(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigB)
qtyInCoin (float)
exchB_closeLong(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigB)
qtyInCoin (float)
exchB_closeShort(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigB)
qtyInCoin (float)
exchB_closeLongPartial(cfg, partialQty)
Parameters:
cfg (ExchangeConfigB)
partialQty (float)
exchB_closeShortPartial(cfg, partialQty)
Parameters:
cfg (ExchangeConfigB)
partialQty (float)
BotConfig
Fields:
exchangeName (series string)
symbolInput (series string)
botName (series string)
tfStr (series string)
botID (series string)
useMultiPair (series bool)
leverage (series int)
AlertTPSL
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)
sl_pct (series float)
SWBotConfig
Fields:
licenseKey (series string)
secretKey (series string)
symbol (series string)
pipValue (series float)
contractSize (series float)
useBrokerTPSL (series bool)
useMultiPos (series bool)
ExchangeConfigA
Fields:
symbol (series string)
strategyId (series string)
maxLag (series int)
ExchangeConfigB
Fields:
symbol (series string)
signalId (series string)
uid (series string)
positionSide (series string)
buildCode(action, cfg)
Parameters:
action (string): Action code (e.g., 'ENTER-LONG', 'EXIT-SHORT', etc.)
cfg (BotConfig): Bot configuration
Returns: Formatted code string
buildMPTPSL(tpsl)
Parameters:
tpsl (AlertTPSL): TP/SL configuration
Returns: JSON string (,"takeProfits":[...],"stopLoss":{...})
enterLong(cfg, amount, tpsl)
Parameters:
cfg (BotConfig): Bot configuration
amount (float): Trade amount (USDT)
tpsl (AlertTPSL): TP/SL configuration (for MP mode, if na not added)
Returns: JSON string
enterShort(cfg, amount, tpsl)
Parameters:
cfg (BotConfig): Bot configuration
amount (float): Trade amount (USDT)
tpsl (AlertTPSL): TP/SL configuration (for MP mode)
Returns: JSON string
exitLong(cfg)
Parameters:
cfg (BotConfig): Bot configuration
Returns: JSON string
exitShort(cfg)
Parameters:
cfg (BotConfig): Bot configuration
Returns: JSON string
exitLongPartial(cfg, totalNotional, pctClose)
Parameters:
cfg (BotConfig): Bot configuration
totalNotional (float): Current total position volume
pctClose (float): Percentage to close (100 = full)
Returns: JSON string
exitShortPartial(cfg, totalNotional, pctClose)
Parameters:
cfg (BotConfig): Bot configuration
totalNotional (float): Current total position volume
pctClose (float): Percentage to close
Returns: JSON string
buildTPSL_Normal(tp1_pct, tp1_port, tp2_pct, tp2_port, tp3_pct, tp3_port, sl_pct)
Parameters:
tp1_pct (float)
tp1_port (float)
tp2_pct (float)
tp2_port (float)
tp3_pct (float)
tp3_port (float)
sl_pct (float)
buildTPSL_DCA(dca_tp1_pct, dca_tp1_port, dca_tp2_pct, dca_tp2_port, dca_tp3_pct, dca_tp3_port, dca_sl_pct)
Parameters:
dca_tp1_pct (float)
dca_tp1_port (float)
dca_tp2_pct (float)
dca_tp2_port (float)
dca_tp3_pct (float)
dca_tp3_port (float)
dca_sl_pct (float)
selectTPSL(level, normalTPSL, dcaTPSL)
Parameters:
level (int): Current DCA level
normalTPSL (AlertTPSL): Normal entry TP/SL
dcaTPSL (AlertTPSL): DCA entry TP/SL
Returns: Appropriate AlertTPSL
formatPnL(pnl)
Parameters:
pnl (float): PnL value
Returns: Formatted string
formatPct(pct)
Parameters:
pct (float): Percentage value
Returns: Formatted string
formatPrice(price)
Parameters:
price (float): Price value
Returns: Formatted string
buildEntryLabel(isLong, level, price, amount, leverage)
Parameters:
isLong (bool): Is Long
level (int): DCA level
price (float): Entry price
amount (float): Trade amount
leverage (int): Leverage
Returns: (emoji) Level - price - amount
buildTPLabel(isLong, tpNum, price, pnl, isDCA)
Parameters:
isLong (bool): Is Long
tpNum (int): TP number (1, 2, 3)
price (float): Exit price
pnl (float): PnL value
isDCA (bool): Is DCA TP
Returns: Formatted label string
buildSLLabel(isLong, price, pnl, isTrailing)
Parameters:
isLong (bool)
price (float)
pnl (float)
isTrailing (bool)
buildForceExitLabel(isLong, price, pnl)
Parameters:
isLong (bool)
price (float)
pnl (float)
buildSwingLabel(isLong, price, pnl)
Parameters:
isLong (bool)
price (float)
pnl (float)
swb_secretPart(cfg)
Parameters:
cfg (SWBotConfig)
swb_base(cfg, action)
Parameters:
cfg (SWBotConfig): SWBot configuration
action (string): Action type ('BUY', 'SELL', 'CLOSE_LONG', etc.)
Returns: JSON start
swb_buy(cfg, lotSize, slPrice)
Parameters:
cfg (SWBotConfig): SWBot configuration
lotSize (float): Lot amount
slPrice (float): SL price (if na, SL not added)
Returns: JSON string
swb_sell(cfg, lotSize, slPrice)
Parameters:
cfg (SWBotConfig): SWBot configuration
lotSize (float): Lot amount
slPrice (float): SL price (if na, SL not added)
Returns: JSON string
swb_buy_tpsl(cfg, lotSize, slPips, tpPips)
Parameters:
cfg (SWBotConfig)
lotSize (float)
slPips (float): SL distance (pips)
tpPips (float): TP distance (pips)
Returns: JSON string
swb_sell_tpsl(cfg, lotSize, slPips, tpPips)
Parameters:
cfg (SWBotConfig)
lotSize (float)
slPips (float)
tpPips (float)
swb_closeLong(cfg)
Parameters:
cfg (SWBotConfig)
swb_closeShort(cfg)
Parameters:
cfg (SWBotConfig)
swb_closeLongPartial(cfg, lotToClose)
Parameters:
cfg (SWBotConfig)
lotToClose (float): Lot amount to close
swb_closeShortPartial(cfg, lotToClose)
Parameters:
cfg (SWBotConfig)
lotToClose (float)
swb_amendLong(cfg, slPrice, tpPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float): New SL price
tpPrice (float): New TP price
swb_amendShort(cfg, slPrice, tpPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float)
tpPrice (float)
swb_amendSLLong(cfg, slPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float)
swb_amendSLShort(cfg, slPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float)
swb_amendTrailingLong(cfg, slPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float): SL price (broker trailing start point)
swb_amendTrailingShort(cfg, slPrice)
Parameters:
cfg (SWBotConfig)
slPrice (float)
exchA_openLong(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigA): configuration
qtyInCoin (float): Trade amount in Coin
exchA_openShort(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigA)
qtyInCoin (float)
exchA_closeLong(cfg)
Parameters:
cfg (ExchangeConfigA)
exchA_closeShort(cfg)
Parameters:
cfg (ExchangeConfigA)
exchA_closeLongPartial(cfg, pct)
Parameters:
cfg (ExchangeConfigA)
pct (float)
exchA_closeShortPartial(cfg, pct)
Parameters:
cfg (ExchangeConfigA)
pct (float)
exchB_base(cfg)
Parameters:
cfg (ExchangeConfigB)
exchB_openLong(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigB)
qtyInCoin (float)
exchB_openShort(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigB)
qtyInCoin (float)
exchB_closeLong(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigB)
qtyInCoin (float)
exchB_closeShort(cfg, qtyInCoin)
Parameters:
cfg (ExchangeConfigB)
qtyInCoin (float)
exchB_closeLongPartial(cfg, partialQty)
Parameters:
cfg (ExchangeConfigB)
partialQty (float)
exchB_closeShortPartial(cfg, partialQty)
Parameters:
cfg (ExchangeConfigB)
partialQty (float)
BotConfig
Fields:
exchangeName (series string)
symbolInput (series string)
botName (series string)
tfStr (series string)
botID (series string)
useMultiPair (series bool)
leverage (series int)
AlertTPSL
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)
sl_pct (series float)
SWBotConfig
Fields:
licenseKey (series string)
secretKey (series string)
symbol (series string)
pipValue (series float)
contractSize (series float)
useBrokerTPSL (series bool)
useMultiPos (series bool)
ExchangeConfigA
Fields:
symbol (series string)
strategyId (series string)
maxLag (series int)
ExchangeConfigB
Fields:
symbol (series string)
signalId (series string)
uid (series string)
positionSide (series string)
Bibliothèque Pine
Dans l'esprit TradingView, l'auteur a publié ce code Pine sous forme de bibliothèque open source afin que d'autres programmeurs Pine de notre communauté puissent le réutiliser. Bravo à l'auteur! Vous pouvez utiliser cette bibliothèque à titre privé ou dans d'autres publications open source, mais la réutilisation de ce code dans des publications est régie par nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Bibliothèque Pine
Dans l'esprit TradingView, l'auteur a publié ce code Pine sous forme de bibliothèque open source afin que d'autres programmeurs Pine de notre communauté puissent le réutiliser. Bravo à l'auteur! Vous pouvez utiliser cette bibliothèque à titre privé ou dans d'autres publications open source, mais la réutilisation de ce code dans des publications est régie par nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.