Creating an Accumulation Distribution Indicator

export class Main extends Indicator {
// create and export a class named Main - a child class (inheriting from the property) of the Indicator predefined class, which in turn is a child of the mScript predefined class.

// constructor creates and initializes the objects necessary for the indicator to work
constructor () {

// "In the constructor, the super keyword is used as a function that calls the parent constructor. It must be called before the first call to the this keyword in the body of the constructor."
super ();

        // Set indicator properties[// mtrader7.com/docs/Terminal/mScript/JavaScript/v1/mScript/setProperty]
		this.setProperty(Property.SeparateWindow, true); // Is the indicator data displayed in a separate window? true = yes;		  				
        
		this.setProperty (Property.ShortName, "A / D"); // Indicator display name = A / D
        // Add to the indicator initialization dialog a request for the type of used price (PriceType) - Bid or Ask
		// mtrader7.com/docs/Terminal/mScript/JavaScript/v1/mScript/addInput
        this.addInput("Тип цены", InputType.PriceType, PriceType.Bid); 
		

this.buffers = {
		    // create the necessary buffers for work mtrader7.com/docs/Terminal/mScript/JavaScript/v1/mScript/addBuffer
            ExtMapBuffer1 : this.addBuffer(), // ;the buffer in this indicator is one
        };
    } // end of constructor method


onInit () {// Initialization of the indicator, executed immediately after loading by the client terminal
this.buffers.ExtMapBuffer1 // initialization of the indicator value buffer
.setShape (Shape.Line) // set the type of chart - line
.setColor (Color.LightSeaGreen) // default line color; in the dialog box, you can select another

        ;
} // end of the onInit function


async onUpdate () {// onUpdate is a standard function that is executed every time a new tick is received by the symbol for which the indicator is calculated

const {PriceType} = this.getInputs (), // get the previously requested price type and save it as a PriceType constant
{ExtMapBuffer1} = this.buffers, // get accumulated buffer data

// request from the terminal data High, Low, Close, Volume for all bars and wait for the filling of the corresponding arrays
// mtrader7.com/ru/docs/Terminal/mScript/JavaScript/v1/Bar/load
            {
                High,
                Low,
                Close,
                Volume
            } = await Bar.load ([// await is a program execution is suspended until all data is received
Bar.Mode.High,
Bar.Mode.Low,
Bar.Mode.Close,
Bar.Mode.Volume,
], PriceType), // for the corresponding price type

barSize = Close.length; // barSize = the number of elements in the array Close

// let is a declaration of variables valid only within the given program block
let i, h, l, c,
countedBars = Bar.counted (); // countedBars = the number of bars that have not changed since the last launch of the indicator

i = barSize - countedBars - 1; // set the number of iterations of the loop

// The while statement creates a loop that executes a given set of instructions while the condition is being verified. The logical value of the condition is computed before the loop body is executed. "
		// developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/while
		while (i> = 0) {// loop through i from the beginning of the data to the end - to the last (current, zero) bar

// save the values of arrays High, Low and Close in temporary variables for the current bar (with index i)
h = High [i];
l = Low [i];
c = Close [i];

// calculate the buffer value - Y coordinate of the indicator line
ExtMapBuffer1.set (i, ((c - l) - (h - c))); // set the value of the i-th element equal to (Close [i] - Low [i]) - (High [i] – Close[i]) mtrader7.com/ru/docs/Terminal/mScript/JavaScript/v1/Buffer/set
            if (ExtMapBuffer1.get (i)! == 0) {// if now the value of ExtMapBuffer1 [i] is not 0; //mtrader7.com/ru/docs/Terminal/mScript/JavaScript/v1/Buffer/get
                let diff = h - l; // High [i] - Low [i]
if (0 === diff) {// if the resulting diff is zero
ExtMapBuffer1.set (i, 0); // set the value of the ith element of the buffer = 0
}
else {// if the resulting diff is not zero
ExtMapBuffer1.set (i, (ExtMapBuffer1.get (i) / diff));
ExtMapBuffer1.set (i, (ExtMapBuffer1.get (i) * Volume [i]));
} // end if (0 === diff)
} // end if (ExtMapBuffer1.get (i)! == 0)

if (i