Simple counter producing number i do not want

 

Hi, I am learning to code, wrote a simple counter as practice.  

it is just supposed to Print  1,2,3,4,5,etc but the count is coming out as 6363,6364,6365 etc.

Can someone tell me what I have done wrong.

Thank you in advance.

//+------------------------------------------------------------------+
//|                                                    Newbie2.0.mq4 |
//|                                   Copyright 2019, Harvey Trading |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, Harvey Trading"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   double NumberToAddTo=0.0;
   double a = 1; 
   int i;
   for(i=1;i<Bars;i++) 
     {
      NumberToAddTo+=a;
      Print("Number is "+ DoubleToString( NumberToAddTo,1));
      
     }

  }
//+------------------------------------------------------------------
 
Richard Roberts: Can someone tell me what I have done wrong.

My guess: you are printing so much that your assumption that the GUI is showing all lines, is wrong. Right Click on a line and open the real log file.

 
Richard Roberts:

Hi, I am learning to code, wrote a simple counter as practice.  

it is just supposed to Print  1,2,3,4,5,etc but the count is coming out as 6363,6364,6365 etc.

Can someone tell me what I have done wrong.

Thank you in advance.

I think it is because you are using Bars.

I don't know why but if you are trying to count the candle in the chart, use:

long candleCount = ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);

for(int i = 0; i < candleCount; i++){
   //do you thing here
}

goodluck.

 
William Roeder:

My guess: you are printing so much that your assumption that the GUI is showing all lines, is wrong. Right Click on a line and open the real log file.

That was it, thank you for the help
 
Ahmad Zuhairdi Noh:

I think it is because you are using Bars.

I don't know why but if you are trying to count the candle in the chart, use:

goodluck.

Thank you for advise