# all files / technicalindicators/lib/volume/ ADL.js

97.3% Statements 36/37
81.82% Branches 9/11
100% Functions 5/5
97.3% Lines 36/37

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68

    1×

    1×

    4×
    4×
    4×
    4×

    4×

    4×

    4×
    4×
    4×
    4×
    4×

    120×
    120×
    120×
    120×

    4×

    4×
    90×

    90×
    90×
    90×

    1×
    2×
    1×
    1×
    1×
    1×

    2×
    2×
    2×

    1×
    1×

    1×
    30×

     /**
     * Created by AAravindan on 5/17/16.
     */
    "use strict"
    let ADL;

    module.exports = ADL = function(input) {

      var highs       = input.high;
      var lows        = input.low;
      var closes      = input.close;
      var volumes     = input.volume;

      if(I!((lows.length === highs.length) && (highs.length === closes.length) && (highs.length === volumes.length) )){
        throw ('Inputs(low,high, close, volumes) not of equal size');
      }

      this.result = [];

      this.generator = (function* (){
        var result = 0;
        var tick;
        tick = yield;
        while (true)
        {
          let moneyFlowMultiplier = ((tick.close  -  tick.low) - (tick.high - tick.close)) /(tick.high - tick.low);
          let moneyFlowVolume = moneyFlowMultiplier * tick.volume;
          result = result + moneyFlowVolume
          tick = yield Math.round(result);
        }
      })();

      this.generator.next();

      highs.forEach((tickHigh, index) => {
        var tickInput = {
          high    : tickHigh,
          low     : lows[index],
          close   : closes[index],
          volume  : volumes[index]
        }
        var result = this.generator.next(tickInput);
        if(Eresult.value){
          this.result.push(result.value);
        }
      });
    };

    ADL.calculate = function(input) {
      if(input.reversedInput) {
        input.high.reverse();
        input.low.reverse();
        input.close.reverse();
        input.volume.reverse();
      }
      let result = (new ADL(input)).result;
      input.reversedInput ? result.reverse():undefined;
      return result;
    };

    ADL.prototype.getResult = function () {
      return this.result;
    };

    ADL.prototype.nextValue = function (price) {
      return this.generator.next(price).value;
    };