I have been sharing code throughout the blog in various posts. Although there is a “Code” category in the blog, a dedicated page is probably the best way to organise this, before it starts getting messy. I have therefore added a main page (free code) in the nav bar.
Hope you find it useful. It has been updated with all pieces of code published so far and I will continue to do so with all further code.
Improved Vortex indicator
As mentioned in the original Vortex indicator post, I thought there were some flaws that needed to be corrected in the original version published by the authors (Etienne Botes & Douglas Siepman). I have since heard from them .
They gave me a detailed explanation regarding the logic of their design. The most important consideration is that they are using their indicator on Forex – which is a 24-hour market and therefore exhibits virtually no gap. Moreover, I believe they favoured a simple moving average (to Wilder’s exponential one) to add extra lag / beneficial noise filtering.
Anyhow, I still thought that the indicator could be improved for non-Forex markets. I also thought that the process could be taken further by creating the AVX: the Average Vortex Index (similarly to Welles Wilder’s ADX, based on the DMI). Well, I coded that up as well.
Trading Blox blocks for all this code can be downloaded at the end of the article (or in the new free code section).
Updated calculation logic
I started prototyping the calculations in Excel for the original Wilder DMI and ADX, the original Vortex indicator and my improved version. Please find the Excel spreadsheet for your perusal.
As mentioned in the initial Vortex indicator post, the original calculation did not handle gap days appropriately (in my opinion) and was not replicating the smoothing implemented in Wilder’s DMI by the use of an exponential Moving Average (Wilder’s to be precise) for the VI/TR calculation.
The logic implemented is as follows:
VM+ = High - Low
(VM+ is today’s High minus yesterdays’ Low, can be negative, in case of down gaps)
VM- = High - Low
(VM- is yesterday’s High minus today’ Low, can be negative, in case of up gaps)
True Range (TR) is calculated as per the standard formula.
These 3 daily indicators are then smoothed using the “Wilder” exponential moving average (alpha = 1 / N ). These give us AVM+, AVM- and ATR.
Normalise AVM+ and AVM- by ATR to obtain the improved VI+ and VI-.
VI+ =AVM+/ATR VI- =AVM-/ATR
Building upon these calculations, we can just replicate the ADX logic to create the AVX indicator:
Calculate the VX:
VX = (VI+ - VI-) / (VI+ + VI-) x 100
VX is then smoothed (using Wilder moving average) to produce the AVX.
Now we’re talking!
Note that because VM and VI both have higher values than the original DM and DMI, VX and AVX,which express the relative difference of VI+ and VI-) will not register values as high as the ADX. But that’s ok – it just means we work on a different scale (where AVX>15 might be similar to ADX>60).
Vortex to the test
The vortex indicator can be used as an entry signal (go long when VMI+ crosses above VMI- and go short with the opposite cross). In addition, the AVX can be thought of as a measure of the strength of a directional vortex movement. The entry signal could be enhanced by only taking the signals where the AVX breaches a specific strength threshold (note: this is a very similar logic to the ADX system that ships with Trading Blox).
Calculating the e-ratio for the VMI/AVX entry is a great way to measure the edge of that specific entry.
Another great thing is the Blox marketplace where Trading Blox users share their custom code. And guess what? There was a block available for e-ratio calculation. Great! I love it when I can leverage existing code…
With a bit of updating of the system I managed to run the e-ratio calc on 3 different entry signals:
- Simple VMI cross
- VMI cross with AVX threshold filter (threshold = 10)
- VMI cross with AVX threshold filter (threshold = 15)
Below are the charts for each of the entries:
Notice how the AVX threshold does not seem to help and is completely counter-productive in the “AVX>15” case. In a classic example of curve-fitting / data snooping, we could decide to turn around the AVX threshold logic and only take signals for which the AVX is below 15. But we will not do that. Bad practice ;-)
I was not expecting much out of this study. I was mostly using it as material for getting to use Trading Blox. I was not surprised by either: I found Trading Blox easy to get a handle on. Definitely a productivity boost compared to TradersStudio, both in terms of development and simulation running time.
With regards to the vortex indicator, it does seem to provide a (small) edge when used as the authors intended to (albeit in a modified form). The AVX filtering, on the other hand, did not seem to improve anything at all. Maybe the edge would have been better, had I not “messed up” with the indicator…
Please find below the individual components (blocks) for download:
improved Vortex Indicator & AVX auxiliary block file (tbx)
AVX Entry Exit block (tbx)
AVX System (tbs)
The lot in a zip file