PINE LIBRARY

TRADING

Обновлено
Library "TRADING"
This library is a client script for making a webhook signal formatted string to PoABOT server.

entry_message(password, percent, leverage, margin_mode, kis_number)
  Create a entry message for POABOT
  Parameters:
    password (string): (string) [Required] The password of your bot.
    percent (float): (float) [Optional] The percent for entry based on your wallet balance.
    leverage (int): (int) [Optional] The leverage of entry. If not set, your levereage doesn't change.
    margin_mode (string): (string) [Optional] The margin mode for trade(only for OKX). "cross" or "isolated"
    kis_number (int): (int) [Optional] The number of koreainvestment account. Default 1
  Returns: (string) A json formatted string for webhook message.

order_message(password, percent, leverage, margin_mode, kis_number)
  Create a order message for POABOT
  Parameters:
    password (string): (string) [Required] The password of your bot.
    percent (float): (float) [Optional] The percent for entry based on your wallet balance.
    leverage (int): (int) [Optional] The leverage of entry. If not set, your levereage doesn't change.
    margin_mode (string): (string) [Optional] The margin mode for trade(only for OKX). "cross" or "isolated"
    kis_number (int): (int) [Optional] The number of koreainvestment account. Default 1
  Returns: (string) A json formatted string for webhook message.

close_message(password, percent, margin_mode, kis_number)
  Create a close message for POABOT
  Parameters:
    password (string): (string) [Required] The password of your bot.
    percent (float): (float) [Optional] The percent for close based on your wallet balance.
    margin_mode (string): (string) [Optional] The margin mode for trade(only for OKX). "cross" or "isolated"
    kis_number (int): (int) [Optional] The number of koreainvestment account. Default 1
  Returns: (string) A json formatted string for webhook message.

exit_message(password, percent, margin_mode, kis_number)
  Create a exit message for POABOT
  Parameters:
    password (string): (string) [Required] The password of your bot.
    percent (float): (float) [Optional] The percent for exit based on your wallet balance.
    margin_mode (string): (string) [Optional] The margin mode for trade(only for OKX). "cross" or "isolated"
    kis_number (int): (int) [Optional] The number of koreainvestment account. Default 1
  Returns: (string) A json formatted string for webhook message.

manual_message(password, exchange, base, quote, side, qty, price, percent, leverage, margin_mode, kis_number, order_name)
  Create a manual message for POABOT
  Parameters:
    password (string): (string) [Required] The password of your bot.
    exchange (string): (string) [Required] The exchange
    base (string): (string) [Required] The base
    quote (string): (string) [Required] The quote of order message
    side (string): (string) [Required] The side of order messsage
    qty (float): (float) [Optional] The qty of order message
    price (float): (float) [Optional] The price of order message
    percent (float): (float) [Optional] The percent for order based on your wallet balance.
    leverage (int): (int) [Optional] The leverage of entry. If not set, your levereage doesn't change.
    margin_mode (string): (string) [Optional] The margin mode for trade(only for OKX). "cross" or "isolated"
    kis_number (int): (int) [Optional] The number of koreainvestment account.
    order_name (string): (string) [Optional] The name of order message
  Returns: (string) A json formatted string for webhook message.

in_trade(start_time, end_time, hide_trade_line)
  Create a trade start line
  Parameters:
    start_time (int): (int) [Required] The start of time.
    end_time (int): (int) [Required] The end of time.
    hide_trade_line (bool): (bool) [Optional] if true, hide trade line. Default false.
  Returns: (bool) Get bool for trade based on time range.

real_qty(qty, precision, leverage, contract_size, default_qty_type, default_qty_value)
  Get exchange specific real qty
  Parameters:
    qty (float): (float) [Optional] qty
    precision (float): (float) [Optional] precision
    leverage (int): (int) [Optional] leverage
    contract_size (float): (float) [Optional] contract_size
    default_qty_type (string)
    default_qty_value (float)
  Returns: (float) exchange specific qty.

