Documentation

How to use Accumulation Limits

Overview

An accumulation limit lets you control the maximum amount of an asset your bot is allowed to accumulate from repeated buy signals.

This is useful when your strategy may produce several buy alerts before it produces a sell alert. For example, if you only want to hold one 0.25 BTC position at a time, you can set your normal buy amount to 0.25 BTC and set the accumulation limit to 0.25 BTC. The first buy signal can open the position. Additional buy signals will not increase the position once the limit has been reached.

After a sell signal reduces your holdings, the bot can buy again on the next valid buy signal.

How it Works

When an accumulation limit is enabled, TOMMYBOTS checks your current holdings before placing a buy order.

If your current holdings are below the limit, TOMMYBOTS will allow the buy.

If the full buy would go over the limit, TOMMYBOTS will reduce the buy amount to the remaining allowed amount.

If your current holdings are already at or above the limit, TOMMYBOTS will block the buy.

Accumulation limits only apply to "buy" and "cancel-then-buy" alerts.

Using accumulation limits with dollar cost averaging

Accumulation limits can be especially useful for dollar cost averaging bots.

A dollar cost averaging strategy may intentionally send multiple buy signals over time. Without an accumulation limit, the bot can keep buying as long as the strategy continues to trigger. This may be exactly what you want, but it can also cause the position to grow larger than intended.

With an accumulation limit, you can let the bot continue to dollar cost average while still defining the maximum total amount of the asset you want to hold.

For example, you may want your bot to buy 0.01 BTC at a time, but never accumulate more than 0.25 BTC total. In that case, your alert amount would be 0.01, and your accumulation ceiling would be 0.25.

Parameters

accumulation-limit-enabled

Optional. Set this to true to enable the accumulation limit. This parameter only works with "buy" and "cancel-then-buy" alerts.

accumulation-ceiling-units

Required when accumulation-limit-enabled is true. This is the maximum total amount of the base asset you want to hold. For BTC-USD, this value is measured in BTC. For ETH-USD, this value is measured in ETH.

Important notes

The accumulation limit is based on asset units, not dollars. For example, "accumulation-ceiling-units":"0.25" on BTC-USD means 0.25 BTC.

This feature is for limiting long accumulation from buy orders. It does not limit short positions.

The accumulation limit does not change your stop loss or take profit amounts. It only affects the size of the buy order.

You can also create this code using the TOMMYBOTS Code Generator by enabling the Position Limit / Accumulation Limit option on the Amount step.

The Code

To begin, please ensure that your TradingView alert has the correct Webhook URL that contains the unique URL to your bot. Additionally, it's essential to read and understand the How to Create a TradingView Alert article before proceeding.

To get started with the integration, you can either use the Code Generator to generate the code or copy the code below and adjust the values manually. Click the "Copy" button below to copy the code and paste it into your TradingView alert message.

Buy 0.25 BTC, but do not allow total BTC holdings to go above 0.25 BTC

For example, if you only want to hold one 0.25 BTC position at a time, you can set your normal buy amount to 0.25 BTC and set the accumulation limit to 0.25 BTC. The first buy signal can open the position. Additional buy signals will not increase the position once the limit has been reached.

 


{
"asset-pair": "BTC-USD",
"action": "buy",
"order-type": "market",
"amount": "0.25",
"accumulation-limit-enabled": true,
"accumulation-ceiling-units": "0.25"
}
Example with a reduced buy

If your alert tries to buy 0.25 BTC, your accumulation ceiling is 0.50 BTC, and you already hold 0.40 BTC, TOMMYBOTS will reduce the buy to 0.10 BTC.

This keeps your total BTC holdings at the maximum allowed amount of 0.50 BTC.

 


{
"asset-pair": "BTC-USD",
"action": "buy",
"order-type": "market",
"amount": "0.25",
"accumulation-limit-enabled": true,
"accumulation-ceiling-units": "0.50"
}
Dollar Cost Averaging Example

For example, you may want your bot to buy 0.01 BTC at a time, but never accumulate more than 0.25 BTC total. In that case, your alert amount would be 0.01, and your accumulation ceiling would be 0.25.

 


