Custom Strategy

This section will detail the steps to creating an AstraBit bot that can be connected to a custom strategy via webhooks

Regarding TradingView Scripts:

There is a functional difference between an Indicator and a Strategy

A Strategy is a type of script that offers a backtest so users can see the actual trades and results that would’ve been taken, but by design has the tendency to repaint and give false signals if not coded correctly due to the usage of TradingView’s backtesting engine directly generating signals. For Reference.

Strategies MUST USE the Unified Signal endpoint on AstraBit

| DCA Bots & Strategies are currently not compatible with the Unified Signal Endpoint

An Indicator is the other type of script that should NOT repaint and DOES have the ability to create customized alerts. For Reference.

Setup

1) Create a trading bot and go to Step One (Strategy)

2) Select the Personal Strategy tab and Enable the toggle to use bot with a personal strategy.

Select personal strategy option step in AstraBit setup process

3) Fill in the rest of your bot’s allocations, type, and risk management settings


4) After creation you will see a window that shows your bot’s Signal Notification URLs and your secret phrase to authenticate all requests

Select notification URLs step in AstraBit personal strategy setup
Configure notification URLs step in AstraBit personal strategy setup process

5) You can go to Edit your bot at any time to revisit and/or regenerate your Signal Notification URLs on Step Five (Connect your bots)

Select notification URL option step in AstraBit personal strategy setup


Connecting Signals

The URLs are webhook endpoints that expect the body message to have JSON containing the authentication secret { “secret”: “{YOUR_SECRET_PHRASE” }

To confirm your JSON formatting please use a validation tool such as:https://jsonlint.com/

Updating the alert Condition will set the next dropdown box to the default first item in the list of selections

– If you update your indicator settings and want to update the alert with the new settings

– The condition trigger must be updated after it’s been reset to the default

Ex:

  • Default condition trigger is “Long Close”
  • Updating BTC Long alert and BTC Short alert
  • Must change “Long Close” to “Long Open” for the Long Alert
  • Must change”Long Close” to “Short Open” for the Short Alert

TradingView Unified Signal Alert Setup

{
    "code": "SOME_CODE_HERE",
    "asset": "{{ticker}}",
    "order_action": "{{strategy.order.action}}",
    "order_price": "{{strategy.order.price}}",
    "order_contracts": "{{strategy.order.contracts}}",
    "isTest": false,
    "current_position_size": "{{strategy.position_size}}",
    "market_position": "{{strategy.market_position}}",
    "market_position_size": "{{strategy.market_position_size}}",
    "prev_market_position": "{{strategy.prev_market_position}}",
    "prev_market_position_size": "{{strategy.prev_market_position_size}}"
}
Create alert step in AstraBit personal strategy setup showing alert configuration fields
Configure alert notification settings with webhook URL in AstraBit personal strategy setup

TradingView Custom Alert Signal Setup

Finalize alert configuration with webhook and message settings in AstraBit personal strategy setup
Set alert name and message for webhook signal in AstraBit personal strategy setup

TradingView Manual Alert Signal Setup

TradingView chart with moving averages and alert setup for webhook signal integration
TradingView chart with moving averages and alert setup for webhook signal integration (short strategy)


1) Condition

This will depend on what signals you have available to you, custom indicator signals via alertcondition() are recommended

Pinescript v5 Documentation

2) Options


How often the alert will sound off is dependent on your strategy itself, but usually Once Per Bar Close and Once Per Bar are the main options to use.

  • Once Per Bar Close will wait until the confirmation of candle closing to send the signal if your Condition is true
  • Once Per Bar will send the signal once during the candle’s time such as when you need to send a Take Profit or Stop Loss level signal if your Condition is true

3) Expiration time


TradingView has alert expirations unless you have a Premium account, the alert expiration can be continuously edited and updated manually for lower tier subscriptions

4) Alert Actions


This is where the webhook URL is inserted which will send the signal out from TradingView to AstraBit

5) Alert Name


Convenient name to track your alerts and make sure you don’t cross signals

6) Message


MUST contain JSON formatted payload and NO OTHER TEXT to be parsed by AstraBit and confirm signal(s)

Validate JSON formatting at any online lint checker such as https://jsonlint.com/

Example Fields

{
“secret”: “YOUR_SECRET_KEY_WILL_BE_HERE”,
“order_price”: “{{close}}”,
“close”: “50”
}

  1. Secret – Unique authentication of your strategy signal to AstraBit
  2. Price – Current recorded execution Price
  3. Close (optional): Specify up to 100% of CURRENT position to close (Default: Close 100%)

Unified Signals

{
    "code": "STRATEGY_CODE_HERE",
    "asset": "{{ticker}}",
    "price": "{{close}}",
    "order_action": "{{strategy.order.action}}",
    "order_price": "{{strategy.order.price}}",
    "order_contracts": "{{strategy.order.contracts}}",
    "isTest": false,
    "current_position_size": "{{strategy.position_size}}",
    "market_position": "{{strategy.market_position}}",
    "market_position_size": "{{strategy.market_position_size}}",
    "prev_market_position": "{{strategy.prev_market_position}}",
    "prev_market_position_size": "{{strategy.prev_market_position_size}}"
}

Required Values

  1. code – Unique authentication of your strategy signal to Astrabit
  2. order_price – Current recorded execution Price
  3. order_action – Current order action being taken; [Buy/Sell]
  4. order_contracts – Current volume delta of previous position state to current position state
  5. market_position – Current position state; [Long/Short/Flat]
  6. prev_market_position – Previous position trade state; [Long/Short/Flat]
  7. prev_market_position_size – Previous position volume size

Custom Coded

Please reference the notes above for TradingView

Summation


1) Send webhook API call to provided endpoints

2) Message body should contain JSON data including secret

3) AstraBit signal log should show any signals sent over that were received correctly

Testing Signals (TradingView)

To test your signal setup from a personal bot to AstraBit is authenticating and being received correctly:

TradingView alert setup screen for testing webhook signal configuration


1) Create an alert for testing that uses the “Close Signal Notification URL”

2) Select the asset for the chart you’re on (normally the first option)

3) Greater Than

4) Value: 0

5) Only Once

This will send a single test signal whenever it is saved, or each time it’s enabled from the TV alerts sidebar.


You can then check your personal bot’s Signal Log and make sure that the close signal was received by AstraBit to execute on

Now you know that you can send signals and authenticate them now that the Alert Message is correct and can be copied and pasted to all other alerts for that strategy.