DVI Indicator for Amibroker

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);
     return xDVI;
// --- Indicator Calculation & Plotting ---

11 thoughts on “DVI Indicator for Amibroker

  1. Wow ..
    i was wondering about all these DVI formula , looks interestinmg
    Thank you very much for all your efforts.
    looking for more.

  2. 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:


    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:
        par1=param(“xC MA Period”,3,2,10,1); par2=param(“xD MA Period”,5,2,10,1)and so on.

  3. 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.


    • 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.

  4. 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?


Leave a Comment