Algorithmic Trading for Beginners — Part 1

Create your first algo trading strategy with Arcade Trader and Alpaca

Arcade Trader
6 min readJun 10, 2020

NOTE: This tutorial has been modified on July 10th, 2020 to use the new “Natural Language” instead of Javascript. You will find a new tutorial about using Javascript soon.

If you’re an investor or a stock trader, it’s no secret that algorithms have replaced regular investors in terms of volume.

Why algorithms? Because while a person can follow maybe 4 stocks at the same time, algorithms can follow thousands of stocks and respond faster than a blink of an eye. Furthermore, they are committed to a defined strategy without any emotion. Yes, trading can be very emotional. Poor execution due to involved emotions can cause traders with otherwise successful strategies to fail. Technology is king.

Most of those algorithms run by banks and hedge funds use very sophisticated (and expensive) technologies, not available to the public.

Until today.

This 5 step tutorial details the steps for creating your first Arcade strategy using a robot that invests for you. You don’t need to master any programming language.

For our tutorial, we’re going to use the following FREE resources:

  1. Alpaca Markets zero commission broker. You can set up a FREE Paper Account in minutes. Paper accounts are virtual brokerage accounts where you can play with virtual money. They’re perfect for learning and testing.
  2. Arcade Trader platform. The online cloud version is derived from the one used by Hedge Funds. It’s totally FREE for private traders and investors. It allows you to do both backtesting and live trading.

Let’s get started!

1. Create a new Paper Account with Alpaca

Open your browser to https://app.alpaca.markets/signup and insert your email and a password. Example:

Alpaca sign up form

2. Link your Alpaca account to Arcade Trader

Go to Arcade Trader, click “Login” and then “Sign up now” to create a new account. Then connect it to your Alpaca account.

A popup will prompt you to grant authorization to Arcade Trader from your Alpaca account. Just click “Allow” et voila’, your account is setup.

Alpaca request authorization form

3. Login to Arcade Trader

For security reasons, you will be asked to confirm your login the first time. Copy and paste the verification code you received via email in this form.

Arcade Trader verification of the account

Welcome to Arcade Trader’s homepage. Here you can monitor your accounts, profit, positions, and orders.

Home page

Check on the first widget for the connected accounts. If you have created and funded an account with Alpaca, you will see both Live and Paper accounts. Otherwise, only the Paper account will be available.

Alpaca accounts connected to Arcade

4. Research an idea for your first strategy

Let’s build our first simple strategy. The classic lifecycle for a successful Algo trader is the following:

Successful Algo Trader Lifecycle

Never go live with an algorithm that hasn’t been tested with past data. Even if it’s true that “past performance data is not indicative of future results”, checking how an algorithm would have performed in the past is a good indicator if you have found something good or not.

For our tutorial, we’re going to use something well-known in trading literature: the Golden Cross. It’s a very simple strategy that buys when a short-term moving average line crosses above a short-term moving average.

As indicator lines, you can use the SMA (Simple Moving Average) which is a line calculated by using a simple average of the latest X prices, where X is the length. Typical lengths are 5, 10, 20, 50, 100, 150, and 200. So SMA-200 means the Simple Moving Average of the last 200 days.

Another popular Moving Average is the EMA (Exponential Moving Average) where the most recent prices count more. Then, a less popular but more effective indicator: the WMA (Weighted Moving Average) is where also the volume is taken into consideration.

In Arcade Trader, let’s see how “Apple Inc” (symbol AAPL) reacts to the WMA indicator. On the Arcade Trader Home Page, scroll to the Chart widget (or press the shortcut OPTION+L on Mac and Alt+L on Windows) and type “AAPL” without quotes, click the Apple symbol among the results and the candlestick chart will be displayed.

We’re going to use the WMA-150 (WMA with length 150) as our fast line (short-term) and WMA-200 as our slow line (long-term). To do this, click on the button showing 4 horizontal lines, highlighted in the picture below, and change the Fast and Slow WMA lines accordingly.

As you can see, in the chart below, the Fast WMA (green line) crossed the Slow WMA (red line) only once and it was only a short period of a downtrend.

5 years of Apple

What if we find that other large-cap stocks have the same behavior? There are two ways to check that out:

  1. Check manually every single large-cap stock
  2. Use an Arcade robot to do that for you by writing a strategy and backtesting 5 years back for all the large-cap stocks

If our theory is correct, we could write a strategy that buys then WMA-150 crosses over WMA-200 and sells when it crosses below.

5. Develop your first strategy

In Arcade, strategies can be written in Natural, Javascript, and Python languages. For our example, we’re going to use the Natural Language that doesn’t require any programming skill and it’s easy like writing sentences in English.

Every strategy is made of 2 parts:

  • Begin Trading is where you set when a new robot should buy stocks and monitor your trades. This is usually executed every minute for every stock symbol. If you’re using real-time trade, ask or bid price in your strategy, then it’s checked at every Tick message.
  • End Trading contains the conditions to end the execution of the robot and sells the purchased stocks. This section is not mandatory because you can configure the end of the trading via the user interface by setting max profit, stop loss, and much more.

Click on “Develop/Strategy” on the left menu bar and replace the content in the Begin Strategy section with this code:

yesterday 150 day simple moving average crosses above 200 day simple moving average

And this code at the End Strategy section that does the opposite, namely selling when WMA-150 crosses again below WMA-200:

yesterday 150 day simple moving average crosses below 200 day simple moving average

Strategy in Arcade

Remember to save the strategy you have created by clicking on the button “Save”. Pick a name like “wma-150/200 crossover”.

That’s all folks for the 1st part of this tutorial series. The next part covers backtesting our new strategy with Arcade. Jump to Part 2.

Have fun with algorithms,

Arcade Team

— —

Disclaimer: This article is for academic purposes only. The author is not suggesting using a particular strategy or providing any financial advice. For more information, check our risk disclaimer.

--

--