Systematic Trading research and development, with a flavour of Trend Following

## Vortex indicator

#### February 15th, 2010 · 6 Comments · Backtest, Code, Software

I recently came across the Vortex Indicator, which aims to leverage the chaotic science of fluid mechanics (vortices) into a new indicator. I decided to code up this interesting concept in Trading Blox.

Vortex is present in chaotic movements such as fluid mechanics - picture courtesy of NASA

The indicator logic is described in the January issue of TASC (Technical Analysis of Stocks and Commodities) and sounds intriguing (link to PDF article). Without rehashing the details of the indicator calculation, it is very similar to Welles Wilder’s Directional Movement Index Calculation (DMI) except that Wilder’s Directional Movement (largest part of today’s range outside of yesterday’s range) is replaced by calculating the differences between today’s High and yesterday’s Low (positive Vortex Movement) and today’s Low and yesterday’s High (negative Vortex Movement).

TASC provides the Vortex indicator implementations in a wide collection of backtesting platforms (here). Unfortunately the Trading Blox implementation is not provided, which provided me a perfect opportunity to test and learn my new “backtesting toy” out.

### System Logic Flaw?

The authors of the indicator provide a sample Excel spreadsheet to illustrate their calculation. By replicating the logic in Excel to get a handle on it (link to Excel spreadsheet), I uncovered what I think is a flaw in the logic of the indicator of the calculation.

The VM calculations take the absolute value of the difference of opposite price extremes (High and Low) between today and yesterday. The screenshot of this Excel spreadsheet below clearly illustrates that this is a problem when dealing with gaps.

Additionally, one could argue that the simple summation/averaging of the VMs is different from the original DMI calculations which use Wilder Moving Averages.

I have emailed the authors of the indicator with a suggestion for a fix. I’ll relay their answer here.

First and foremost, this is a Trading Blox coding exercise so I was not too concerned about these flaws (although I might be tempted to implement my own version addessing both flaws later).

#### 1: Create Auxiliary Block

This will hold all indicators and implement their calculations. Call it Vortex Indicator.

#### 2: Create parameters

There is one parameter: the period for the Vortex indicator (VI) calculation:

#### 3: Create Indicators

These are the first-level calculations: the daily True Range (TR), and VM+ (plusVM) and VM- (minusVM).

VM+ indicator using a calculated formula

The code for each of these indicators is:

plusVM (VM+ is the difference between today’s High and yesterday’s Low):

`Abs(instrument.High - instrument.Low[1])`

minusVM (VM- is the difference between today’s Low and yesterday’s High):

`Abs(instrument.High[1]-instrument.Low)`

TR (standard True Range calculation):

`Max(instrument.High-instrument.Low,Abs(instrument.High-instrument.Close[1]), Abs(instrument.Low-instrument.Close[1]))`

#### 4: Create Instrument Permanent Variables (IPV)

This is for next-level calculations (Sum of TR, Sum of VM+ and VM-, VI+ and VI-). Setting these up as IPV allow for their values to be made available to other blocks (such the Entry block of a system).

Notice how the variable scope has been updated to System

The values for these IPVs are updated in the block Update Indicators script:

```plusVMSum=Sum(plusVM,viDays,0) minusVMSum=Sum(minusVM,viDays,0) TRSum=Sum(TR,viDays,0) plusVI=plusVMSum/TRSum minusVI=minusVMSum/TRSum```

Adding the auxiliary block to any System will enable it to access the values of the vortex indicators.

Here is how it could be done for a simple reversal system switching from Short to Long when VI+ crosses with VI- (and vice-versa).

#### Create an Entry Exit block

The system will have the Vortex Indicator Auxiliary block and our new Entry Exit block.

#### Add VI+ and VI- as IPV to the Entry Exit block

This is just a declaration to indicate that the values of these indicators are calculated in another block (our Vortex Indicator Auxiliary block).

The IPV is defined externally in another block (Vortex indicator)

The other parameters and indicators in this block are standard ATR Stop elements.

#### Code up the entry formula

Simple logic to enter long when VI+ is above VI- and no long position are in and opposite for short entry:

