Algorithmic Trading and Strategies.
Boris Kushnarev
Business Analyst at Optus | Data Analytics Consultant at The Data School | Neo4j Certified Professional | Tableau Data Analyst Certification | Alteryx Advanced Certified | [email protected]
Algorithmic trading, or algotrading, has gained popularity for several reasons. First, the high-level programming language Python allows users to easily program algorithms, democratizing access to advanced trading technologies. Secondly, data availability through REST APIs and WebSockets is accessible through various data providers, enabling real-time decision making and increased market responsiveness. Thirdly, numerous brokers provide APIs that enable communication with their systems for sending orders, monitoring open and closed positions, checking account balances, and accessing other functionalities. This integration facilitates a more streamlined and efficient trading process. Finally, with such algorithms, traders do not need to be physically present at their computers to trade, as these automated systems handle the trading. This not only saves time but also enhances the potential for executing trades at optimal times without human delay. In this article, I will focus on algotrading strategies to introduce you to the main concepts, exploring how they can significantly improve trading efficiency and effectiveness.
Algorithmic trading strategies are diverse, ranging from simple techniques to complex models that incorporate machine learning or deep learning. This article will focus on a strategy known as "bouncing from moving average curves," where trades are executed based on the price interactions with these curves. Before diving into the specifics of this strategy, let me first introduce some basic concepts for readers who may be unfamiliar with trading.
In the realm of algorithmic trading, understanding the structure and use of candles and dataframes is crucial. Candles, or candlesticks, are graphical representations used in financial charts to display the price movements of securities, derivatives, or currency pairs within a specified timeframe. Each candlestick can represent various time intervals, such as 5, 15, 30 minutes, 1 hour, 4 hours, or one day, and consists of a body and wicks. The body illustrates the opening and closing prices, while the wicks indicate the high and low prices during the trading period. A candlestick is considered bullish (often colored green) if the closing price is higher than the opening price, indicating a price increase. Conversely, it is bearish (typically colored red) if the closing price is lower than the opening price, indicating a price decrease. Candlesticks can vary significantly in form, reflecting different market behaviors. For a visual guide to basic candlestick formations, refer to the image below.
Candlestick data can be effectively organized and manipulated using dataframes, which are pivotal data structures in algorithmic trading. Dataframes facilitate the analysis of historical data, calculation of technical indicators, backtesting of trading strategies, and identification of optimal times for opening and closing positions. They offer a tabular format that is both intuitive and accessible, enabling traders to efficiently slice, dice, and transform data to extract meaningful insights and make informed trading decisions. Together, candlesticks and dataframes constitute the foundation of technical analysis in trading systems. They empower traders to clearly visualize market trends and patterns, and to implement strategies based on precise, structured data.
Moving averages are fundamental tools in financial analysis for trading. They serve to smooth out price data by creating a continuously updated average price, which helps traders identify trends devoid of short-term fluctuations. Typically, moving averages are calculated in two main types: the Simple Moving Average (SMA) and the Exponential Moving Average (EMA). The SMA calculates the average price over a specific number of time periods, equally weighting each period. In contrast, the EMA gives more weight to recent prices, making it more responsive to new information. By overlaying moving averages of different lengths on a chart, traders can spot crossover points where short-term price trends diverge from long-term trends, signaling potential buying or selling opportunities. This method is particularly valued for its ability to highlight directional momentum and to aid in the determination of optimal entry and exit points in the market. While SMA and EMA focus solely on price information, other indicators like the Volume-Weighted Average Price (VWAP) incorporate both volume and price data, offering a more comprehensive analysis tool.
In addition to moving averages, another pivotal indicator employed in our trading strategy is the Relative Strength Index (RSI). The RSI is a momentum oscillator that measures the speed and change of price movements, helping traders identify overbought or oversold conditions in the market. It operates on a scale from 0 to 100, with readings typically considered overbought when above 70 and oversold when below 30. This indicator is particularly useful for signaling potential reversal points by comparing the magnitude of recent gains to recent losses. By integrating RSI into our strategy, we can more effectively gauge the market's sentiment and make informed decisions about when to enter or exit trades, enhancing our ability to capitalize on market fluctuations.
Strategies can also be differentiated by the period of holding position. It can be intraday when the position is open only within a day. On the other hand, the position can be open for a few days and it is called positional (swing) trading. We have developed strategy for both types of trading. Our intraday strategy uses 3 and 5 minutes timeframe while the swing strategy uses 30 minutes timeframe. An example of the swing trading for AMD calculated by our algorithm is presented below. At the first candle we can see that the open and close prices are above of all curves and the RSI condition is also satisfied. So, the position is open. It is hold for seven days until it hit the calculated take profit price.
To accurately assess the performance of our trading strategy, it is essential to compare it against a benchmark. In our case, the benchmark is represented by the SPY index, which reflects the overall performance of the market. This comparison helps us understand how our strategy performs relative to the broader market trends. In this particular case, AMD overperforms market by about 30% for the considered period.
领英推荐
In conclusion, the exploration of algorithmic trading strategies reveals a dynamic and potent field that leverages advanced technologies to enhance market performance. Through the detailed examination of strategies such as bouncing from moving average curves and the integration of sophisticated tools like dataframes and candlestick analysis, traders are equipped to navigate the complexities of the financial markets more effectively. By comparing these strategies against benchmarks like the SPY index, we gain valuable insights into their relative performance, enabling informed decision-making. As the landscape of trading continues to evolve with technological advancements, staying abreast of these strategies and continuously refining them will be crucial for traders aiming to maintain a competitive edge. Embracing these tools and techniques not only helps in optimizing trade outcomes but also in understanding the broader market dynamics at play.
This work has been completed in collaboration with Talgat Baibussinov .