Calculation:

The value of the DeMarker for the "i" interval is calculated as follows:

- The DeMax(i) is calculated:
If high(i) > high(i-1) , then DeMax(i) = high(i)-high(i-1), otherwise DeMax(i) = 0

- The DeMin(i) is calculated:
If low(i) < low(i-1), then DeMin(i) = low(i-1)-low(i), otherwise DeMin(i) = 0

- The value of the DeMarker is calculated as:
DMark(i) = SMA(DeMax, N)/(SMA(DeMax, N)+SMA(DeMin, N))

Where:

SMA - Simple Moving Average;
N - the number of periods used in the calculation.


Source Code "DeMarker":

function init()
{
   DeMarker.createParameter("Period", 14);
   DeMarker.createParameter("LevelUp", 0.7);
   DeMarker.createParameter("LevelDown", 0.3);

   DeMarker.createBuffer("DeMarker");
   DeMarker.setBufferColor("DeMarker", 'lime');
   DeMarker.setBufferDrawStyle("DeMarker", DrawStyle.LINE);

   DeMarker.max = 1;
   DeMarker.min = 0;
}

function start()
{
   var period = DeMarker.parameter("Period");

   DeMarker.label = "DeMarker(" + period + ")";

   DeMarker.removeAllLevels();
   DeMarker.addLevel(DeMarker.parameter("LevelDown"), "red");
   DeMarker.addLevel(DeMarker.parameter("LevelUp"), "red");
   DeMarker.addLevel(0, "yellow");

   var num = Shared.numberOfQuotes();
   var bufDeMax = new Array(num);
   var bufDeMin = new Array(num);

   bufDeMax[0] = 0;
   bufDeMin[0] = 0;
   for (var i = 1; i < num; ++i) {
     if (Shared.high(i) > Shared.high(i - 1)) {
       bufDeMax[i] = Shared.high(i) - Shared.high(i - 1);
     }
     else {
     bufDeMax[i] = 0;
     }

     if (Shared.low(i) < Shared.low(i - 1)) {
     bufDeMin[i] = Shared.low(i - 1) - Shared.low(i);
     }
     else {
      bufDeMin[i] = 0;
     }
   }

   var bufSmaDeMax = Shared.sma(period, bufDeMax);
   var bufSmaDeMin = Shared.sma(period, bufDeMin);
   var bufDeMarker = new Array(num);
   for (var i = 0; i < num; ++i) {
     var fValue = bufSmaDeMax[i] / (bufSmaDeMax[i] + bufSmaDeMin[i]);
     bufDeMarker[i] = fValue;
   }
   DeMarker.setBufferData("DeMarker", bufDeMarker);
}