method set(this, password, start_time, end_time, leverage, initial_capital, default_qty_type, default_qty_value, margin_mode, contract_size, kis_number, entry_percent, close_percent, exit_percent, fixed_qty, fixed_cash, real, auto_alert_message, hide_trade_line)
  Set bot object.
  Namespace types: bot
  Parameters:
    this (bot)
    password (string): (string) [Optional] password for poabot.
    start_time (int): (int) [Optional] start_time timestamp.
    end_time (int): (int) [Optional] end_time timestamp.
    leverage (int): (int) [Optional] leverage.
    initial_capital (float)
    default_qty_type (string)
    default_qty_value (float)
    margin_mode (string): (string) [Optional] The margin mode for trade(only for OKX). "cross" or "isolated"
    contract_size (float)
    kis_number (int): (int) [Optional] kis_number for poabot.
    entry_percent (float): (float) [Optional] entry_percent for poabot.
    close_percent (float): (float) [Optional] close_percent for poabot.
    exit_percent (float): (float) [Optional] exit_percent for poabot.
    fixed_qty (float): (float) [Optional] fixed qty.
    fixed_cash (float): (float) [Optional] fixed cash.
    real (bool): (bool) [Optional] convert qty for exchange specific.
    auto_alert_message (bool): (bool) [Optional] convert alert_message for exchange specific.
    hide_trade_line (bool): (bool) [Optional] if true, Hide trade line. Default false.
  Returns: (void)

method print(this, message)
  Print message using log table.
  Namespace types: bot
  Parameters:
    this (bot)
    message (string)
  Returns: (void)

method start_trade(this)
  start trade using start_time and end_time
  Namespace types: bot
  Parameters:
    this (bot)
  Returns: (void)

method entry(this, id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message, when)
  It is a command to enter market position. If an order with the same ID is already pending, it is possible to modify the order. If there is no order with the specified ID, a new order is placed. To deactivate an entry order, the command strategy.cancel or strategy.cancel_all should be used. In comparison to the function strategy.order, the function strategy.entry is affected by pyramiding and it can reverse market position correctly. If both 'limit' and 'stop' parameters are 'NaN', the order type is market order.
  Namespace types: bot
  Parameters:
    this (bot)
    id (string): (string) [Required] A required parameter. The order identifier. It is possible to cancel or modify an order by referencing its identifier.
    direction (string): (string) [Required] A required parameter. Market position direction: 'strategy.long' is for long, 'strategy.short' is for short.
    qty (float): (float) [Optional] An optional parameter. Number of contracts/shares/lots/units to trade. The default value is 'NaN'.
    limit (float): (float) [Optional] An optional parameter. Limit price of the order. If it is specified, the order type is either 'limit', or 'stop-limit'. 'NaN' should be specified for any other order type.
    stop (float): (float) [Optional] An optional parameter. Stop price of the order. If it is specified, the order type is either 'stop', or 'stop-limit'. 'NaN' should be specified for any other order type.
    oca_name (string): (string) [Optional] An optional parameter. Name of the OCA group the order belongs to. If the order should not belong to any particular OCA group, there should be an empty string.
    oca_type (string): (string) [Optional] An optional parameter. Type of the OCA group. The allowed values are: "strategy.oca.none" - the order should not belong to any particular OCA group; "strategy.oca.cancel" - the order should belong to an OCA group, where as soon as an order is filled, all other orders of the same group are cancelled; "strategy.oca.reduce" - the order should belong to an OCA group, where if X number of contracts of an order is filled, number of contracts for each other order of the same OCA group is decreased by X.
    comment (string): (string) [Optional] An optional parameter. Additional notes on the order.
    alert_message (string): (string) [Optional] An optional parameter which replaces the {{strategy.order.alert_message}} placeholder when it is used in the "Create Alert" dialog box's "Message" field.
    when (bool): (bool) [Optional] An optional parmeter. Condition, deprecated.
  Returns: (void)

