## Introduction

The Accumulative Swing Index (ASI) is designed to isolate the “real” price of a security by comparing the relationships between the current prices (open, high, low, close) and the previous period’s prices. This guide will provide an in-depth look at the ASI, helping traders understand how it works and how to use it effectively in their trading strategies. We will also cover how to approach coding it in Python and R for those interested in using it for automated strategies.

## Origins of Accumulative Swing Index (ASI)

The ASI was developed by J. Welles Wilder, a renowned figure in the world of technical analysis. Wilder introduced the ASI, along with several other ground-breaking indicators, in his 1978 book “New Concepts In Technical Trading Systems.” Wilder’s work has had a profound impact on technical analysis, and his indicators, including the ASI, are still widely used by traders today.

Wilder developed the ASI as part of his quest to create a trend-following system that could accurately reflect the real price movements of a security. He believed that by comparing the relationships between the current and previous prices, the ASI could provide a more accurate picture of a security’s price trend.

## Mathematical Construction

The Accumulative Swing Index (ASI) is derived from the Swing Index (SI), which is calculated using a specific formula. Here’s how it works:

The Swing Index (SI) is calculated as follows:

SI = 50 \times \left[ \frac{(C - C_{y} + 0.5(C - O_{y}) + 0.25(C - O))}{R} \right] \times \frac{K}{T}

which can also be written **SI = 50 × [(C – Cy + 0.5(C – Oy) + 0.25(C – O)) / R] × K/T**

In this formula:

- SI represents the Swing Index
- C is the closing price for the current period
- Cy is the closing price for the previous period
- H is the highest price for the current period
- Hy is the highest price for the previous period
- K is the larger of (Hy – C) and (Ly – C)
- L is the lowest price for the current period
- Ly is the lowest price for the previous period
- O is the opening price for the current period
- Oy is the opening price for the previous period
- R is a variable that changes based on the relationship between C, Hy, and Ly
- T is the maximum amount of price change for the period (i.e. limit up or limit down value in futures)

‘K’ is the maximum of the following two differences:

- The difference between the previous period’s high price and the current period’s closing price.
- The difference between the previous period’s low price and the current period’s closing price.

The variable R is determined by the largest of the following:

- H – Cy
- L – Cy
- H – L

The calculation for R varies based on which of the above is the largest:

- If (H – Cy) is largest, R = H – Cy – 0.5(L – Cy) + 0.25(Cy – Oy)
- If (L – Cy) is largest, R = L – Cy – 0.5(H – Cy) + 0.25(Cy – Oy)
- If (H – L) is largest, R = H – L + 0.25(Cy – Oy)

Once the Swing Index is calculated, it is then accumulated over time to form the **Accumulative Swing Index**. The indicator can have a wide range of values depending on the price swings of the security and the period over which it’s calculated. As a price-centric index, it generally follows the candlestick pattern of a price chart. The Swing Index and ASI can be used for analyzing all types of securities, including futures and other assets.

Later in this post we will be showing you how you can code this formula which you could then expand upon to create your own screener.

## Purpose and Design

The Accumulative Swing Index (ASI) was designed with the primary purpose of capturing the “real” price of a security. It does this by comparing the relationships between the current prices (open, high, low, close) and the previous period’s prices. This comparison allows the ASI to isolate the true price movements and provide a more accurate reflection of a security’s price trend.

Wilder intended the ASI to be used as part of a trend-following system. The ASI’s ability to accurately reflect price movements makes it a valuable tool for identifying and following trends. When the ASI is rising, it indicates that the trend is upward, and when it’s falling, it suggests a downward trend.

## How to Use Accumulative Swing Index (ASI) for Trading

The ASI can provide valuable signals for traders. Here’s how you can interpret these signals:

**Buy Signals**: A buy signal is generated when the ASI line crosses above the zero line or breaks above a previous swing high. This indicates that the trend is upward and it might be a good time to enter a long position.**Sell Signals**: A sell signal is generated when the ASI line crosses below the zero line or breaks below a previous swing low. This suggests that the trend is downward and it might be a good time to enter a short position.**Divergence**: If the price is making new highs but the ASI isn’t, or if the price is making new lows but the ASI isn’t, this could indicate a potential price reversal. This divergence between the price and the ASI can provide an early warning of a trend change.