{
"asset-pair": "BTC-USD",
"action": "buy",
"order-type": "market",
"amount": "0.01",
"accumulation-limit-enabled": true,
"accumulation-ceiling-units": "0.25"
}
Parameter
Description
asset-pair
The ticker symbol and the quote currency separated by a hyphen. Example: "BTC-USD"
action
"buy" or "sell" or "cancel-then-buy" or "cancel-then-sell" or "cancel-orders" or "get-open-orders"
order-type
"limit" or "market" or "stop" or "take-profit" or "trailing-stop"

* trailing-stop not available on all exchanges.
price
Required for limit orders. Do not include for market orders. The limit price of the asset. Example: "95.99"
amount

One of amount, amount-percent-balance, or amount-percent-position is required. The "amount" is a decimal and represents the exact number of units, coins, or shares that you would like to buy or sell. (ie. buy "2.0" BTC).

amount-percent-balance
One of amount, amount-percent-balance, or amount-percent-position is required. The "amount-percent-balance" is a percentage and represents the percentage of your available account balance (or quote currency) that you would like to buy or sell.
amount-percent-position
One of amount, amount-percent-balance, or amount-percent-position is required. The "amount-percent-position" is a percentage and represents the percentage of your position (or base currency) that you would like to buy or sell.
Optional Parameters for Simple Orders
accumulation-limit-enabled
Optional. Set to true to prevent repeated buy entries after your current holdings reach a maximum position size. This only applies to "buy" and "cancel-then-buy" alerts. When enabled, accumulation-ceiling-units is required.
accumulation-ceiling-units
Required when accumulation-limit-enabled is true. The maximum total amount of the base asset you want to hold, entered as units, coins, or shares. Example: "0.25" means a maximum of 0.25 BTC for a BTC-USD alert. If the next buy would exceed this amount, TOMMYBOTS will reduce the buy size to the remaining allowed amount. If you are already at or above the limit, the buy will be blocked.
price-value-tracker-id

(Optional with limit orders) The "price-value-tracker-id" can be specified instead of the "price" parameter if you want to dynamically set the price using the high, low, or average value from a value tracker.

price-logic

(Required with price-value-tracker-id) "high" or "low" or "avg"; This tells the bot to take the high, low, or average of the specified value tracker's data set.

post-only

(Optional with limit orders) "true" or "false"; If you send a post only order, your order will not be allowed to take. So if it would provide it will be sent as a normal Limit Order, but if it would cross the book it will be canceled instead. See this article for more details.

ioc

(Optional with limit orders) "true" or "false"; Immediate or cancel (IOC) orders are the opposite of post only: they can only take.  If you send an IOC that would not immediately trade, it will be canceled. See this article for more details.

reduce-only

(Optional) "true" or "false"; These orders can only close your positions and will only trade if it would decrease your position size. You can combine with any order type: limit, market, stop, trailing-stop, or take-profit. See this article for more details.

Trigger Order Parameters (Stop, Take Profit, Trailing Stop)
trigger-price

(Required with "stop" and "take-profit" order types, but not required if a Value Tracker is specified.) This is the price at which you want your stop or take profit to trigger. Example: "95.99"

trail-value

(Required with trailing-stop orders) The "trail-value" should be a percentage (ie. "3.25%") of the current price.

current-price

(Required with trailing-stop orders on the FTX exchange) The "current-price" is needed to calculate the correct trailing value in the quote currency using the trail-value percentage. In most cases, you will want to use the "{{close}}" TradingView variable to set the current price dynamically like so: "current-price":"{{close}}"

add-stop

(Optional with limit and market orders) "true" or "false". Include this if you want to add a stop loss trigger order to your limit or market order, in the exact same alert as your limit or market order.

stop-price

(Required with "add-stop") Example: "95.99". The price at which you want to set your stop. Alternatively, you may use a value tracker to set your stop price. In this case, use "stop-value-tracker-id" instead.

stop-amount

(Required with "add-stop") The amount can be specified as a decimal (ie. "150.00") or a percentage (ie. "50.0%") of your position size.

stop-order-type

(Optional with "add-stop". Also optional with "stop" order types, but only when using a Value Tracker with the stop.) "limit" or "market"; Will default to market if not specified.

stop-value-tracker-id

(Optional with "add-stop") Example: "your unique id". The value tracker id that contains the high, low, or average value that you want to use to set your stop. Alternatively, you may use "stop-price" to explicitly set your stop price.

