What is wrong in this code ?
I have an indicator that crosses an average of the indicator as a buy/sell signal , in this case going short.
The closing of this position is done by the reverse cross. (see picture test)
However the execution in backtest shows that the position is covered randomness without taking in account the “closing condition” ; worse it opens a new short without satisfying the “condition”…
Where is the problem in this code?
Any suggestion is welcome.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Conditions to enter long positions
indicator1 = DPO[8](close)
indicator2 = Average[5](DPO[8](close))
c1 = (indicator1 CROSSES OVER indicator2)
//IF c1 AND not daysForbiddenEntry THEN
//BUY 1 SHARES AT MARKET
//ENDIF
// Conditions to enter short positions
indicator3 = DPO[8](close)
indicator4 = Average[5](DPO[8](close))
c2 = (indicator3[1] CROSSES UNDER indicator4[1])
//c3 = (indicator3[1] CROSSES OVER indicator4[1])
IF c2 AND not daysForbiddenEntry THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
IF c1 THEN
EXITSHORT AT MARKET
ENDIF
Were the settings the same in the strategy and on the chart?
Which instruments?
Which TF?
Which date/time is the trade under investigation?
and keep in mind that DPO is not suitable for automatic trading, as the internal instruction make use of future datas, which is obviously not possible in real time.
Nicolas,
According to the definition the Detrended Price Oscillator (DPO) measures the difference between a past price and a moving average. The detrended price oscillator is calculated and utilized from the variables shown below:
X is first determined by the number of periods; 20 day or 30 day periods are common. Simple moving average over an “n” day period is needed.
DPO = Closing price – Simple moving average [from (n / 2 + 1) days ago]. It is possible to displace the Detrended Price Oscillator (DPO) with a horizontal shift to the right. (see picture of the setting Prorealtime in attachment.)
So I do not understand what you mean by : ” the internal instruction make use of future datas” . Can you clarify ? Thank you for your efforts.
Brgds
J-P
Robberto
The answers on your questions:
Were the settings the same in the strategy and on the chart? YES
Which instruments? DAX Futures
Which TF? Day
Which date/time is the trade under investigation? from 28 november 2015 till 20 september 2018
Thank you for your reply.
Brgds
J-P
So I do not understand what you mean by : ” the internal instruction make use of future datas” . Can you clarify ?
If you try to run a strategy live with DPO then you will get a message telling you that it is not an indicator that can be used for live trading. This is the same for all similar indicators that re-paint in the future such as the zig-zag They look great because they change in the future. For this reason it is not worth continuing to develop strategies based on these type of indicators.
@didi059
You are right, but if you look carefully at the oscillator by reloading the chart, let’s say each 10 minutes, you’ll see different information, because that’s how the DPO is made in the platform. You have the choice to choose between the future and past datas in its settings.
There are plenty of topics in the forums which deal about the DPO and its repainting behavior. You can also have a look at this one where you’ll find the code for the DPO that use the past data: (but indeed not as accurate than the one which has the crystal ball!! 😆 ) https://www.prorealcode.com/topic/detrended-price-oscillator-dpo/#post-13747