closing price

 

I want to show the closing price of the previous bar when it comes to the new bar

And I'm using this code to do this, but it's a mistake

void OnTick()
  {
double Open[];
int count;   // number of elements to copy
ArraySetAsSeries(Open,true);
CopyOpen(_Symbol,_Period,0,count,Open);
   
   

                       
              int Bars=Bars(_Symbol,_Period);

             for(int i = 1 ; i <= Bars ; i++)
              {
                  
                 double open = Open[i];
                 Comment(open) ;
                  
                  
              }
  }

I think for() has a problem

But I do not know what that problem is

 
  1. You can only show one comment. The for is unnecessary.

  2. int count;   // number of elements to copy
    CopyOpen(_Symbol,_Period,0,count,Open);
    Count has a random value.

  3.  for(int i = 1 ; i <= Bars ; i++){
       double open = Open[i];
    When i equals Bars, Open[i] does not exist. If there are n things they are numbered [0 .. n-1]

  4. You set Open to as series. Therefor the newest value is index zero.
 
moslemS:

I want to show the closing price of the previous bar when it comes to the new bar

And I'm using this code to do this, but it's a mistake

I think for() has a problem

But I do not know what that problem is

No need to loop if all you want is the close price of the prev bar. 

{
   double c;
   if(LastBarClose(c))
      printf("The close of the last bar is %f",c);
}


bool LastBarClose(double &value)
{
   value = 0.0;
   static datetime   last_bar = 0;
   static double     close[1] = {0.0};
   datetime          curr_bar = (datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
   if(curr_bar == last_bar)
   {
      value = close[0];
      if(value > 0.0)
         return true;
   }
   last_bar = curr_bar;
   ArraySetAsSeries(close,true);
   if(CopyClose(_Symbol,_Period,1,1,close) > 0)
      value = close[0];
   return value > 0.0;   
}
 

Double and triple posts removed. Please don't do that again.

General rules and best pratices of the Forum.