for(int i=2; i<limit; i++)
is there a reason that you changed from
for(int i=0; i<limit; i++)
in the original code?
is there a reason that you changed from
in the original code?
That's me bad. I was trying to work out why so I thought that since I'm introducing i+1 into the equation I needed to start back a couple. How wrong I am. It should be the same. I just forgot to change it back.
So here's the problem pictorially. Blue channel is the original DC code. Green channel is the modified DC code.
As you can see when first applied, historically the two codes plot the same output. Its only once applied the new code starts to work and we see the difference in output.
Since DC is trend following the modified code needs to replicate the original code and it does so nicely. Although later on the initial break it still captures the trend but also eliminates a couple of false long breaks a DC trader would of traded against the original code.
However Ranging markets are a DC traders worst nightmare constantly being whipped into losing trades.
As you can see here. The new logic detects a ranging markets and eliminates all losing trades. In this shot 15 trades over an 8 day period would of been taken, 2 winners 13 losers. That hurts a DC traders bank account. But with the modified code, the only two trades that would of been taken correspond to the two winning trades. Now that works for me. So that's why I want to make sure the code logic is correct and share this little finding
for(int i=0; i<limit; i++) { if((iHigh(Symbol(),0,i) > upper[i+1]) || (iLow(Symbol(),0,i) < lower[i+1])) {
This if condition will be true for every historical bar when the indicator is initialised.
This is because you count up, so initially buffer[i+1] will always be EMPTY_VALUE
for(int i=limit-1; i>=0; i--) {
Count down instead

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Ok so I only just passed coding 101. But its enough for me to do the basics. So I modified a donchian channel indicator so it only adjust levels when a new high or low is made. But it only works once applied to a chart.
Could someone have a quick look at it and tell me where I went wrong. Thanks in anticipation of help.
Original DC code
Bobs Modified DC