You've successfully subscribed to Alpaca Learn | Developer-First API for Crypto and Stocks
Great! Next, complete checkout for full access to Alpaca Learn | Developer-First API for Crypto and Stocks
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.
Community Examples

How to Build a Recurring Investment Bot in Trellis

Alpaca Team
Alpaca Team
Build a Recurring Investment Bot in Trellis

Please note that this article is for educational and informational purposes only. All screenshots are for illustrative purposes only. The views and opinions expressed are those of the author and do not reflect or represent the views and opinions of Alpaca. Alpaca does not recommend any specific securities or investment strategies.

This article was written by Andy Lebowitz, Co-founder of Trellis

What is Trellis?

Trellis is a platform where anyone can build a trading bot in under five minutes without code. I started building Trellis back in January when I wanted to create a semi-automated trading bot for myself through notifications. Specifically, I wanted to receive a notification on my phone whenever my algorithm set off a buy or sell condition, then I could manually tap “Approve” on the notification to actually execute a trade.

After outlining the details of the mobile app, server, and APIs I’d have to code from scratch, I realized that building my bot would take me at least a week, despite the fact that I already had a couple years of programming experience under my belt. After talking to a couple dozen other traders, I learned that they too couldn’t get involved with algo-trading either because they didn’t have enough programming experience, or they didn’t want to commit this much time to building a trading bot. So, I decided to build Trellis to allow traders who are too busy or have non-technical backgrounds to have access to this world of automated trading. Just a few months after launching it, 500 trading bots have already been created through Trellis, with each one being made in just a couple minutes. Continue reading below to see how a specific strategy can be built within Trellis.

How to build a recurring investment bot that sells when a stock is overpriced

Let’s say we want to make a bot that buys 1 share of TSLA every week, but if the RSI crosses above 70 (we can assume TSLA stock is relatively overpriced at this point), we’ll sell all the shares we own.

First, click the “Create new bot” button.

Next, select TSLA from the list of tickers.

After that, we can name our bot, allocate it some money to trade with, and say it must wait 10,080 minutes between each trade. This way, our bot can only submit a buy order once every week (10,080 minutes = 1 week). If you want to connect your bot to your Alpaca account, be sure to select “Trade with real money” and then follow our steps. Connecting to Alpaca should only take a minute.

Now, we can set the buy conditions for our bot. Like we said, we want the bot to buy automatically once per week. Since we already said our bot is limited to 1 buy order every 10,080 minutes (1 week), we need to make sure our buy triggers go off every time they’re allowed to. To do this, you can just make a trigger that we know will always be true. In the example below, we said “If the price of TSLA is above -1, then buy 1 share of TSLA.” This will always be true, so it is the same as saying “Buy 1 share of TSLA every week.”

We can then hit “Continue” and set our sell trigger for TSLA: If the RSI of TSLA crosses above 70, sell as many shares as possible.

This next part is optional, but let’s say you also want a way to take losses and move on if your bot is unsuccessful. More specifically, maybe you want to sell all your shares if your bot is down 20%. To do that, we can click “OR” and introduce this condition as an OR operator:

When you’re ready to save and deploy your bot, you can hit “Deploy Bot.”

Nice job, you’ve deployed your first bot on Trellis!

Go ahead and try building and deploying your own strategy on Trellis. Trellis is free to use, and you can click here to get started.

Learn more at

Alpaca does not prepare, edit, or endorse Third Party Content. Alpaca does not guarantee the accuracy, timeliness, completeness or usefulness of Third Party Content, and is not responsible or liable for any content, advertising, products, or other materials on or available from third party sites.

Brokerage services are provided by Alpaca Securities LLC ("Alpaca"), member FINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.

Interested in getting the latest news and content from Alpaca? Follow us on LinkedIn, Twitter, and Facebook for more.

Community Examples

Alpaca Team

API-first stock brokerage. *Securities are offered through Alpaca Securities LLC*