Building A Stock Trading Bot in Python

Make Passive Income with an Automated Stock Trading Bot Developed in Python

Craig Mariani
5 min readAug 9, 2021

--

In this article we will be creating an automated system that can trade stocks while you are away from you computer. This article is not meant for financial advise but for educational purposes. First we will begin with discussing the trading strategy, then we will prepare the data and work on how the bot will execute trades through an exchange.

Developing The Trading Strategy

We will be implementing a simple cross-over strategy built around a slower and faster moving average. Moving averages are calculated by taking the recursively taking the average of the closed price of a stock over x number of days. Taking a smaller number for x will lead to a moving average that responds faster to the original closed price and give the illusion of moving “faster”. Likewise, using a larger number for x will lead to a moving average that responds slower to the original closed price and give the illusion of moving “slower”. When the faster moving average goes above the slower moving average this is an indication that the price will go up and is an optimal time to buy the stock, this type of indicator is known as a “Golden Cross”. When the faster moving average goes below the slower moving average…

--

--