[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

DUNNS DENSITY CODE FIXES



PureBytes Links

Trading Reference Links

Dans un courrier daté du 06/10/98 17:01:53  , Dale Legan écrit :

<< 
 This improvement allows you to specify any length as well as determine what
price to use.  Use as a indicator or user function;
 
 Input: Length(10),Price(c);
 vars: counter(0);
 value11=0;
 value3=length-1;  < ====== Mistake. One may read "length".
 counter=0;
 while counter<value3 begin
 	value1=price[counter]-price[counter+1];
 	if value1>0 then value11=value11+1;
 	if value1<0 then value11=value11-1;
 	counter=counter+1;
 end;
 plot1(value11,"Density");
  >>

I verified that my version matched the original  Dunn's code.
Yours do not because one iteration was missing.
You exit the loop at iteration 8 and not 9 as expected, because counter is set
to 9  at the end of iteration 8.

Also , the reason what I did not code the difference like you did (inside a
loop), but outside was to spare  "length" iterations of the difference.
Because the price difference is computed and stored in the maxbars back
sliding window, there is no reason to calculate it for each previous bar
inside the loop.
Accessing the previous value with the diff[k] syntax is  clever.

My previous solution was:

input: price(c), len(10);

vars: k(0),diff(0),tmp(0),tmp2(0);
diff=price-price[1];
tmp2=0;
for k=0 to len-1 begin
	tmp=0;	
	if diff[k]<>0 then tmp=iff(diff[k]>0,1,-1);
	tmp2=tmp2+tmp;
end;

plot1(tmp2,"densityC");
plot2(tmp2, "mid");

Now, and for ending this is the shortest and fastest solution available
=================================================

input: price(c), len(10);
vars: k(0),diff(0),tmp(0);

diff=sign(price-price[1]);

tmp=0;	
for k=0 to len-1 begin
	tmp=tmp+diff[k];
end;
plot1(tmp,"densityC");

=================================================


Enjoy!

Sincerely,

Pierre Orphelin
Still TS Express Technical Editor...
www.sirtrade.com