stop-logic

(Required with "stop-value-tracker-id") "high" or "low" or "avg"; This tells the bot to take the high, low, or average of the specified value tracker's data set.

add-take-profit

(Optional with limit and market orders) "true" or "false". Include this if you want to add a take profit trigger order to your limit or market order, in the exact same alert as your limit or market order.

tp-price

(Required with "add-take-profit") Example: "95.99". The price at which you want to set your take profit. Alternatively, you may use a value tracker to set your take profit price. In this case, use "tp-value-tracker-id" instead.

tp-amount

(Required with "add-take-profit") The amount can be specified as a decimal (ie. "150.00") or a percentage (ie. "50.0%") of your position size.

tp-order-type

(Optional with "add-take-profit") "limit" or "market"; Will default to market if not specified.

tp-value-tracker-id

(Optional with "add-take-profit") Example: "your unique id". The value tracker id that contains the high, low, or average value that you want to use to set your take profit. Alternatively, you may use "tp-price" to explicitly set your take profit price.

tp-logic

(Required with "tp-value-tracker-id") "high" or "low" or "avg"; This tells the bot to take the high, low, or average of the specified value tracker's data set.

tp-risk-reward-ratio

(Optional when "add-take-profit" and "add-stop" are used together) A decimal value (ie. 2.5) that represents the risk-reward ratio that should be used to calculate the take profit price based on the stop price.

retry-until-filled *

(Optional with trigger market orders) "true" or "false"; Retry all trigger market orders (stop, take-profit, and trailing-stop) until they get filled. See this article for more details.

* Not available on all exchanges.

Group Alert Parameters
alert-group-id

(Optional) A unique identifier for a group of alerts. You can use any alphanumeric name that you like as long as it's 50 characters or less. Example: "strategy-b-group"

alert-number

(Required with alert-group-id) The integer number which identifies a particular alert within a group of alerts. The value must be between 1 and 9 (a max of 9 alerts per group). Example: "2"

of-total-alerts

(Required with alert-group-id) The integer number which identifies the total number of alerts in a particular group of alerts. The value must be between 1 and 9 (a max of 9 alerts per group). Example: "3"

group-window

(Required with alert-group-id) The time window in which all alerts need to be received relative to each other. It can be specified in minutes, hours, days, or weeks. (ie. "15 minutes", "2 hours", "3 days", "1 week"...etc)

alert-trigger-if

(Optional with alert-group-id) When included with an alert that is part of an alert group, this value is used to compare the current value in the alert to the value from the previous alert that came through with the same alert-number. This value can only contain one of the following: ">" (greater than) or "<" (less than) or ">=" (greater than or equal to) or "<=" (less than or equal to) or "==" (equal to).

alert-value

(Required with alert-trigger-if) When using the alert-trigger-if feature, the alert-value parameter is required to capture a decimal value. This could be any value on your indicator or chart (ie. the price, a moving average, RSI value...etc) In most cases, you will use a TradingView variable here to dynamically set the value in the alert message (ie. "{{plot_3}}")

or-group

(Optional with alert-group-id) A list of alert numbers within an alert group that should have the logical OR operator applied. Each number should be separated by hyphens. Example: "2-4-5". Each alert that is part of the OR group should include the "or-group" parameter with the same value.

Value Tracker Alert Parameters
value-tracker-id

(Optional) A unique identifier or name for the Value Tracker Dataset. You can use any alphanumeric name that you like as long as it's 50 characters or less. Example: "BTC 1HR ATR Stop"

value

(Required with value-tracker-id) The numeric value that you would like to track as a dataset over the last X alerts or candles.

track-last-x-alerts

(Required with value-tracker-id) This is an integer number that represents the number of alerts or candles that you want to keep as a dataset to reference later from other alerts. For example, if you want to reference the swing low over the last 50 candles from other alerts, set track-last-x-alerts to 50 and configure your Value Tracker Alert to trigger on every candle close. The max number of alerts that you can track in one dataset is 100.

Checking the Order Status

Once your alert has been triggered, follow these steps:

  1. Check the Alert Logs tab under My Account for any errors or additional information.

  2. Log in to your exchange account and confirm that the order has been placed.

Copyright 2024 (c) www.tommybots.com