DEV Community

Nyria
Nyria

Posted on Edited on Fully Autonomous

How a no-code trading bot turns alerts into orders

A no-code trading bot is a hosted program that sits between an alert and a broker account. It receives the alert as an HTTP request or a chat message, reads the ticker and direction out of it, applies rules you entered in a form, and calls the broker's order API with credentials you gave it. The bot makes no trading decision. The alert says what to trade, and your rules set the size and the order type.

TradingView's help page on strategies says strategy trading is limited to backtesting and that automated trading through a brokerage account isn't offered there yet. The category exists because TradingView stops at the alert.

Where does the alert come from?

Most bots accept a webhook. TradingView's webhook guide says it posts the alert's message to a URL you supply the moment the alert triggers. The bot gives you a URL, you paste it into the alert, and the text in the alert's message box becomes the request body. The same guide requires two-factor authentication on the TradingView account before webhook alerts work.

Chat is the other common source. On Discord, automation runs through a bot account, which the OAuth2 docs say can't accept an ordinary invite and has to be added through Discord's OAuth2 flow. Someone with permission in the server has to add it. To read what is posted, the bot also needs the MESSAGE_CONTENT intent covered in the gateway docs.

What has to be in the alert?

A bot can act only on what the message carries. TradingView fills in placeholders when the alert fires. {{ticker}} becomes the symbol's ticker, such as AAPL. On a strategy alert, {{strategy.order.action}} returns buy or sell for the executed order.

A typical message is one line of JSON, such as {"ticker": "{{ticker}}", "action": "{{strategy.order.action}}", "price": {{close}}}. The webhook guide says valid JSON goes out with an application/json content-type header and anything else as text/plain.

Whatever the alert leaves out has to come from a rule stored in the bot. Quantity is the usual example, and the choice of account is another.

How does the bot turn text into an order?

It maps the parsed alert onto the parameters the broker's API requires, and those parameters are public. Tradier's order reference takes class, symbol, side, quantity, type and duration, where type is "One of: market, limit, stop, stop_limit". Alpaca's create-order reference has a similar set under different names. A no-code setup form is a front end for this list.

Setups differ most in the mapping, which is also where they break. An alert that says buy while the account is already long can mean "add" or "do nothing". An alert that says sell can mean "close" or "open a short", and Tradier's reference lists those as separate side values, "One of: buy, sell, sell_short, buy_to_cover". Find out how a bot resolves each case before it holds a position for you.

What is different for an option alert?

A share order needs a ticker. An option order needs one contract out of the many listed on that ticker. Each contract fixes a strike price and has an expiration date, as the Options Industry Council's introduction sets out. Brokers fold all of that into one symbol. Alpaca's options page shows AAPL240119C00100000 for the "AAPL Jan 19 2024 100 Call".

An option bot therefore works in one of two ways. Either the alert names the exact contract, or the alert gives a direction and the bot picks the contract from rules for expiry and strike. TradingView's placeholder list has no strike, expiration or delta variable, so chart alerts fall into the second group unless the message itself supplies the contract.

Option orders also carry tighter limits. Alpaca's page accepts only day or gtc as the time_in_force of an option order, and its validations include "extended_hours must be false or not populated". The account needs approval too. On Alpaca, buying a call or a put sits at level 2 of the trading levels in that document.

Expiry adds a duty that a share position doesn't have. Alpaca's options page says its default is to exercise in-the-money contracts automatically at expiry. A bot that opens option positions needs an exit rule that fires before then.

What happens when an alert fires twice or a request fails?

A duplicate alert or a retried request can place a second order, and brokers don't always prevent it. tastytrade's idempotency guide says "Order placement is not idempotent." It adds that repeating your own order id on a second request doesn't prevent that order. The duplicate check has to live in the bot.

Timing matters on the inbound side as well. TradingView drops a webhook request if the receiving server hasn't finished with it inside three seconds, its guide says. A bot has to accept the alert fast and place the order afterwards, and you need a log that shows both steps.

What happens outside market hours?

Alerts fire whenever the chart condition is met, including after the close. On Alpaca, a day order that arrives after the close is held and sent on the next trading day, per its orders page. A bot that forwards a late alert this way trades at the next session, so the fill can differ from the price in the alert. A market order fills at whatever the market offers then, while a limit order fills at its limit or better, or not at all.

Options are stricter because the extended-hours flag must be off. Cboe's hours page ends regular trading in equity options on its C1 exchange at 4:00 p.m. Eastern Time, and its footnote keeps some ETF options open to 4:15 p.m.

How do you test one without real money?

Point the bot at a broker's paper account. Alpaca's paper trading page describes paper trading as a real-time simulation that runs like live trading except that no order goes to an exchange. Options are switched on for paper accounts by default, per its options page. Tradier's FAQ puts sandbox market data on a 15-minute delay. tastytrade's sandbox page warns that "The environment resets every 24 hours".

Read the results as a test of wiring. Alpaca's simulator doesn't check order size against the quantity quoted in the market, so a thin option contract can fill there and sit unfilled in a live account.

What access does the bot have to your account?

The bot places orders with your credentials, so it can do whatever those credentials allow. Keep them out of the alert itself. TradingView's guide warns against putting passwords or other login details in a webhook's body.

Treat the webhook URL as a secret too, because a bot that accepts any post to that address will act on it. Start with paper keys. Alpaca issues a paper account its own API key, separate from the live one. Before going live, find the place at your broker where that access is revoked.

What should you check before going live?

Question to answer Why it matters Source
Does the bot answer inside three seconds? TradingView cancels slower webhooks TradingView webhook guide
What does a repeated alert do? Not every broker rejects a duplicate order tastytrade idempotency guide
How is sell resolved? Closing and shorting are different side values Tradier order reference
Which contract does an option alert buy? Alert placeholders carry no strike or expiry TradingView placeholder list
What happens to an alert after 4:00 p.m. ET? A day order queues for the next session Alpaca orders page
What closes an option before expiry? In-the-money contracts are exercised by default Alpaca options page

A bot that answers all six works end to end on a paper account. Whether the alerts are worth following is a separate question that no bot settles.

AI tools wrote this article. Its facts were checked against the official docs linked above.

Trading involves risk of loss.

Top comments (0)