```VARIABLES: pvi TYPE: Floating pvi = plusVI VARIABLES: nvi TYPE: Floating nvi = minusVI VARIABLES: pos TYPE: String pos = instrument.position   IF plusVI > minusVI AND instrument.position <> LONG THEN   IF useATRStops THEN broker.EnterLongOnOpen( instrument.close - averageTrueRange * atrStop ) ELSE broker.EnterLongOnOpen ENDIF   ENDIF   IF plusVI < minusVI AND instrument.position <> SHORT THEN   IF useATRStops THEN broker.EnterShortOnOpen( instrument.close + averageTrueRange * atrStop ) ELSE broker.EnterShortOnOpen ENDIF   ENDIF```

Although I would like to do a more complete test to compare the Vortex Indicator to the DMI, all I have time left for today is a simple run of the system described above. I arbitrarily chose 39 for the VI period and here is the result:

CAGR Sharpe ratio Max DD
5.80%
0.10
42.4%

Logarithmic Equity curve from Vortex indicator system

And as a side note of caution when dealing with backtest results, I’ll show you a quick trick that will allow me to nearly double the CAGR (Compounded Annual Growth Rate) by not touching the system at all:

CAGR Sharpe ratio Max DD
10.93%
0.26
33.0%

Logarithmic Equity curve from Vortex indicator system (truncated period)

Notice what happened there: I just dropped years 1996 to 1999 from the backtests. Et voila! Surely a trick employed by more than one dubious trading systems salesmen…

### Conclusion

The authors claim that the Vortex indicator improve on the DMI invented by Welles Wilder Update: the authors have sent me an email to clarify that they have not made such claim (I was merely interpolating, given the ressemblance of the Vortex indicator with the DMI). It would be interesting to test this as the idea of mixing chaos/fluid mechanics concepts to price movements is appealing. Fixing the indicator flaws would be good too. More to come… (update: on the next post, I also explain the authors response to my claim of the indicator having flaws).

link to Vortex indicator block file (tbx)
link to VI sample Entry Exit block (tbx)

Tags: ·····

### 6 Comments so far ↓

• Damian

Great stuff – thanks for giving me a sense of what I’m missing. I hope you keep posting on your progress, because I’d just love to learn more about TBB.

• Hi Damian, That’s more or less the idea. I wish I had more posts like these available when I was researching which back-testing platform to use. Glad you are finding it useful.
I’ll definitely try to keep the TBB tutorial/demo angle in some of the posts.

One thing to note as well is that I was “mightily” impressed with the richness of information in the customer-only section of the TB forum. I had fun playing with TB at the weekend but I hit a few issues/interrogations, etc. (learning curve stuff). Every time so far, there was an answer for me waiting at the end of a forum or user manual search. Great! (I really dont regret TradersStudio)

• Damian

Yeah, I’m with you on Tradersstudio – just disappointment after disappointment. Still doesn’t have the new version out. I remember hearing that TBB can now deal with fundamental info (earnings, etc) – can you confirm?

It does amaze me that their website contains basically no useful information on the program.

Does it deal with real-time data at all?

• I went through a lot of information this weekend (through Trading Blox forum and user manual) and if I can recall correctly, there are 2 “extra data” fields which could be used to import anything else (including fundamental data) and which are available during simulation. On top of that there is the possibility to import other files during simulation (which I assume could also be used for fundamental data) – I havent tried those myself yet though.

I was also pleased to see that they are working on Walk-Forward in their latest beta (3.4).

As far as I am aware, Trading Blox deals with intra-day data (not so well from comments I read) but I dont think real-time (ie backtest only).

Agree with the info on their website, could be more complete (although manuals are available in full…) – as mentioned the customer-only section (with free code, etc.) really adds a dimension to the forum + info available. Shame you cannot see it before you purchase (although I understand why they do it). I guess the trial (which is full TBB available for a week) is a great way to learn more about the Trading Blox Builder platform

• Damian

I can’t believe they don’t have walk-forward yet. Is there any place where they announce what is in each release? I’m wondering if they have a major release coming up any time soon.

• the announcement for the 3.4 beta (with all added features) is in the Customer Support forum… so inaccessible to the public unfortunately – I havent seen a release summary on their site…