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)
Biblioteca Pine
Fiel al espíritu de TradingView, el autor ha publicado este código de Pine como biblioteca de código abierto, para que otros programadores de nuestra comunidad puedan reutilizarlo. ¡Enhorabuena al autor! Puede usar esta biblioteca de forma privada o en otras publicaciones de código abierto, pero su reutilización en publicaciones está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Biblioteca Pine
Fiel al espíritu de TradingView, el autor ha publicado este código de Pine como biblioteca de código abierto, para que otros programadores de nuestra comunidad puedan reutilizarlo. ¡Enhorabuena al autor! Puede usar esta biblioteca de forma privada o en otras publicaciones de código abierto, pero su reutilización en publicaciones está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.