Appendix 1 - BARS - page 2

 
 

Thank u all, this real great work

 

Bars vs. IndicatorCounted() and Coding Efficency

Techguy:
Additional help for Bar referencing...

The Word document attached to the above referenced post states:

"int Bars

This internally updated variable returns the number of bars on the current chart, including the incomplete current bar. Bars is a reserved word and can be used in your code. It will reference the One Based numbering system count of all bars on the chart...

int IndicatorCounted()

This Function could be better thought of as the int Count_Of_Fully_Completed_Bars_Which_Are On_the_Chart ().

This function actually returns the bar count of fully completed bars that has not changed since the last time a quote was received, but does Not count the current uncompleted bar. In most cases, the same total count of index numbers will have not changed between individually received quotes and it is a big waste of time and effort for the program to recount the Bar array index every time the int Start () function is executed because a new quote has been received.

It has a return value in the int Start () of the total count of Bars - 1. The newest Bar is not counted if it is an incomplete bar and still in the process of forming. Until the new bar is complete, it will not be counted."

Techguy and codersguru,

After reading all this bar count stuff, me braaain 'urrts!!!

I have noticed very few mq4 files bother to use the IndicatorCounted() function. They use the Bars function instead, since one knows the number generated by Bars is the same as the number generated by IndicatorCounted() -1.

The phrase that caught my eye was "it is a big waste of time and effort for the program to recount the Bar array index every time the int Start () function is executed because a new quote has been received". What is actually going on with the workings of IndicatorCounted()? Does it count all the bars (except the current bar) only once when attached to the chart, then thereafter just increments the count immediately after each new bar is formed? Perhaps this should be clarified in the document.

What are some rules and guidelines for when to apply each of these functions assuming one is aware that they differ in value by one bar?

Similarly, while we are on the subject of coding efficency, it seems to me that many indicators only need to be drawn once, and may only need to be updated once a day or maybe once per bar (e.g. some pivot point programs).

What are some techniques for periodically updating the drawing of an object rather than updating it every tick? Can periodic updating also be applied to lines drawn with arrays?

Thank you both for efforts and contributions on this site.

WRR

 

thanks for you all, Coderguru & techguy,

finally i know where i must started

 

Some good information. Can someone post all the functions available to EXCEL?

 

Time in your bar

is there a way to calculate how much time is left in the formation of the current bar ?

for example.... 5 min chart

I know that i want to enter a position on the next bar if it reaches a certian price.

it that bar hit the target price within the first 30 seconds of opening, i know that there is a good probibilaty that I will be able to enter my position at an even better price.

How can I put some sort of countdown on the current bar formation?

 
Kurka Fund:
is there a way to calculate how much time is left in the formation of the current bar ?

I believe I saw some code in MQL4 Articles: automated forex trading, strategy tester, expert advisors and custom indicatorsIt compared the date of the current bar vs date of a previous one to compute time remaining.

 
WHRoeder:
I believe I saw some code in MQL4 Articles: automated forex trading, strategy tester, expert advisors and custom indicatorsIt compared the date of the current bar vs date of a previous one to compute time remaining.

int nextBar=Time[0]+Period()*60;

int secondsRemaining=nextBar-CurTime(); // negative values are possible