Skip to main content

Amibroker is the most efficient tool to build and backtest trading systems with minimum coding. Using amibroker you can develop systems across different instruments like equities, futures & options, commodities, forex, etc. In this article, we’ll understand how to develop an options trading system in Amibroker.

You’ll also get a complimentary AFL code (from the end of this post) that can be used. to backtest options strategies.

Also Read: Getting Started with Amibroker – Features, Pros-Cons & Learning Resources

How is developing Options based trading systems different from other conventional systems?

Developing an options trading system in Amibroker is fairly complex and requires extra computational steps compared to the conventional stock-based systems. The reasons are manifold. 

First of all, options itself is a complicated instrument. The options pricing is determined by a variety of factors and not just supply/demand. All these factors may act as variables while developing an options based trading system.

Also, when we talk about any option symbol, it’s not just ‘singular’, rather it is a bunch of different symbols with different strike prices and expiries. This is collectively called as options chain. While developing a trading system, any symbol from the options chain can be used based on your system logic.

First Step: Import Historical Options Data into Amibroker

The first and the most important step is to import historical options data into Amibroker which can be used for backtesting.

To do the same, you may refer to the below article. It lists down the steps with screenshots.

Historical Options Data Free Download – Intraday 1 Minute

Follow each step in this article and segregate the symbols into different watchlists which will make backtesting easier.

Please note that this article is confined to Nifty and Banknifty options, in case you want to backtest any other options and have data handy for it, please feel free to follow the same steps and import the data into Amibroker.

Trading System Logic

We are going to illustrate the most popular yet simple options trading strategy known as “Short Straddle

The strategy rules go like below:

  • Entry Time: 09:20 AM
  • Exit Time: 15:05 PM
  • Entry Rules: Sell 1 lot ATM Call Option and 1 lot ATM Put Option at entry time
  • Exit Rules: Square off all open positions at the exit time
  • Stop Loss: 40% per leg
  • Expiry: Use near week expiry options for taking any positions

This strategy is popularly known as 0920 straddle.

AFL Coding Logic

The AFL for this strategy is designed primarily to backtest the system, rather than pretty plotting in the charts.

The backtesting is carried out on each individual option strike in the option chain.

Here’s the high-level logic of the AFL code:

For each Options symbol in the Database:

  • Check if it is “At the Money(ATM)” strike at 9:20 AM. This is done by calculating the ATM strike price at 09:20 AM (using the Round function on Underlying Open), and then comparing it with the numeric part of options symbol name.
  • Check if it is a weekly option contract. This is an important step as the database also contains monthly option strikes, and on the last week of the month, the monthly strikes should be considered as weekly.

If both the conditions are TRUE and the time is 09:20 AM, Short position is taken on that symbol. And the square off happens either at stop loss level (40%) or at 15:05 PM.

Apart from this the backtesting parameters like initial equity, commission, margin, position size, etc are embedded in the AFL code.

AFL Screenshot

Below is the screenshot of this AFL when plotted on the NIFTYWK17400CE symbol:

The Best Tool for Backtesting your Trading Systems – Expert opinion

Backtesting Procedure

In order to backtest this trading system, follow the below steps:

Step 1: Click on File → New → Analysis

Step 2: Select your AFL formula at the top right of the analysis window

Step 3: In the Apply To dropdown, select “All Symbols” if you want to backtest on all the symbols in your database, or select “Filter” if you want to backtest on a specific watchlist

Click on the “Backtest” button, the results would come up in a few seconds.


Download AFL

You may download the AFL code by entering your Email ID in the below form. Don’t worry, we hate SPAM just as much as you do! You can unsubscribe anytime.

After downloading, you can either open it in notepad or directly import it to Amibroker

Final Thoughts – Options Trading System in Amibroker

We hope you understood how an options trading system is built and backtested in Amibroker. At a glance, it may sound complex, but the more you try to understand it, the simpler it becomes.

It’s scalable too, you can easily modify the logic to create any other options strategy. Backtesting is fairly quick, and that’s the beauty of Amibroker.

Let us know in the comments section if you have any questions about this system.

In case you are looking for step-by-step training on Amibroker and trading system development, please check out this link 

Leave a Reply