PINE LIBRARY

libKageBot

Updated
Library "libKageBot"
Library of function to generate command strings for bots FrostyBot and Zignally. This version ONLY WORKS WITH FROSTYBOT.

strSize(_sizePercent, _sizeCurrency)
  Converts a float to a formated string suitable to position size in percentage or currency. At leaste one parameter must be given
  Parameters:
    _sizePercent: (float) Position size in percent value. Optional. Default = na. Mandatory if _sizeCurrency is not given.
    _sizeCurrency: (float) Position size in currency value. Optional. Default = na. Mandatory if _sizePercent is not given.
  Returns: (string) A formated string containing the position size

entry(_bot, _direction, _sizePercent, _sizeCurrency)
  Generates a simple entry command string for a bot
  Parameters:
    _bot: (TradeBot) Previously instancied bot type variable
    _direction: (string) Flag to opena long or a short position. Must be either DIRECTION_LONG or DIRECTION_SHORT constant
    _sizePercent: (float) Position size in percent value. Optional. Default = na. Mandatory if _sizeCurrency is not given.
    _sizeCurrency: (float) Position size in currency value. Optional. Default = na. Mandatory if _sizePercent is not given.
  Returns: (string) A string of a simple open position command

exit(_bot, _sizePercent, _sizeCurrency, _reduce)
  Generates a simple exit command string for a bot
  Parameters:
    _bot: (TradeBot) Previously instancied bot type variable
    _sizePercent: (float) Position size in percent value. Optional. Default = na. Mandatory if _sizeCurrency is not given.
    _sizeCurrency: (float) Position size in currency value. Optional. Default = na. Mandatory if _sizePercent is not given.
    _reduce: (bool) Flag to use Ruce Only option on Binance positions. Optional. Default = true
  Returns: (string) A string of a simple close position command

cancelAll(_bot)
  Generates a command string for a bot that cancels all open orders
  Parameters:
    _bot: (TradeBot) Previously instancied bot type variable
  Returns: (string) A string of a command to cancel all open orders

leverage(_bot, _leverage, _type)
  Generates a command string for a bot to set leverage
  Parameters:
    _bot: (TradeBot) Previously instancied bot type variable
    _leverage: (int) The amount of leverage to be used when opening a position. Optional. If does not given, the bot's default will be used
    _type: (string) Type of leverage. Must be either LEVERAGE_CROSS or LEVERAGE_ISOLATED. Optional. Default is LEVERAGE_CROSS.
  Returns: (string) A string of a simple leverage command

entryLong(_bot, _leverage, _leverageType, _sizePercent, _sizeCurrency)
  Generates a complete long entry command string for a bot
  Parameters:
    _bot: (TradeBot) Previously instancied bot type variable
    _leverage: (int) The amount of leverage to be used when opening a position. Optional. If does not given, the bot's default will be used
    _leverageType: (string) Type of leverage. Must be either LEVERAGE_CROSS or LEVERAGE_ISOLATED. Optional. Default is LEVERAGE_CROSS.
    _sizePercent: (float) Position size in percent value. Optional. Default = na. Mandatory if _sizeCurrency is not given.
    _sizeCurrency: (float) Position size in currency value. Optional. Default = na. Mandatory if _sizePercent is not given.
  Returns: (string) A string of a complete open long position command

entryShort(_bot, _leverage, _leverageType, _sizePercent, _sizeCurrency)
  Generates a complete short entry command string for a bot
  Parameters:
    _bot: (TradeBot) Previously instancied bot type variable
    _leverage: (int) The amount of leverage to be used when opening a position. Optional. If does not given, the bot's default will be used
    _leverageType
    _sizePercent: (float) Position size in percent value. Optional. Default = na. Mandatory if _sizeCurrency is not given.
    _sizeCurrency: (float) Position size in currency value. Optional. Default = na. Mandatory if _sizePercent is not given.
  Returns: (string) A string of a complete open short position command

exitPosition(_bot, _sizePercent, _sizeCurrency, _reduce)
  Generates a complete close position command string for a bot
  Parameters:
    _bot: (TradeBot) Previously instancied bot type variable
    _sizePercent: (float) Position size in percent value. Optional. Default = na. Mandatory if _sizeCurrency is not given.
    _sizeCurrency: (float) Position size in currency value. Optional. Default = na. Mandatory if _sizePercent is not given.
    _reduce: (bool) Flag to use Ruce Only option on Binance positions. Optional. Default = true
  Returns: (string) A string of a comlete close position command

printBot(_bot, _command)
  Print bot's information for debug purposes
  Parameters:
    _bot: (TradeBot) Previously instancied bot type variable
    _command: (string) A command string to be debugged
  Returns: Nothing.

Constants
  Constants to be used in both in internal and external code
  Fields:
    SERVER_FROSTBOT: (string) Identifier to FrostyBot
    SERVER_ZIGNALY: (string) Identifier to Zignaly
    DIRECTION_LONG: (string) Flag to open a long position
    DIRECTION_SHORT
    LEVERAGE_CROSS: (string) Flag to set leverage to cross
    LEVERAGE_ISOLATED: (string) Flag to set leverage to isolated

TradeBot
  Bot type to handle its essential information
  Fields:
    server: (string) Type o server. Must me one of the SERVER_* constant values
    id: (string) Id of the account in the server (Stub for FrostyBot or Key to Zignally)
    symbol: (string) Symbol of the pair to be negotiated (example: ETH/USDT)
    leverage: (int) Leverage coeficient. Default is 1
Release Notes
v2

Updated:
Constants
  Constants to be used in both in internal and external code
  Fields:
    SERVER_FROSTBOT: (string) Identifier to FrostyBot
    SERVER_ZIGNALY: (string) Identifier to Zignaly
    DIRECTION_LONG: (string) Flag to open a long position
    DIRECTION_SHORT: (string) Flag to open a short position
    LEVERAGE_CROSS: (string) Flag to set leverage to cross
    LEVERAGE_ISOLATED: (string) Flag to set leverage to isolated

TradeBot
  Bot type to handle bot's essential information
  Fields:
    server: (string) Type o server. Must me one of the SERVER_* constant values
    id: (string) Id of the account in the server (Stub for FrostyBot or Key to Zignally)
    symbol: (string) Symbol of the pair to be negotiated (example: ETH/USDT)
    leverage: (int) Leverage coeficient. Default is 1
automationbotsstrategies

Pine library

In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House rules.

Disclaimer