Welcome to this follow-up article, building upon our introductory guide on Unlocking the Power of Algorithmic Trading. Assuming you’ve grasped the fundamental concepts and benefits of Algorithmic Trading, it’s time to dive into creating your own trading system from scratch. In this article, we will provide a step-by-step guide on how to develop your first Algorithmic Trading system. Our tool of choice for this endeavor is Amibroker.

### Prerequisites:

• You should have a basic understanding of Technical Analysis.
• You need hands-on experience with Amibroker and AFL Coding.

Feel free to explore more articles related to Amibroker here.

For additional insights, you can also explore: Algorithmic Trading Courses for Beginners.

### Step 2: Translating Your Idea into an Algorithm

Next, you’ll start writing the code for your formulated trading plan. This code is essentially a set of instructions that a computer can interpret to execute your Buy/Sell logic. For this purpose, we’ll be using the Amibroker Formula Language (AFL). AFL is a high-level programming language that’s straightforward to comprehend, particularly when starting from the basics. Even individuals without a background in programming can learn AFL, saving them from unnecessary expenses on pre-made AFL solutions. If you’d like to explore AFL coding from scratch, you can refer to this tutorial. As an example, let’s say you’re trading based on the exponential moving average (EMA) crossover in the daily timeframe. In this scenario, you’d purchase a stock when the 50 EMA crosses above the 200 EMA, and sell when the 50 EMA crosses below the 200 EMA. For simplicity, let’s consider this a Buy-only strategy.

Below, you’ll find the basic AFL code for this logic.

```				```

//Parameters

MALength1 = 50;
MALength2 = 200;

Buy = Cross(ema( C, MALength1 ),ema( C, MALength2 ));
Sell =Cross( ema( C, MALength2 ), ema( C, MALength1 )) ;

Sell = ExRem( Sell, Buy );

Plot( Close, "Price", colorWhite, styleCandle );
Plot(ema( C, MALength1 ),"FastEMA",colorWhite);
Plot(ema( C, MALength2 ),"SlowEMA",colorBlue);

_SECTION_END();
```
```

Here’s how it appears when applied on a chart:

### Step 3: Evaluating Your Algorithm Through Backtesting

Backtesting is the process of assessing your Algorithm’s performance using historical data. This step is akin to what you manually did in Step 1. Fortunately, Amibroker boasts a robust backtest engine that can complete this task within seconds. All you need to do is import historical data for your preferred stocks into Amibroker. To gain a comprehensive understanding of the backtesting process within Amibroker, please refer to the official documentation link provided below.

For the purpose of backtesting this EMA Crossover strategy, we’ll use NSE Nifty as our preferred stock, commencing with an initial capital of 200,000 Rupees. Let’s assume that we purchase 2 lots (150 units) per transaction. Upon completing this backtest, you’ll receive a detailed report that includes key metrics such as your Annual CAGR, Drawdown, Net Profit/Loss percentage, and more. You can delve into various parameters by exploring the Amibroker Backtest report here.

Here’s a summary of our initial backtest:

 Parameter Value Nifty Initial Capital 200,000 Final Capital 1,037,655 Backtest Period 26-Mar-2002 to 23-July-2016 Net Profit % 418.83% Annual Return % 10.45% Number of Trades 11 Winning Trade % 54.55% Average Holding Period 227.91 days Max Consecutive Losses 2 Max System % Drawdown -33.24% Max Trade % Drawdown -29.94%

While this performance is decent, there’s room for improvement. The drawdown is slightly on the higher side, which could pose challenges for retail investors.

### Best Stock Trading Apps for Beginners in India

dexterDecember 11, 2023

### The Ultimate Guide to Swing Trading: Beginner Friendly

dexterOctober 29, 2023