method order(this, id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message, when)
  It is a command to place order. If an order with the same ID is already pending, it is possible to modify the order. If there is no order with the specified ID, a new order is placed. To deactivate order, the command strategy.cancel or strategy.cancel_all should be used. In comparison to the function strategy.entry, the function strategy.order is not affected by pyramiding. If both 'limit' and 'stop' parameters are 'NaN', the order type is market order.
  Namespace types: bot
  Parameters:
    this (bot)
    id (string): (string) [Required] A required parameter. The order identifier. It is possible to cancel or modify an order by referencing its identifier.
    direction (string): (string) [Required] A required parameter. Market position direction: 'strategy.long' is for long, 'strategy.short' is for short.
    qty (float): (float) [Optional] An optional parameter. Number of contracts/shares/lots/units to trade. The default value is 'NaN'.
    limit (float): (float) [Optional] An optional parameter. Limit price of the order. If it is specified, the order type is either 'limit', or 'stop-limit'. 'NaN' should be specified for any other order type.
    stop (float): (float) [Optional] An optional parameter. Stop price of the order. If it is specified, the order type is either 'stop', or 'stop-limit'. 'NaN' should be specified for any other order type.
    oca_name (string): (string) [Optional] An optional parameter. Name of the OCA group the order belongs to. If the order should not belong to any particular OCA group, there should be an empty string.
    oca_type (string): (string) [Optional] An optional parameter. Type of the OCA group. The allowed values are: "strategy.oca.none" - the order should not belong to any particular OCA group; "strategy.oca.cancel" - the order should belong to an OCA group, where as soon as an order is filled, all other orders of the same group are cancelled; "strategy.oca.reduce" - the order should belong to an OCA group, where if X number of contracts of an order is filled, number of contracts for each other order of the same OCA group is decreased by X.
    comment (string): (string) [Optional] An optional parameter. Additional notes on the order.
    alert_message (string): (string) [Optional] An optional parameter which replaces the {{strategy.order.alert_message}} placeholder when it is used in the "Create Alert" dialog box's "Message" field.
    when (bool): (bool) [Optional] An optional parmeter. Condition, deprecated.
  Returns: (void)

method close_all(this, comment, alert_message, immediately, when)
  Exits the current market position, making it flat.
  Namespace types: bot
  Parameters:
    this (bot)
    comment (string): (string) [Optional] An optional parameter. Additional notes on the order.
    alert_message (string): (string) [Optional] An optional parameter which replaces the {{strategy.order.alert_message}} placeholder when it is used in the "Create Alert" dialog box's "Message" field.
    immediately (bool): (bool) [Optional] An optional parameter. If true, the closing order will be executed on the tick where it has been placed, ignoring the strategy parameters that restrict the order execution to the open of the next bar. The default is false.
    when (bool): (bool) [Optional] An optional parmeter. Condition, deprecated.
  Returns: (void)

method cancel(this, id, when)
  It is a command to cancel/deactivate pending orders by referencing their names, which were generated by the functions: strategy.order, strategy.entry and strategy.exit.
  Namespace types: bot
  Parameters:
    this (bot)
    id (string): (string) [Optional] A required parameter. The order identifier. It is possible to cancel an order by referencing its identifier.
    when (bool): (bool) [Optional] An optional parmeter. Condition, deprecated.
  Returns: (void)

method cancel_all(this, when)
  It is a command to cancel/deactivate all pending orders, which were generated by the functions: strategy.order, strategy.entry and strategy.exit.
  Namespace types: bot
  Parameters:
    this (bot)
    when (bool): (bool) [Optional] An optional parmeter. Condition, deprecated.
  Returns: (void)

method close(this, id, comment, qty, qty_percent, alert_message, immediately, when)
  It is a command to exit from the entry with the specified ID. If there were multiple entry orders with the same ID, all of them are exited at once. If there are no open entries with the specified ID by the moment the command is triggered, the command will not come into effect. The command uses market order. Every entry is closed by a separate market order.
  Namespace types: bot
  Parameters:
    this (bot)
    id (string): (string) [Required] A required parameter. The order identifier. It is possible to close an order by referencing its identifier.
    comment (string): (string) [Optional] An optional parameter. Additional notes on the order.
    qty (float): (float) [Optional] An optional parameter. Number of contracts/shares/lots/units to exit a trade with. The default value is 'NaN'.
    qty_percent (float): (float) [Optional] Defines the percentage (0-100) of the position to close. Its priority is lower than that of the 'qty' parameter. Optional. The default is 100.
    alert_message (string): (string) [Optional] An optional parameter which replaces the {{strategy.order.alert_message}} placeholder when it is used in the "Create Alert" dialog box's "Message" field.
    immediately (bool): (bool) [Optional] An optional parameter. If true, the closing order will be executed on the tick where it has been placed, ignoring the strategy parameters that restrict the order execution to the open of the next bar. The default is false.
    when (bool): (bool) [Optional] An optional parmeter. Condition, deprecated.
  Returns: (void)

