Historical Bar count problem

 

I have the following code in the start section:

int counted_bars=IndicatorCounted();
 int i=Bars-counted_bars-1;
 Print(i + " Start");  << when I run the code on a eurusd i = 65019
 

 
  while(i>=0)
  {
 // Print (i + "Not Start");   <<< This is commented

 i--;

 } 

 

Then I uncomment the 'Not Start" section and I get

2013.04.07 20:18:01 MTFMACrossInd EURUSD,M5: 203Not Start

203 is my highest value for i.  The "Start" code above does not show up.

 

What am I doing wrong??

Thank you... 


 

 

Read https://www.mql5.com/en/articles/1500.

Learn how to locate the Log_File.

And use the SRC button when inserting codes. 

 

 
Try
if(i<50) Print (i + "Not Start");
 
ubzen:

Read https://www.mql5.com/en/articles/1500.

Learn how to locate the Log_File.

And use the SRC button when inserting codes. 

 

ubzen--thank you for your reply....

I know how to get to the log file.  I just do not understand the results of the variable 'i'.  I am just trying to count the number of bars.

What am I missing?

I will keep searching...

Thank you for the advice.

 
dukeb:

ubzen--thank you for your reply....

I know how to get to the log file.  I just do not understand the results of the variable 'i'.  I am just trying to count the number of bars.

What am I missing?

The value returned by IndicatorCounted() changes, it is not a constant,  so the value of i will also change as it is calculated from IndicatorCounted().  Uncomment the   "Not start"  line,  remove the indicator from your chart,  then re-attach it and look in the experts tab or the experts log . . .  
 
RaptorUK:
The value returned by IndicatorCounted() changes, it is not a constant,  so the value of i will also change as it is calculated from IndicatorCounted().  Uncomment the   "Not start"  line,  remove the indicator from your chart,  then re-attach it and look in the experts tab or the experts log . . .  

                                                                                                                                                                                                                                                                    

Thank you, Raptor.... I now get 2049 both times.  I do not know why.  Is there an explanation?

Thanks again... 

 
dukeb: Thank you, Raptor.... I now get 2049 both times.  I do not know why.  Is there an explanation?

Did you read the Article link I provided. It explains IndicatorCounted(). Like RaptorUK said "The value returned by IndicatorCounted() changes".

1>On the 1st Run, IndicatorCounted() returns the count of All_Bars [Uncounted]. This is why the values are the same when you Print both i's.

2>On the 2nd Run, IndicatorCounted() returns only those bars which have changed or new. Therefore if you wait after the 1st run then Print i or IndicatorCounted() then value will be smaller.

3>Your while(Loop) Prints much faster than the Experts_Tab can keep up with. This could be why you're not seeing some print statements. To see all print statements, open the actual Log.txt file.

 
ubzen:

Did you read the Article link I provided. It explains IndicatorCounted(). Like RaptorUK said "The value returned by IndicatorCounted() changes".

1>On the 1st Run, IndicatorCounted() returns the count of All_Bars [Uncounted]. This is why the values are the same when you Print both i's.

2>On the 2nd Run, IndicatorCounted() returns only those bars which have changed or new. Therefore if you wait after the 1st run then Print i or IndicatorCounted() then value will be smaller.

3>Your while(Loop) Prints much faster than the Experts_Tab can keep up with. This could be why you're not seeing some print statements. To see all print            statements, open the actual Log.txt file.                                                                                                                                                                                    

                               

Thank you, ubzen;

As I understand this, the software will process existing (historical) bars faster than IndicatorCounted() will accumulate new bars.  Therefore, IndicatorCounted() will get smaller and smaller until all bars seen by the software will be new bars or bars(0).  Correct?

 
dukeb:Thank you, ubzen; As I understand this, the software will process existing (historical) bars faster than IndicatorCounted() will accumulate new bars.  Therefore, IndicatorCounted() will get smaller and smaller until all bars seen by the software will be new bars or bars(0).  Correct?
Yeah, keep testing and you'll learn how it works.
Reason: