Following my post on the DVI system, a reader asked me to post the DV2 indicator code for Amibroker. As the code is available over at MarketSci in MS Excel sheet, I felt I can share my Amibroker translation.

So here it is (the bounded version):

function DV2(Length)
{
d1= ( C / ((H+L)/2) ) - 1;
dv=Sum(d1,2)/2;
xDV2=percentrank(dv,Length);
return xDV2;
}

Have fun with it!

QD

*Related*

Hi,

Thanks for sharing! I enjoy your blog.

The DV2 function can be even simpler:

function DV2(Length) {

return PercentRank(MA(C/Avg,2),Length);

}

I get identical results with both.

Mark

Hi Mark, thanks for giving back! I will update my code as well.

Have a nice weekend, Michel

I have quickly whipped up EasyLanguage (TradeStation/MultiCharts) code for DV2. Let me know if there are any errors. Also wondering what default value do you guys use for ‘Length’. Appreciate your feedback.

inputs:

Length(0) ;

variables: var1(0), var2(0), var3(0), var4(0);

var1 = Close / ((High + Low) / 2);

var2 = Close[1] / ((High[1] + Low[1]) / 2);

var3 = (var1 + var2) / 2;

var4 = _PercentRankFast(var3, var3, Length);

plot1(var4, “DV2 bounded”);

Where _PercentRankFast = the following function below:

inputs:

ValueToRank(numericsimple),

DataSet(numericseries),

Length(numericsimple);

variables:

R(0),

X(0);

R = 0;

for X = 1 to Length begin

if DataSet[X-1] <= ValueToRank then

R = R + 1;

end;

_PercentRankFast = R / ( Length – 1 ) ;

Duh! Just answered my own question. The Length = 252.

But please do let me know if there are any errors in my code. Thx u.

As per the post showing how the DV(2) is calculated at http://marketsci.wordpress.com/2009/07/15/varadi%E2%80%99s-rsi2-alternative-the-dv2/ the bounded and unbounded DVs are separate entities so need to be calculated using different formulae,

Here’s the Amibroker code for unbounded:

function DVu(period){ // Unbounded

return MA(((C / Avg) – 1) * 100, period); // default period is 2

}

…and bounded

function DVb(period){ // Bounded

return PercentRank(((C / Avg) – 1), period); // default period is 252

}

DVI and DV2 are the same?if not then please give full amibroker code for DV2.It does not plot the DV2.