ticks_to_price(ticks, from)
  Converts ticks to a price offset from the supplied price or the average entry price.
  Parameters:
    ticks (float): (float) Ticks to convert to a price.
    from (float): (float) A price that can be used to calculate from. Optional. The default value is `strategy.position_avg_price`.
  Returns: (float) A price level that has a distance from the entry price equal to the specified number of ticks.

method exit(this, id, from_entry, qty, qty_percent, profit, limit, loss, stop, trail_price, trail_points, trail_offset, oca_name, comment, comment_profit, comment_loss, comment_trailing, alert_message, alert_profit, alert_loss, alert_trailing, when)
  It is a command to exit either a specific entry, or whole market position. If an order with the same ID is already pending, it is possible to modify the order. If an entry order was not filled, but an exit order is generated, the exit order will wait till entry order is filled and then the exit order is placed. To deactivate an exit order, the command strategy.cancel or strategy.cancel_all should be used. If the function strategy.exit is called once, it exits a position only once. If you want to exit multiple times, the command strategy.exit should be called multiple times. If you use a stop loss and a trailing stop, their order type is 'stop', so only one of them is placed (the one that is supposed to be filled first). If all the following parameters 'profit', 'limit', 'loss', 'stop', 'trail_points', 'trail_offset' are 'NaN', the command will fail. To use market order to exit, the command strategy.close or strategy.close_all should be used.
  Namespace types: bot
  Parameters:
    this (bot)
    id (string): (string) [Required] A required parameter. The order identifier. It is possible to cancel or modify an order by referencing its identifier.
    from_entry (string): (string) [Optional] An optional parameter. The identifier of a specific entry order to exit from it. To exit all entries an empty string should be used. The default values is empty string.
    qty (float): (float) [Optional] An optional parameter. Number of contracts/shares/lots/units to exit a trade with. The default value is 'NaN'.
    qty_percent (float): (float) [Optional] Defines the percentage of (0-100) the position to close. Its priority is lower than that of the 'qty' parameter. Optional. The default is 100.
    profit (float): (float) [Optional] An optional parameter. Profit target (specified in ticks). If it is specified, a limit order is placed to exit market position when the specified amount of profit (in ticks) is reached. The default value is 'NaN'.
    limit (float): (float) [Optional] An optional parameter. Profit target (requires a specific price). If it is specified, a limit order is placed to exit market position at the specified price (or better). Priority of the parameter 'limit' is higher than priority of the parameter 'profit' ('limit' is used instead of 'profit', if its value is not 'NaN'). The default value is 'NaN'.
    loss (float): (float) [Optional] An optional parameter. Stop loss (specified in ticks). If it is specified, a stop order is placed to exit market position when the specified amount of loss (in ticks) is reached. The default value is 'NaN'.
    stop (float): (float) [Optional] An optional parameter. Stop loss (requires a specific price). If it is specified, a stop order is placed to exit market position at the specified price (or worse). Priority of the parameter 'stop' is higher than priority of the parameter 'loss' ('stop' is used instead of 'loss', if its value is not 'NaN'). The default value is 'NaN'.
    trail_price (float): (float) [Optional] An optional parameter. Trailing stop activation level (requires a specific price). If it is specified, a trailing stop order will be placed when the specified price level is reached. The offset (in ticks) to determine initial price of the trailing stop order is specified in the 'trail_offset' parameter: X ticks lower than activation level to exit long position; X ticks higher than activation level to exit short position. The default value is 'NaN'.
    trail_points (float): (float) [Optional] An optional parameter. Trailing stop activation level (profit specified in ticks). If it is specified, a trailing stop order will be placed when the calculated price level (specified amount of profit) is reached. The offset (in ticks) to determine initial price of the trailing stop order is specified in the 'trail_offset' parameter: X ticks lower than activation level to exit long position; X ticks higher than activation level to exit short position. The default value is 'NaN'.
    trail_offset (float): (float) [Optional] An optional parameter. Trailing stop price (specified in ticks). The offset in ticks to determine initial price of the trailing stop order: X ticks lower than 'trail_price' or 'trail_points' to exit long position; X ticks higher than 'trail_price' or 'trail_points' to exit short position. The default value is 'NaN'.
    oca_name (string): (string) [Optional] An optional parameter. Name of the OCA group (oca_type = strategy.oca.reduce) the profit target, the stop loss / the trailing stop orders belong to. If the name is not specified, it will be generated automatically.
    comment (string): (string) [Optional] Additional notes on the order. If specified, displays near the order marker on the chart. Optional. The default is na.
    comment_profit (string): (string) [Optional] Additional notes on the order if the exit was triggered by crossing `profit` or `limit` specifically. If specified, supercedes the `comment` parameter and displays near the order marker on the chart. Optional. The default is na.
    comment_loss (string): (string) [Optional] Additional notes on the order if the exit was triggered by crossing `stop` or `loss` specifically. If specified, supercedes the `comment` parameter and displays near the order marker on the chart. Optional. The default is na.
    comment_trailing (string): (string) [Optional] Additional notes on the order if the exit was triggered by crossing `trail_offset` specifically. If specified, supercedes the `comment` parameter and displays near the order marker on the chart. Optional. The default is na.
    alert_message (string): (string) [Optional] Text that will replace the '{{strategy.order.alert_message}}' placeholder when one is used in the "Message" field of the "Create Alert" dialog. Optional. The default is na.
    alert_profit (string): (string) [Optional] Text that will replace the '{{strategy.order.alert_message}}' placeholder when one is used in the "Message" field of the "Create Alert" dialog. Only replaces the text if the exit was triggered by crossing `profit` or `limit` specifically. Optional. The default is na.
    alert_loss (string): (string) [Optional] Text that will replace the '{{strategy.order.alert_message}}' placeholder when one is used in the "Message" field of the "Create Alert" dialog. Only replaces the text if the exit was triggered by crossing `stop` or `loss` specifically. Optional. The default is na.
    alert_trailing (string): (string) [Optional] Text that will replace the '{{strategy.order.alert_message}}' placeholder when one is used in the "Message" field of the "Create Alert" dialog. Only replaces the text if the exit was triggered by crossing `trail_offset` specifically. Optional. The default is na.
    when (bool): (bool) [Optional] An optional parmeter. Condition, deprecated.
  Returns: (void)

