Moren Information about:
Link: 1) www.forexdeluxe.com/technical-indicators/mass-index-mi.htm
Link: 2) www.etrading.sk/en/technical-analysis/44-indikatory-technickej-analyzy/110-mass-index



Calculation:

1. Calculate the exponential moving average of 9 days difference between the highest and lowest prices.

2. Calculate the exponential moving average 9 days from the results of step 1.

3. The result of step 1 divided by the result of step 2.

4. Total the results of step 3 for 25 periods (eg 25 days).


Source Code "Mass Index":

function init()
{
   with (MI) {
     label = "MI";
     createBuffer("MI");
     setBufferColor("MI", "lime");
     setBufferDrawStyle("MI", DrawStyle.LINE);
     setAutoChangeMaxMin("MI");
     addLevel(27, "red");
     addLevel(26.5, "red");
   }
}

function start()
{
   var Period = 9;
   var num = Shared.numberOfQuotes();
   var MIbuf = new Array(num);
   var MIdelta = new Array(num);

   for (var j = 0; j < num; ++j) {
     MIdelta[j] = Shared.high(j) - Shared.low(j);
   }

   var bufMIema = Shared.ema(Period, MIdelta);
   var bufDoppelMiema = Shared.ema(Period, bufMIema);

   for (var j = 0; j < num; ++j) {
     MIbuf[j] = bufMIema[j]/bufDoppelMiema[j];
   }

   MI.setBufferData("MI", summa( MIbuf, 25));
}

function summa(buf, periodsumma)
{
   result = new Array(buf.length);

// 1
     result[0] = buf[0];
     for (var i = 1; i < periodsumma; ++i)
   {
     result[i] = result[i-1] + buf[i];
   }

// 2
   for (var i = periodsumma; i < buf.length; ++i)
   {
     result[i] = result[i-1] + buf[i] - buf[i-periodsumma];
   }
return result;
}