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.
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.
Trading Blox implementation
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).
I suggest you follow the calculation logic on the PDF article or the Excel spreadsheet. Here is how I implemented the Vortex Indicator in Trading Blox:
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).
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)
minusVM (VM- is the difference between today’s Low and yesterday’s High):
TR (standard True Range calculation):
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).
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
Use in Trading Blox
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 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
Trading Blox test
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|
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|
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…
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).