You've successfully subscribed to Alpaca Resources
Great! Next, complete checkout for full access to Alpaca Resources
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.
  • Home
  • We're hiring
  • Support
  • Forum
  • Docs
  • Log in
  • Sign up
Community Examples

Simple Algo Trading with Alpaca and Streak

Alpaca Team
Alpaca Team

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 originally appeared on Decoding Markets, written by Joe Marwood


visit alpaca.markets/broker to learn more

Technology is moving fast and there are a number of interesting fintech startups cropping up in recent years.

One promising development is Alpaca, which was started in 2015 and billed as the first commission-free API stock brokerage. Relevant SEC and FINRA fees may apply.

The interesting thing with Alpaca is that it connects with a host of apps and services that makes algorithmic trading more accessible to everyone.

Here are some of the integrations that are currently available with Alpaca:

  • TradingView
  • Streak
  • Slack
  • IFTTT
  • QuantRocket
  • Blueshift
  • Tradetron
  • Passiv
  • Zapier
  • Alexa
  • Arcade Trader

As you can see, there is a lot you can do with a bit of creativity.

For example, can you imagine shouting out trade orders in your living room and having them placed via Amazon Alexa? What about auto-trading anytime a certain phrase is typed out in Slack?

Some of the integrations are a bit of a novelty but the technology is great and becoming more and more powerful.

One useful integration that I have been looking at is Alpaca + Streak.

Streak lets you build and backtest algorithmic trading strategies without having to code and it links up with Alpaca. You can then deploy your Streak algorithm straight to Alpaca for simple automated trading.

In the rest of this article, I will take one of our existing strategies called 60-Minute Gaps and build it in Streak.

I’m going to set the strategy up in Streak, run a backtest and then deploy it via Alpaca. Let’s take a look, step by step:

1. Setting Up Streak And Alpaca

The first step is to open an account on the Streak website. There is a free trial as well as three pricing options available;

  • $16/month allows 200 backtests per day and 25 live deployments
  • $24/month allows 500 backtests per day and 50 deployments
  • $32/month allows 1000 backtests per day and 100 deployments

You will also need to open and fund a live account with Alpaca. Both platforms also offer paper trading to test the waters.

2. Creating An Algo

Streak has technical charts, screeners and dashboards but for the purpose of this article I will be focusing on the backtesting and deploying of a live trading strategy.

To do this, click ‘Algos’ in the menu bar and select ‘My Algos’. Then click ‘Create Algo’.

You will now see a simple interface that will allow you to create your very first trading algorithm.

To build an algo is straightforward and requires zero coding or skill. Here are the steps required:

  1. Select the instrument/s you want to trade
  2. Select the timeframe (anything from 1-minute to 1-day)
  3. Select whether you want to buy (long) or sell (short)
  4. Set the position quantity that you want to buy/sell on an entry signal
  5. Set up the entry rule based on various indicators available
  6. Set up the exit rule based on various indicators available
  7. Set up any stop loss or profit target.
  8. Set up any advanced criteria such as chart type and time of trading.
  9. Give the Algo a name.

Once you have followed these steps, you simply click save and backtest and you will be able to backtest the strategy you’ve created.

As I mentioned earlier, I’m going to set up the rules for our 60-Minute Gaps strategy like below:

As you can see, this is a very simple intraday strategy that buys up gaps and exits on down gaps. It is easy to set up and is now ready to be backtested on Streak.

There are other ways to build a trading strategy in Streak with lots of indicators to choose from. According to the documentation, Streak will always send the order to be placed at the close of the current candle.

The following screengrab shows some of the indicators available:

3. Backtesting The Algo

After clicking save and backtest, Streak takes a couple of seconds to backtest the algo and reports the results on each individual instrument. It also provides some basic stats such as win rate, winning/losing streak, and max drawdown. The parameters and dates of the backtest can also be adjusted by clicking on the Edit Parameters button.

As you can see below, the 60-Minute Gaps strategy was profitable in the backtest period between November 2019 and November 2020. You can click on the image below to see a larger version:

The algo made a profit of $3126.69 on SPY, $1862.99 on QQQ, $1582.83 on TLT, and lost -$1286.88 on DIA. These results are based on a fixed position size of 100 shares.

Clicking into any of these results takes you to an equity chart and more details around actual transactions:

Next, you can change the dates of the backtest to see if the strategy performs consistently well over other time periods.

A major downside here is that Streak seemingly allows you to only backtest one year at a time? Below are the results for 2018:

Now that I have backtested the strategy on Streak, the first thing I do is to check the individual transactions to make sure the trades match up with the entry and exit logic that was created.

Then I compare the backtest results to another source. Since I created 60-Minute Gaps in Amibroker with data from eSignal I check the results there.