percent_to_ticks(percent, from)
  Converts a percentage of the supplied price or the average entry price to ticks.
  Parameters:
    percent (float): (float) The percentage of supplied price to convert to ticks. 50 is 50% of the entry price.
    from (float): (float) A price that can be used to calculate from. Optional. The default value is `strategy.position_avg_price`.
  Returns: (float) A value in ticks.

percent_to_price(percent, from)
  Converts a percentage of the supplied price or the average entry price to a price.
  Parameters:
    percent (float): (float) The percentage of the supplied price to convert to price. 50 is 50% of the supplied price.
    from (float): (float) A price that can be used to calculate from. Optional. The default value is `strategy.position_avg_price`.
  Returns: (float) A value in the symbol's quote currency (USD for BTCUSD).

bot
  Fields:
    password (series__string)
    start_time (series__integer)
    end_time (series__integer)
    leverage (series__integer)
    initial_capital (series__float)
    default_qty_type (series__string)
    default_qty_value (series__float)
    margin_mode (series__string)
    contract_size (series__float)
    kis_number (series__integer)
    entry_percent (series__float)
    close_percent (series__float)
    exit_percent (series__float)
    log_table (series__table)
    fixed_qty (series__float)
    fixed_cash (series__float)
    real (series__bool)
    auto_alert_message (series__bool)
    hide_trade_line (series__bool)
Информация о релизе
v2
Информация о релизе
v3
Информация о релизе
v4
alerts

Библиотека Pine

В истинном духе TradingView автор опубликовал этот код Pine как библиотеку с открытым исходным кодом, чтобы другие программисты Pine из нашего сообщества могли им воспользоваться. Вы можете использовать эту библиотеку в приватных или других публикациях с открытым исходным кодом, но повторное использование этого кода в публикации регулируется Правилами поведения.

Отказ от ответственности