# Optuma Swing Charts: Trend vs Direction

Use the scripting language to identify swing trend versus direction in scans and watchlists, and to create a swing ranking value.

This is the second in a series of articles on using Optuma’s swing charts and overlays - particularly when it comes to creating scripts for scans or testing.

​In the first article we looked at an easy way to identify swing trends using overlay colours and a simple scan formula. In this article we can take it a step further by looking at the swing direction within the current trend, i.e. to see whether the current swing is a dip down in an upward trend, or a bounce in a downward trend.

To scan for when the current swing is down but the overall trend is up we can combine the SWINGDOWN() function for direction, with the SWINGTRENDUP() function (or SWINGUP() and SWINGTRENDDOWN() for the opposite).

Here’s the formula for swings based on 10% price moves:

Now you might be wondering why the CLOSE()>0 condition is required to produce the desired results. This is one of the difficult issues regarding swing charts, in that there is not a swing value for every date, only when the swings occur (this is what we call a swing list). By adding CLOSE()>0 - which will always be true - this converts the swing list into a bar-by-bar list, therefore giving a swing value for every day, allowing the scan to work as expected.

## SwingList vs BarList

If I’ve just confused you, click here for Mathew Verdouw’s detailed explanation on swing lists versus bar-by-bar lists

Using the above formula in a scan will return stocks that are currently in an uptrend but the latest direction is down, as per this example of CBA:

Swing Trend vs Direction

See this video to link the scan results to a watchlist in a workbook. Whenever the workbook is opened the list will update with the latest scan results.

## Creating a SwingRank value

Using these functions it is possible to create a ranking value depending on the current swing trend and direction. These are the four scenarios, along with their SwingRank value:

Swing Trend negative and Direction negative: SwingRank = 0
Swing Trend negative and Direction positive = 1
Swing Trend positive and Direction negative = 2
Swing Trend positive and Direction positive = 3

Here’s an example of the Dow 30 stocks in a watchlist, based on a 3 bar Gann swing:

Swing Rank

Apple is showing a current value of 3 as both the trend and direction are up, whereas CVX is a 2 and in a possible ‘buy the dip’ situation, with plenty showing 0s or 1s.

Here’s the formula to calculate the SwingRank (remember to change S1 variable to use a different swing type):

Clients can click the button on the right to save and open a sample workbook with separate tabs for Australian and US markets with the SwingRank watchlist column (based on daily 3 bar Gann Swings). For other regions or lists clients can click the Linked to List watchlist property and select an alternative Symbol List to use.

Next time we’ll look at comparing previous swing values which can be used to identify consecutive higher highs or lows, or to calculate retracement levels.

Apple is showing a current value of 3 as both the trend and direction are up, whereas CVX is a 2 and in a possible ‘buy the dip’ situation, with plenty showing 0s or 1s.

Here’s the formula to calculate the SwingRank (remember to change S1 variable to use a different swing type):