I can see that there are some differences in the results which I think might be down to Streak including after-market data. I can’t be sure without further investigation. The backtest results are good anyway so I will proceed for now and deploy the strategy to a paper trading account.

4. Deploying To Paper Trading

Streak is not a brokerage but it does allow you to paper trade your strategy inside the platform. All you need to do is select the box of the strategy you want to deploy and then click the Deploy All button.

In the next window, you have some options to change position size, deployment type, algo cycle, and order type:

The Algo Cycle refers to the sequence of events throughout a trade, which is not only influenced by trade signals but could also change subject to market conditions and user behavior. It’s quite complex so it’s worth reading about on the Algo Cycle help page.

For now, I will leave the position size how it is, deployment type I set to Paper Trading, Algo Cycle to 1, and Order Type to Market. (If I was trading less liquid securities I would consider a limit order here but I think market order will be fine for now).

After clicking continue, you are taken to the Paper Trading screen. As you can see, all algos are now deployed to paper trading. The market is currently closed so all 4 algos are waiting for a signal:

5. Deploying To Alpaca

Once you have an algo set up and working well in paper trading the next step is to transition to a live broker. This is where Alpaca comes in. First, you need to open an account with Alpaca and go through the steps necessary to fund it.

To connect your Streak algo to Alpaca click on the menu icon in Streak and navigate to My Accounts then click Add Account. Then head down to the bottom of the list of brokers, pick Alpaca and follow the verification procedure:

At this point, you should be connected to Alpaca. The next step is to go back to your collection of Algos in Streak. Instead of deploying them to Paper Trading we are now going to deploy them to Alpaca instead:

The best way I have found to do this is to copy the Algos in the paper trading account (the ones we just created) and give them a new name such as 60-Minute Gaps – Live.

Save and backtest the copied algo and then click ‘deploy all’ once again. This time you are going to select Auto Trading and choose the relevant account name in Alpaca:

The four algos are now deployed and signals will be sent from Streak to Alpaca.

6. Observing The Results

If you’ve been following the steps, there should now be 8 algos, 4 are going to the Streak paper trading account and 4 are going to Alpaca.

Be aware that Streak algos cannot be used with an Alpaca paper account they can only be connected to a live, funded account.

The only thing to do now is observe the algos (you can watch them place paper trades in Streak and live trades in Alpaca). Make sure they are behaving as you expect them to and that the orders are getting good fills.

Things To Be Aware Of

There are lots of things to be aware of with algorithmic trading and you need to tread especially carefully when you start deploying your algorithm to the live market.

A good place to learn about the finer details is the Streak help page. This page will tell you, for example, how the Streak bots operate, how long they wait between signals and how you can know if the systems are talking to each other correctly.

Likewise, Alpaca maintains a helpful amount of documentation including a Slack community and a forum.

One piece of advice I would recommend is to always keep a close eye on your algorithms while they are trading to ensure they are acting appropriately.

Always remember that anything can happen in trading; black swans and leverage can be fatal so always trade small with money you can afford to lose.

I would also recommend using different software such as Amibroker for more extensive backtesting first before moving to Streak since the backtesting and analysis tools on Streak are not comprehensive enough.

Crypto Trading

As well as allowing traders to run stock algos via Alpaca, Streak has support for a number of different crypto exchanges.

Currently, the platform supports the following crypto exchanges which all allow trading via API:

  • Binance
  • Deribit
  • HITBTC
  • Okex
  • Huobi
  • Kraken
  • Coinbase Pro
  • Coinbase
  • ZB
  • BitMEX

I have no experience with algo trading on cryptocurrencies but it looks like this is becoming a significant focus on Streak.

Conclusion

Streak with Alpaca will appeal to beginners because it offers a very straightforward entrance to the world of algorithmic trading. Anyone can create their own algo with just a few clicks of the mouse – no coding required.

This approach could also benefit someone who has done the hard work of building a robust trading strategy but has not found an easy way to automate it.

More experienced traders will probably find that the solution is not sophisticated or robust enough for their needs. Streak is still in beta, it lacks some advanced features and the documentation could be improved. I have also not been able to test the latency with a live account.

Alpaca is also a very promising broker/platform that offers a multitude of interesting integrations. It’s great to have these types of platforms gaining popularity. It’s clear that the world of algorithmic trading is opening up.

visit alpaca.markets/broker to learn more

About the Author

Joe Marwood is an independent trader and the founder of Decoding Markets. He worked as a professional futures trader and has a passion for investing and building mechanical trading strategies.

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. This is not an offer, solicitation of an offer, or advice to buy or sell securities, or open a brokerage account in any jurisdiction where Alpaca is not registered (Alpaca is registered only in the United States).

Community Examples

Alpaca Team

API-first stock brokerage. *Securities are offered through Alpaca Securities LLC* http://alpaca.markets/#disclosures