Remember, like all trading indicators, the ASI should be used in conjunction with other tools and analysis to confirm signals and reduce the risk of false signals.

## Limit Move Value

The “limit move value” or ‘T’ in our formula, typically refers to a pre-defined maximum allowable price move for a particular trading instrument in a single trading session. This concept is often used in futures trading for products such as cattle, where exchanges often set daily limit up and down values to prevent excessive volatility or manipulation. You can find these values listed on exchange websites for the products you are interested in.

In the context of the ASI, if you find a limit move value setting, then it is used to adjust the calculations based on the maximum expected price change for the trading period. This can help to normalize the ASI values and make them more comparable across different trading periods or different securities.

## Pros and Cons of Using ASI

Like any technical indicator, the ASI has its strengths and weaknesses. Understanding these can help you use the ASI more effectively in your trading.

**Pros**:

**Trend Identification**: The ASI is excellent at identifying the underlying trend of a security. It can help traders identify whether the trend is upward or downward, which can inform their trading decisions.**Price Isolation**: The ASI isolates the “real” price of a security by comparing the relationships between the current and previous prices. This can provide a more accurate reflection of a security’s price trend.

**Cons**:

**Complexity**: The ASI is a complex indicator that requires a good understanding of technical analysis and price movements. It’s important to fully understand how it works before using it in your trading strategy.**False Signals**: Like all technical indicators, the ASI can generate false signals. It’s important to use the ASI in conjunction with other tools and analysis to confirm signals and reduce the risk of false signals.

## Coding it in Popular Trading Languages

Implementing the ASI in a trading system requires coding the formula into a programming language that can handle financial data. Here, we’ll provide examples in Python and R, two popular languages used in trading.

```
def calculate_ASI(data):
# Calculate the necessary components
data['K'] = np.maximum(data['High'].shift(1) - data['Close'], data['Low'].shift(1) - data['Close'])
data['T'] = data['Close'].shift(1) * 0.07 # 7% of the previous day's closing price for S&P 500 futures
condition1 = (data['High'] - data['Close'].shift(1)) > data['Low'] - data['Close'].shift(1)
condition2 = (data['High'] - data['Close'].shift(1)) > data['High'] - data['Low']
condition3 = (data['Low'] - data['Close'].shift(1)) > data['High'] - data['Close'].shift(1)
condition4 = (data['Low'] - data['Close'].shift(1)) > data['High'] - data['Low']
data['R'] = np.where(condition1 & condition2,
data['High'] - data['Close'].shift(1) - 0.5 * (data['Low'] - data['Close'].shift(1)) + 0.25 * (data['Close'].shift(1) - data['Open'].shift(1)),
np.where(condition3 & condition4,
data['Low'] - data['Close'].shift(1) - 0.5 * (data['High'] - data['Close'].shift(1)) + 0.25 * (data['Close'].shift(1) - data['Open'].shift(1)),
data['High'] - data['Low'] + 0.25 * (data['Close'].shift(1) - data['Open'].shift(1))))
# Calculate the Swing Index
data['SI'] = 50 * ((data['Close'] - data['Close'].shift(1) + 0.5 * (data['Close'] - data['Open']) + 0.25 * (data['Close'].shift(1) - data['Open'].shift(1))) / data['R']) * (data['K'] / data['T'])
# Calculate the AS Index
data['ASI'] = data['SI'].cumsum()
return data
```

Here’s a breakdown of what the above function does:

- Computes ‘K’, which is the larger of the difference between yesterday’s high and today’s close, and the difference between yesterday’s low and today’s close.
- Computes ‘T’, which is the maximum price change for the period, I’ve added 7% here just for example as it happens to be the first level circuit breaker in ES S&P500 emini futures. T was originally designed to be the limit up or limit down setting for a trading period more commonly triggered in agricultural futures such as cattle or grains.
- Determines the conditions for different cases to calculate ‘R’ based on whether (H – Cy), (L – Cy), or (H – L) is largest.
- Calculates ‘R’ accordingly based on the conditions.
- Calculates the Swing Index (SI) using the provided formula.
- Computes the Accumulative Swing Index (ASI) by cumulatively summing the Swing Index (SI) values.

In R it would be:

```
calculate_ASI <- function(data) {
# Calculate the necessary components
data$K <- pmax(data$High - lag(data$Close), data$Low - lag(data$Close))
data$T <- lag(data$Close) * 0.07
condition1 <- (data$High - lag(data$Close) > data$Low - lag(data$Close))
condition2 <- (data$High - lag(data$Close) > data$High - data$Low)
condition3 <- (data$Low - lag(data$Close) > data$High - lag(data$Close))
condition4 <- (data$Low - lag(data$Close) > data$High - data$Low)
data$R <- ifelse(condition1 & condition2,
data$High - lag(data$Close) - 0.5 * (data$Low - lag(data$Close)) + 0.25 * (lag(data$Close) - lag(data$Open)),
ifelse(condition3 & condition4,
data$Low - lag(data$Close) - 0.5 * (data$High - lag(data$Close)) + 0.25 * (lag(data$Close) - lag(data$Open)),
data$High - data$Low + 0.25 * (lag(data$Close) - lag(data$Open))))
# Calculation of SI (Swing Index)
data$SI <- 50 * ((data$Close - lag(data$Close)) + 0.5 * (data$Close - lag(data$Open)) + 0.25 * (lag(data$Close) - lag(data$Open))) / data$R * (data$K / data$T)
# Calculation of ASI
data$ASI <- cumsum(data$SI, na.rm = TRUE)
return(data)
}
```

‘T’ is again calculated as 7% of the closing price from the previous period for the reasons mentioned above. It’s important to handle potential NA values in your data, especially for the first row (since the

function is used).**lag**

## To Plot it On a Chart with Python

Let’s look at some code for plotting your ASI indicator for Microsoft stock using VSCode software. Make sure you have Python installed first the use **pip install** to install the required modules by typing in the Terminal e.g. **pip install yfinance** etc. The Terminal will tell you if you are missing any installations when you run it at the end.

**Step 1: Import Required Libraries and Define Functions**

- Start a new Python file in VSCode.
- Copy the following code into the file. This code imports the required libraries and defines the functions for calculating K, R, SI, and ASI.

```
import yfinance as yf
import pandas as pd
import mplfinance as mpf
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import numpy as np
def calculate_K(df):
df['K'] = np.maximum(df['High'].shift(1) - df['Close'], df['Low'].shift(1) - df['Close'])
return df
def calculate_R(df):
conditions = [
((df['High'] - df['Close'].shift(1)) > (df['Low'] - df['Close'].shift(1))) & ((df['High'] - df['Close'].shift(1)) > (df['High'] - df['Low'])),
((df['Low'] - df['Close'].shift(1)) > (df['High'] - df['Close'].shift(1))) & ((df['Low'] - df['Close'].shift(1)) > (df['High'] - df['Low']))
]
choices = [
df['High'] - df['Close'].shift(1) - 0.5 * (df['Low'] - df['Close'].shift(1)) + 0.25 * (df['Close'].shift(1) - df['Open'].shift(1)),
df['Low'] - df['Close'].shift(1) - 0.5 * (df['High'] - df['Close'].shift(1)) + 0.25 * (df['Close'].shift(1) - df['Open'].shift(1))
]
df['R'] = np.select(conditions, choices, default=df['High'] - df['Low'] + 0.25 * (df['Close'].shift(1) - df['Open'].shift(1)))
return df
def calculate_SI(df):
df = calculate_K(df)
df = calculate_R(df)
df['SI'] = 50 * ((df['Close'] - df['Close'].shift(1) + 0.5 * (df['Close'] - df['Open'].shift(1)) + 0.25 * (df['Close'] - df['Open'])) / df['R']) * (df['K'] / df['High'] - df['Low'])
return df
def calculate_ASI(df):
df = calculate_SI(df)
df['ASI'] = df['SI'].cumsum()
return df
```

### Step 2: **Fetch Data and Calculate ASI**

After the function definitions, add the code for downloading the data from Yahoo Finance and calculating the ASI. You can replace ‘MSFT’ with the ticker symbol for the asset you’re interested in.

```
# Fetch the data
data = yf.download('MSFT', start='2022-07-17', end='2023-07-17')
# Calculate the ASI
data = calculate_ASI(data)
# Invert the ASI line
data['ASI'] = data['ASI'] * -1
```

