This is a trading object shared by a member. You can use this object as well as hundreds of others with QuantShare - Trading Software.
Click on the Like button or on one of the share buttons to share this object and spread the word about QuantShare.
QuantShare is an advanced trading software for stock, forex, futures, ETF and options markets. It is the best and the most complete EOD trading software software and it is FREE (beta version).
The Detrended Price Oscillator is an indicator used as a long or short signal. In fact, the DPO eliminates cycles that are longer than the moving average period. It leaves thus short-term trends, and it allows both overbought and oversold levels to be detected more accurately. These levels are used with DPO to generate signals; when DPO goes below the upper (overbought) one, which means that the bulls are tired and that the bears are going to dominate the market, you should go short. When the DPO goes up the lower (oversold) line, that means the opposite situation, and you ought then to go long because the market is going to become bullish.
DPO formula is quite simple and its coding does not require from you more than one or two lines. You have first to specify an N-bar period; you calculate the simple moving average of the close price over that period, and then you shift the result N/2 + 1 bars back. You finally subtract the result from the daily close price.
The function I have written takes as argument a time frame (the SMA period multiplied by 2) and returns as result the DPO indicator time-series for that time frame. Therefore, if your time frame is of 40 days, the function calculates the SMA over 20 days and shifts it 11 days back.
Generally, a 20 bars time frame or window value is used.