Newbie question about the Bars variable

 
Hi,

I'm reading the Book/Documents and the articles on this site.
I'm not completely understanding the built in Bars variable
Also I'm super new to programming so much of what I'm learning I have to constantly reference C++ sites to learn those topic first and then come back and re-read what I didn't understand at first.

Anyhow the newbie article is here:

https://www.mql5.com/en/articles/1475

And the part about:

Integrated or Built-in Arrays and Variables

Where it begins talking about the loop and the cycles. (a<Bars)

I'm almost understanding it I think I'm close, but as I understand the loop it's just counting bars ? and inputing the number for (a) into the index and counting the next bar. But I'm not sure I completely understand this or what (AveragePrice) is actually doing other then declaring it, and NO output other then to count ?

Am I right about this ?
double AveragePrice = 0.0;   
for(int a = 0; a < Bars; a++)
{     
    AveragePrice += High[a];
}
Anyhow Please clarify the variiable Bars.

I read through iBars but I'm just missing it.

Thanks
 
  1. On any chart the total count of candles is Bars. Candle zero, candle one, ... candle Bars-1.
  2. The loop is indexing through every candle. Shift of zero the the current candle, shift of one is the previous.
  3. The loop body is summing the highs of each candle.
  4. To compute the average price you sum all the prices and then divide by the count, (missing in your post.)
  5. Better variable names may help:
    double Sum = 0.0;   
    for(int shift = 0; shift < Bars; shift++) // All candles
        sum += High[shift];                   // Sum the highs
    double AveragePrice = Sum / Bars;         // Ave = Sum / Count
    
  6. Lessons
 

From here: https://docs.mql4.com/predefined/variables/bars

Bars :

Number of bars in the current chart.

In MT4 Options, under the Charts tab there is an option/variable called Maximum bars in chart, if you set this value to 1000 and open a new chart the value of Bars will always be 1000, so Bars is the number of bars in a chart.

In a chart where you have 1000 bars the currently forming bar on the right is bar number 0, the last bar on the left is number 999

In your code snippet the loop counts through the bars, from 0 to less than Bars (999) at an increment of 1, so starting with 0, then 1, then 2, then 3, etc . . . . each time though the loop AveragePrice has the High value for bar number a added to it, so it is continually summing the bar High values.

After this loop add this bit of code and it will be complete . . .

AveragePrice = AveragePrice/Bars;    // AveragePrice is the average value of all the bar High values in the chart
 
Thanks
 
I re-combined all those pdf's into 1 large document and now starting to re-read the lessons.
And of course the sample .mq4's

So huh ? I'm not complaining but there is only PDF's huh ? no html version of the lessons ?
 
Agent86:
So huh ? I'm not complaining but there is only PDF's huh ? no html version of the lessons ?
Why don't you ask the poster of the files on that board? This forum has nothing to do with them.
 
WHRoeder:
Why don't you ask the poster of the files on that board? This forum has nothing to do with them.
I see, just thought if anyone knew since the link was posted to the PDF's someone may have had a link to html as well.

Actually the PDF turns out better for me I can print it out then read while the commercials of a TV program are on.

Thanks