**Step 3: Plot the Data**

After the ASI calculation, add the code to plot the data. This code also sets up the layout of the plot, adds additional plots for volume and ASI, and adds a legend.

```
# Define the additional plots as a list of dictionaries
apd = [
mpf.make_addplot(data['ASI'], panel=2, color='g', secondary_y=False, ylabel='ASI'),
mpf.make_addplot([0]*len(data), panel=2, color='r')
]
# Set the panel sizes. The first panel (candles) is 5 times the size of the second and third panels (volume and ASI)
panel_sizes = (5, 1, 3)
# Create a subplot for the ASI and add the additional plot
fig, axes = mpf.plot(data, type='candle', style='yahoo', addplot=apd, volume=True, volume_panel=1, panel_ratios=panel_sizes, title='Microsoft and ASI', returnfig=True)
# Create legend using dummy lines
legend_lines = [Line2D([0], [0], color='g', lw=1.5), Line2D([0], [0], color='r', lw=1.5)]
axes[2].legend(legend_lines, ['ASI', 'Zero Line'], loc='lower left')
# Show the plot
mpf.show()
```

Save the file, and run it in VSCode. This will fetch the data for the specified asset, calculate the ASI, and display a chart with the price, volume, and ASI. You will then end up with a chart that looks similar to mine below:

Note that we have excluded ‘T’ from this coding example, which is related to limit up and limit down in futures and therefore not applicable to this stock chart.

## Applications

The ASI can be used in various trading scenarios. For instance, futures traders often use it to identify and follow breakout trends, particularly in markets prone to trend.

One notable real-world application of the ASI therefore is in the commodities market. Given the ASI’s ability to isolate the “real” price of a security, it can be particularly useful in markets that are subject to large price swings, such as commodities. By accurately reflecting these price movements, the ASI can help traders make more informed decisions about whether an underlying trend is building or whether those moves can be dismissed while in search of something better.

## Comparing it with Other Trading Indicators

While the ASI is a powerful tool, it’s important to remember that no single indicator should be used in isolation. The ASI can be even more effective when used in conjunction with other indicators.

For example, the ASI and the Relative Strength Index (RSI) can be used together to confirm trend strength and spot potential reversals. The ASI could be used to identify the trend, while the RSI could be used to confirm the trend’s strength and identify overbought or oversold conditions.

## Key Takeaways

**Origins and Purpose of ASI**: The Accumulative Swing Index (ASI) was developed by J. Welles Wilder, with the primary purpose of capturing the “real” price of a security by comparing the relationships between the current and previous prices.**Mathematical Construction**: The ASI is derived from the Swing Index (SI), with additional components such as K, R, and T included in the calculation. Understanding these individual elements is key to understanding the ASI as a whole.**Usage in Trading**: ASI can be used for identifying and following trends, spotting potential reversals, and generating buy and sell signals. The ASI should be used in conjunction with other indicators to confirm signals and reduce the risk of false signals.**Limit Move Value**: The ‘limit move value’ or ‘T’ is a concept often used in futures trading, referring to a maximum allowable price move in a single trading session. In the ASI, ‘T’ is used to adjust calculations based on the maximum expected price change for the trading period.**Pros and Cons**: The ASI is excellent at trend identification and price isolation but can be complex and generate false signals. Traders should understand these strengths and weaknesses before incorporating it into their strategies.**Coding ASI**: The guide provides examples of how to implement the ASI in Python and R, two popular languages used in trading.**Comparison with Other Indicators**: The ASI can be even more effective when used in conjunction with other indicators, such as the Relative Strength Index (RSI), to confirm trend strength and spot potential reversals.**Real-World Applications**: One notable real-world application of the ASI is in the commodities market, given its ability to isolate the “real” price of a security in markets that are subject to large price swings.**Concluding Advice**: The ASI is a powerful tool for traders, but it should be used in conjunction with other indicators and tools for the most effective results.

If you’re interested in learning more about the ASI the original text might be helpful -“*New Concepts in Technical Trading Systems*” by J. Welles Wilder, 1978: This is the book where Wilder first introduced the ASI, along with several other ground breaking indicators.

## Leave a Reply