In view of the series by Michael Stokes on the DVI indicator developed by David Varadi I have translated the code into an Amibroker indicator.

Have fun with it!

// ---- Functions Used by the indicator ---
function PercentRank( Data, Periods )
{ Count = 0;
for ( i = 1; i < Periods + 1 ; i++ )
{
Count = Count + IIf ( Ref( Data, 0 ) > Ref( Data, -i ), 1, 0 );
}
return 100 * Count / Periods;
}
function DVI(Length)
{ // default Length=250, the variables used in the function refer to the columns in the excel sheet
xF=IIf(C>**ref(C,-1)**,1,-1); xG=(Sum(xF,10)+Sum(xF,100)/10)/2;xH=MA(xG,2);
Stretch=PercentRank(xH,Length);
xC=(C/MA(C,3))-1;xD=(MA(xC,5)+MA(xC,100)/10)/2;xE=MA(xD,5);
Magnitude=PercentRank(xE,Length);
xDvi=0.8*Magnitude+0.2*Stretch;
return xDVI;
}
// --- Indicator Calculation & Plotting ---
Length=Param("Length",250,1,300,1);
xDVI=DVI(Length);
Plot(xDVI,"DVI("+NumToStr(Length,1.0)+")",colorBlue);

*Related*

Wow ..

i was wondering about all these DVI formula , looks interestinmg

Thank you very much for all your efforts.

looking for more.

Nice work. Thanks!

hi,

i just wanted to make sure i am reading the DVI AB code right. Something didnt quite seem kosher, so i wanted to check:

This is the stretch calculation you gave. Notice that you have averaged the short term sum and long term sum : i.,e sum(xf,10) and sum(xf,100)/10. The 100 term sum is divided by 10, no doubt to normalize it and bring it comparable to the 10-day sum. Makes perfect sense so far.

xF=IIf(C>O,1,-1); xG=(Sum(xF,10)+Sum(xF,100)/10)/2;xH=MA(xG,2);

Now look at the magnitude calculation:

xC=(C/MA(C,3))-1;xD=(MA(xC,5)+MA(xC,100)/10)/2;xE=MA(xD,5);

here you still have the 100 day AVERAGE divided by 10. Why is this needed ? since the terms are both MAs in the first place, you do not have to normalize the MA(xC,100) by further dividing by 10. My opinion only. could be wrong. But either i missed something, or it is a mistake.

hi bgl,

I noticed this as well when I was creating the DVI indicator in AB from the excel code that was provided at MarketSci. In fact I you look up the post, you will find a question from me about the calculation. David (the inventor of the DVI) confirmed that this was the correct calcuation.

As a further illustration, I have tested the alternative and found a weaker performance compared to the original with the “odd” /10 calculation.

Regards, QD

With respect to: xC=(C/MA(C,3))-1;xD=(MA(xC,5)+MA(xC,100)/10)/2;xE=MA(xD,5);

David is not normalizing, but weighing.

Essentially he creates: xD=function1(xC); xE=function2(xC)with fixed weighing factors;

If so desired in AB you can easily play with variable weighing factors, by replacing constants with parameters:

xC=(C/MA(C,par1))-1;xD=(MA(xC,par2)+MA(xC,par3)/par4)/2;xE=MA(xD,par5);

par1=param(“xC MA Period”,3,2,10,1); par2=param(“xD MA Period”,5,2,10,1)and so on.

thanks QD,

for the clarification.

The underweight / overweight seems more of a result of an optimization, but the concept is nice.

Have you ever used only the stretch and the magnitude separately ?

i used to use a calculation similar to the stetch in the past, and it worked ok, not great, but ok.

best,

bgpl

Hi bgpl, no problem.

I have done some experimenting with the stretch & magnitude settings, but in my experiments they seem not to make a big difference. So I kept them to the original.

QD.

Hi QD,

Thanks for the post. But I notice the xF=IIf(C>O,1,-1) is check C vs O, not C vs ref(C, -1) which is in David’s original Excel? Twisted on purpose?

JC

Hi JC, thank you for your reply. You are correct, I checked the original spreadsheet and I made a code error!

I will correct the posts for the error.

Thanks again for your reply.

QD

>>Thanks for the post. But I notice the xF=IIf(C>O,1,-1) is check C vs O, not C vs ref(C, -1) which is in

>>David’s original Excel? Twisted on purpose?

I am confused – according to various implementations out there i.e. including MarketSci and others (see below) – the comparison is with the previous close. Here it seems you are comparing to the Open.

http://www.marketsci.com/supporting.docs/dvi_calculation.xls

http://dvindicators.cssanalytics.com/community/?vasthtmlaction=viewtopic&t=47.0

Is there any confirmation on what the comparison should be –

a) C>O

or

b) C > C[1]

Hi AT, this is a small mod. You can experiment with both options and see what has your preference. QD