Buffer start at 0

 

Trying to get a buffer to start from 0, as opposed to the calculated amount.  Below is a simplistic example where the initial value (1000) will reflect the close of the current symbol.  I'm trying to get it to start from 0 and show the movement from that point on.  Any help would be appreciated.  Thanks

 

     int k=1000;

     while (k>=0)

     {

     ExtMapBuffer[k]=iClose(Symbol(),0,k);

     k--;

     } 

 
The_InvestorAny help would be appreciated. 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Help which what? You've stated no problem.
  3. Do your lookbacks correctly.
 
//+------------------------------------------------------------------+
//|                                                        Start.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property  indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property  indicator_width1  2

//---- indicator buffers
double ExtMapBuffer[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
  
   IndicatorShortName(Bars);
   SetIndexDrawBegin(0,0);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   
   sma();

   return(0);
  }

void sma()
  {

   int pos=1000;

   while(pos>=0)
     {

      ExtMapBuffer[pos]=iClose(Symbol(),0,pos);

      pos--;
     }
  }
 
To clarify a little. This essentially shows a 1 period moving average, back 1000 bars. Now the issue, on the start bar (1000) it's taking the calculation as the start for the value on the indicator. I'm trying to figure out how to have the initial bar have a value of 0, as opposed to the calculated value, then bars 999->0 be calculated value of iClose(Symbol(),0,pos).     Bar1000 = 0;    Bar999 = Bar1000+Calculated;    Bar998 = Bar 999+Calculated;     etc.
 
void sma()
  {

   int pos=1000;
   ExtMapBuffer[pos]=0);
   pos--;
   while(pos>=0)
     {

      ExtMapBuffer[pos]=iClose(Symbol(),0,pos);

      pos--;
     }
  }

.

 
Exactly what I needed, thanks GumRai!
Reason: