Registered User Joined: 12/5/2004 Posts: 10
|
Hi,
I have been in contact with Support about a problem with the Detrended Price Oscillator (DPO).
Here is my last message to Support as well as the e-mail that was sent to me in response to earlier correspondence. In the first reply to me, I was told by support that they had to refer to the programmers. In a message just received from J.C. Bryan, he wrote "
The trainers are the people that write the conditions, rules, formulas and calculations for all the Worden products"
Here is the earlier correspondence.
Thanks for getting back to me. Most sources that I have seen are in agreement with the definition you supplied, printed in a simplified manner here.
1. Decide on the time frame that you wish to analyze. Set n as half
of
that cycle period.
2. Calculate a simple moving average for n periods.
3. Calculate (n / 2 + 1)
4. Subtract the moving average, from (n / 2 + 1) days ago, from the
closing price:
DPO = Close - Simple moving average [from (n / 2 + 1) days ago]
Worden Support wrote: It's just the current Price minus the Simple Moving Average of Price using the Period of the DPO for the Moving Average Period offset (Period / 2) + 1 Bars to the left (meaning the Moving Average uses future data in its calculations which is why it ends before the right-edge of the Chart).
The explanation in parenthesis is incorrect. If we are using the current price minus the moving average of X bars ago, there is no future data involved and there is no reason for it to end X number of bars before the right edge.
However, even using the definition as given, Stockfinder does not come up with the answer shown in your formula.
Let's look at a specific example. Assume we want a 10 day DPO on COMPQX.
This according to the formula shown above would be:
Price at the close on 10/2/09 minus the 5 day simple moving average of price offset 6 days to the left.
The values are 2048.11 - 2131.246 or negative 83.136. Stock finder shows the last DPO as of 6 days ago of negative 2.096924.
This is a flaw in the information that is offered in your program.
Instead of referring me to your trainers, why not have your programmers fix the problems. We, who use the program, depend on the program for correct information. The messrs Worden pride themselves on the quality of their programs.
I am not interested only in a workaround for myself, but in having the problem corrected.
What is the next step in addressing this so that the problem is corrected in Stockfinder, not just on my desk.
Regards,
Dan
-----Original Message-----
From: Worden Support [mailto:Support2@Worden.com]
Sent: Thursday, October 01, 2009 1:44 PM
To: delta1@cfl.rr.com
Cc: Worden Support
Subject: Worden Support
Mr. Chiswick,
We inquired about our DPO calculation with our Trainers. They have advised that they can tell you how DPO is calculated in StockFinder. It's just the current Price minus the Simple Moving Average of Price using the Period of the DPO for the Moving Average Period offset (Period / 2) + 1 Bars to the left (meaning the Moving Average uses future data in its calculations which is why it ends before the right-edge of the Chart). Odd Periods are rounded down for purposes of determining the offset.
They're not yet sure how StockFinder is performing that calculation.
They
are still awaiting that information.
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
It is sad that support does not know that the information is available:
You can add the indicator to your chart and edit the realcode. I don't have the time to figure out the problem but here is the code as of 10/3/09:
'# Period = UserInput.Integer = 14
Static AvgC As Single
Static Offset(1) As Integer
Static Start(2) As Integer
If isFirstBar Then
AvgC = 0
Offset(0) = (-(Period / 2 + 1))
Start(0) = System.Math.Max(Offset(0), 0)
Offset(1) = Offset(0) + Period
Start(1) = System.Math.Max(Offset(1), Period)
Start(2) = Start(0) + Start(1) - 1
End If
If CurrentIndex >= Start(0) Then AvgC += Price.Last(Offset(0)) / Period
If CurrentIndex >= Start(1) Then AvgC -= Price.Last(Offset(1)) / Period
If CurrentIndex >= Start(2) Then
Plot = Price.Last - AvgC
Else
Plot = Single.NaN
End If
|
|
Registered User Joined: 12/5/2004 Posts: 10
|
to jas0501
Thank you for the code. That takes care of the immediate problem for me, but does nothing to iresolve the issue with Stockfinder.
Stockfinder should correct the code so that when anyone uses DPO it returns the correct values.
If a problem is known to exist and it is not repaired how can any indicator be trusted. If someone now tries to use the DPO, they will receive wrong information. If they trade based on this wrong information they may make wrong decisions. If a back test is run using the DPO as one of the parameters, the results will be erroneous.
It is difficult enouh to find that a problem exists. But to find a problem and bring it tio the attention of Stockfinderand not have the problem corrected is not good.
Dan
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
I'm in complete aggreement. Bad results shuld be the highest priorty bugs
It is as bad as bad price history, However that does not seem to be the perspective maintained by Worden. For example the Ann Retern/Trade fron the backscanner has need grossly wrong for more than a year! It typically overstates the annual return of a scan by a factor of 3! This is a critical bug and a very simple fix.
As to Wordens implementation, they misinterpreted the shift of the MA in the wrong direction. One can do the DPO by plotting the MA and then offsetting it and then dragging and dropping Price to the MA and produce a Compare:Difference.
So for a cycle of 20:
MA10
barsago = 6
to duplicate wordens DPO just offset MA10 by -6, which shifts the plot to the left, using futue values, which is wrong.. Then do the Compare:Difference and is matches the Worden's DPO. They shifted incorrectly.
To get the correct DPO the offset would need to be +6, using the MA10 from 6 bars ago.
=======================
I think you misinterpreted the rules a bit as well. Your example had an MA5 and bars ago of 6. I think that is wrong. Worden's DPO userinput is the MA period, or 1/2 the cycle. The barsAgo should never be greater than the MA period.
cycle=C
MA=C/2
barsago = MA/2+1
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
There is in fact considerable disagreement as to the definition and calculation of the Detrended Price Oscillator. The definition you have given is just one of numerous possibilities, so your assumption that it is the one true way is factually incorrect. MarketScreen calculates DPO using past data as you described:
C - AVGCP.(P/2+1)
Most sources do shift the Moving Average to the left (requiring future data) instead of shifting the Moving Average to the right and using past data in the calculations however. Technical Analysis from A to Z for example is quite specific that future data should be used (this definitely seems to be the most common method):
To calculate the DPO, first create an n-period simple moving average (where “n” is the number of periods in the DPO). Next, subtract the moving average “(n/2) + 1” days (in the future) from the closing price. This has the effect of shifting the DPO back “(n/2) + 1” periods. The shift is done to eliminate the trend in prices. The last “(n/2) + 1” periods of the DPO will have no value.
Close – (Simple Moving Average "((n / 2) + 1)" days in the FUTURE)
Or:
C - AVGCP.(-(P/2+1))
When DPO was first added to Blocks, we used the following (see DPO in Blocks for some advantages when compared to the most common version):
C - AVGCP.(-(P/2-2))
But switched to the most common version that uses future data in an effort to be consistent with most other sources. It should probably be noted that Paritech has yet another DPO calculation using future data (and bustermu goes into a fairly understandable basic description of why this might be preferable to the other three in New Search):
C - AVGCP.(-(P-1)/2)
One nice thing about the RealCode used in the StockFinder version is that is rather easily adjusted to use whichever method you want. Just change the following line:
Offset(0) = (-(Period / 2 + 1))
To the following for the MarketScreen version:
Offset(0) = (Period / 2 + 1)
To the following for the original Blocks version:
Offset(0) = (-(Period / 2 - 2))
Or to the following for the Paritech version:
Offset(0) = (-(Period - 1) / 2)
In this RealCode, if the Offset results in a fractional result, the rounding used to create an integer offset is done automatically by Visual Basic. If you wish to force the rounding in one direction or the other, you could use the System.Math.Ceiling() or System.Math.Floor() functions.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/31/2005 Posts: 2,499
|
Bruce,
Thanks for the explanation. In thinking about it, if one is attempting to detrend on a 20 days cycle, 10 day MA, bar offset of 6, moving forward or backward should make little difference. However if one is attempting to produce actionalble information then using the MA 6 bars ago permits this. It also permits backtesting the concept.
In addition using future information, the 6 bars in the future presents an opportunity for "future information leak" when backtesting as DPO as currently implemented,
I would vote for the x bars ago to avoid accidental faulty conclusions derived from backtests using future information. I think it might be prudent in the indicator's info panel to clearly point out when future information is used in an indicator.
I'd be curious to know if there are any other indicators that use future information.
Regards,
jas0501
|
|
Registered User Joined: 12/5/2004 Posts: 10
|
Hi Bruce,
Thank you for your thoughtful reply, however there are some things that appear to have changed . You made reference to Technical Analysis from A to Z by Steven Achelis.
Here is what is written in the online version of Technical Analysis from A to Z published by Equis in 2003.
Calculation
To calculate the Detrended Price Oscillator, first create an n-period simple moving average (where "n" is the number of periods in the moving average).
Now, subtract the moving average "(n / 2) + 1" days ago, from the closing price. The result is the DPO.
DPO = Close – (Moving Average”((n/2) + 1)” days ago
Please note that he refers to days ago, not the future.
One of the messages you referred me to mentioned Wikipedia. Here is the article from Wikipedia.
The detrended price oscillator (DPO) is an indicator in technical analysis that attempts to eliminate the long-term trends in prices. Leaving short-term trends, the indicator allows immediate overbought and oversold levels to be found more effectively.
The DPO is calculated by subtracting the simple moving average over an N day period and shifted N/2+1 days back from the price.
To calculate the Detrended Price Oscillator:
Decide on the time frame that you wish to analyze. Set n as half of that cycle period.
Calculate a simple moving average for n periods.
Calculate (n / 2 + 1)
Subtract the moving average, from (n / 2 + 1) days ago, from the closing price:
DPO = Close - Simple moving average [from (n / 2 + 1) days ago]
Rather than go on listing sources that refer to using the MA of n days ago, suffice it to say that the way Stockfinder uses the DPO does not allow its value to be referenced as of the day you wish to trade. Nor does it lend itself to easy backtesting.
FreeStockCharts, another Worden program uses the detrended price oscillator differently from StockFinder and allows for current information to be displayed.
I realize that StockFinder is an enormously flexible program that allows for the creation of indicators to perform in any way desired. What I am asking for is a default set up for DPO that allows the indicator to be used in back testing and in current selection of stocks. Using the present arrangement if I set the DPO to 50 periods and used daily bars, the most recent information would be 26 trading days ago, more than one month. Of what benefit can that be?
If it is not within your purview to make this change to the program, please let me know who to contact. Thank you again for your help.
Dan
|
|
Registered User Joined: 12/5/2004 Posts: 10
|
Hi Bruce,
As an example, think of a stock that has always traded at the same price. For the last 20 trading seesions the price has always closed at $50.
Today, the price closes at $75. Using the DPO calculation with a 14 day period and the formula
DPO = Close - Simple moving average [from (n / 2 + 1) days ago]
the value of the DPO would be zero for all days previous to today, which of course is correct since there was no cycle, and would have a value of 25 today, indicating a cycle change.
Using the forward looking formula others have suggested, as I understand it, the result would be shifted back 4 days giving a DPO of 25 four days ago, obviously a method to look into the future.
Dan
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
dan2fl,
The DPOs used in both StockFinder and FreeStockCharts are being looked at by the people that actually make the decisions about the Indicators provided.
The version you have proposed as "standard" has two primary advantages (and they are fairly significant advantages in my mind). It doesn't use future data and can be Plotted all the way up to the right edge of the chart (these could be considered the same advantage). It has one big disadvantage considering the name. It doesn't actually detrend price (and seems to shift the Moving Average in the opposite direction of what would be required to do so).
A Simple Moving Average has lag. This lag is the reason the shift-left crowd thinks the proper way to Plot a Moving Average is to Plot it in the exact center of the data used in its calculation: (Period - 1) / 2 Bars Ago. If you exclude the Bar at which it is Plotted for odd periods, exactly half of the data used to calculate the Moving Average appears before the Moving Average while the other half appears after the Moving Average.
Now let's think about a Price that is trending up at a steady pace. If Price is exactly tracking the trend, the detrended price should be zero (because it isn't deviating from the trend). Let's say Price is currently at $10 and has been increasing by exactly a penny each Bar during the recent past. If we take a 15-Bar Simple Moving Average of Price (I'm using an odd number for the Period because it will actually line up with the Price Bars when offset (-(Period - 1) / 2) bars):
(9.86 + 9.87 + 9.88 + 9.89 + 9.90 + 9.91 + 9.92 + 9.93 + 9.94 + 9.95 + 9.96 + 9.97 + 9.98 + 9.99 + 10.00) / 15 = 9.93
Price is properly detrended using this Moving Average when Price is 9.93 (remember the result should be zero because Price is following the trend exactly). So if you are using a 15-Bar Simple Moving Average to detrend Price, that Moving Average needs to be from 7-Bars in the future.
Let's think about what happens when we Offset the Moving Average by (Period / 2 + 1) instead of (-(Period - 1) / 2). This time we'll use a 14-Bar Simple Moving Average (the order of operations changes when the offset Moving Average lines up with prices). So the 14-Bar Simple Moving Average of 8-Bars Ago would be:
(9.79 + 9.80 + 9.81 + 9.82 + 9.83 + 9.84 + 9.85 + 9.86 + 9.87 + 9.88 + 9.89 + 9.90 + 9.91 + 9.92) / 14 = 9.855
Now 10 - 9.855 = .145, which definitely isn't zero (like it should be if we were actually detrended this Price which is following the trend exactly).
The problem is that the DPO indicator uses a Simple Moving Average to detrend Price (which is something all the definitions seem to agree upon) and that an SMA has lag. If one of the zero lag alternatives had been chosen instead (like a DEMA or a LR), this might not be an issue at all. You could just subtract the current DEMA or LR from Price without an Offset (I haven't thought stringently about using DEMA or LR, there may be issues that aren't obvious with them as well).
Now a Detrended Price Oscillator doesn't necessarily need to detrend to be correct. Wilder's Relative Strength Index isn't an Index and it doesn't have anything to do with Relative Strength. But there are multiple published versions of DPO (and I haven't been able to figure out which, if any, are the "original" source). Either there are multiple original sources with different ideas of what a DPO should be or DPO was interpreted incorrectly when it was implemented by numerous people over time (or some combination of the two). Barring evidence over which is actually the "correct" original, it would seem that a version that actually does what the name suggests has at least one big advantage over one that doesn't.
One option to get versions that uses future Moving Averages in their calculations to Plot all the way to the right (and not use future data) is to shift the Price instead of the Moving Average. This does introduce a disadvantage however. The Detrended "Price" won't line up with the actual Price.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Administration
Joined: 9/30/2004 Posts: 9,187
|
Attached is a modified version of DPO which uses what has become a widely accepted interpretation of the indicator. We don't know for sure which is correct so we'll offer both in StockFinder. You can open the attachment directly into a running copy of StockFinder and save it for future use until we get it added to the indicator library. Attachments: Detrended Price Oscillator Modified.sfInd - 6 KB, downloaded 1,008 time(s).
|
|
Registered User Joined: 12/5/2004 Posts: 10
|
To Bruce and Administration,
Thank you for resolving this issue.
This issue is similar to the one that comes up from time to time regarding moving averages, where an argunment is made to offset the moving average by one half the number of days in the average.
For convenience the default in the MA case is to plot the MA value on the last price bar in the series, as you are now making available for the DPO.
The earliest reference I could find to offsetting the moving average was ihn the JR Hurst Book, The Profit Magic of Stock Transaction Timing published in 1970. Although he does not refer to the DPO by name in that book, he does point out how that information can be of help in identifying cycles.
Dan
|
|
Registered User Joined: 10/7/2004 Posts: 16
|
Having read through this thread, I still have the outstanding question of what formula is used for the DPO as found in v 12.3? Specifically, for the default DPO21?
I ask for the formula and DPO21 example simply because it is not legal to use DPO21 in a pcf, as for example TSV21 can be used without error.
Thank you.
Redeyez
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
An Indicator Formula for a 21-Period DPO in TC2000 version 12.3 would be:
C - AVGC21.12
This formula is based on the following:
C - AVGCP.(P/2+1)
PCF Formula Descriptions
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 10/7/2004 Posts: 16
|
Many thanks, Bruce. :)
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |