Problem with working buffers

 

Hi,

my problem is seeing from screen:

 
#property copyright "20.06.2012"
#property link      "ms_soft@"
//----
#define pocet 18

#property indicator_chart_window
#property  indicator_buffers 2

double ZeroHistBuffer[];
double ZeroSignalBuffer[];

string arrayticker[pocet];  
int j=0, i=0;
int TF[7]; 
int Bar[pocet][7]; 


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(2);
   
   SetIndexBuffer(0, ZeroHistBuffer);
   SetIndexBuffer(1, ZeroSignalBuffer);
   
   SetIndexStyle(0, DRAW_NONE);
   SetIndexStyle(1, DRAW_NONE);
     
   IndicatorDigits(Digits+2);
   
   arrayticker[0] ="AUDCAD"; //8
   arrayticker[1] ="AUDJPY"; //5
   arrayticker[2] ="AUDNZD"; //15
   arrayticker[3] ="AUDUSD"; //3
   arrayticker[4] ="EURAUD"; //9
   arrayticker[5] ="EURCAD"; //10
   arrayticker[6] ="EURGBP"; //3
   arrayticker[7] ="EURCHF"; //4
   arrayticker[8] ="EURJPY"; //3
   arrayticker[9] ="EURUSD"; //1
   arrayticker[10]="GBPCHF"; //6
   arrayticker[11]="GBPJPY"; //6
   arrayticker[12]="GBPUSD"; //2
   arrayticker[13]="CHFJPY"; //6
   arrayticker[14]="NZDUSD"; //4
   arrayticker[15]="USDCAD"; //3
   arrayticker[16]="USDJPY"; //2
   arrayticker[17]="USDCHF"; //2
   TF[0]=5; TF[1]=15; TF[2]=30; TF[3]=60; TF[4]=240; TF[5]=1440;  TF[6]=10080;   
   for(int j = 0; j <=6; j++) 
   {
     for(int a = 0; a <=pocet-1; a++) { Bar[a][j]= iBars(arrayticker[a],TF[j])-1; } 
   }
   j=0; 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  j=6;
  while (j>=0)
  {
   while(i<pocet)
   { 
     if (Bar[i][j] < iBars(arrayticker[i],TF[j]) && (i==3 || i==9 || i==12) && j==0) // only  AUDUSD, EURUSD, GBPUSD
     {  
       Bar[i][j]  = iBars(arrayticker[i],TF[j]);   
       CalcZero_and_MACD();
       Alert (arrayticker[i],"(",TF[j],") Zero: Hist= ",DoubleToStr(ZeroHistBuffer[1],6)," Signal= ",DoubleToStr(ZeroSignalBuffer[1],6));
     } 
     Bar[i][j]  = iBars(arrayticker[i],TF[j]); 
     i++;
   }  // end while i
   j--; i=0;
  }  // end while j       
   
   return(0);
  }
//+------------------------------------------------------------------+
void CalcZero_and_MACD()
{
   int limit;
   //if (iBars(arrayticker[i],TF[j])<1000) return(0);
   //limit = 1000;// limit=Bars - counted_bars; // 
   //limit= iBars(arrayticker[i],TF[j]);
   limit=Bars;


   for(int x = 0; x < limit; x++)
     ZeroSignalBuffer[x] = iMA(arrayticker[i],TF[j], 10, 0, MODE_EMA, PRICE_CLOSE, x);
       //
   /*    
   if (i>3)
     for( x = 0; x < limit; x++) ZeroSignalBuffer[x] = 10;
   
   for( x = 0; x < limit; x++) ZeroHistBuffer[x] = 0;
   */
   
   //   !!!  problem is here !!!
   for(x = 0; x < limit; x++)
       ZeroHistBuffer[x]=iMAOnArray(ZeroSignalBuffer,0,100,0,MODE_EMA,x);
   
}
 
Can you help me, please? Problem is last row.... calc values of buffer.
 
endy5:
Can you help me, please? Problem is last row.... calc values of buffer.

You have 2 for inside a while inside a while, OK, maybe next ... century.

LOL ... maybe you should change your avatar first.

 
     Alert (arrayticker[i],"(",TF[j],") Zero: Hist= ",DoubleToStr(ZeroHistBuffer[1],6)," Signal= "

You are print out HistBuffer[ one ] not HistBuffer[ eye ]

Another reason not to use variables like i, j, k. Use descriptive names iPair, iTF.

 

Cycles while / for aren´t problem. It´s ok. When you see code you find that calc si doing 1x/bar (after closed bar!)

Therefore using variable Bar[] .

WHRoeder: index "1" is really ok. This is check alert and I want see value ZeroHistBuffer[] on last ending bar.

I reduced number of rows in my code.

#property copyright "20.06.2012"
#property link      "ms_soft@"
//----
#define pocet 3

#property indicator_chart_window
#property  indicator_buffers 2

double ZeroHistBuffer[];
double ZeroSignalBuffer[];

string arrayticker[pocet];  
int j=0, i=0;
int Bar[pocet];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(2);
   
   SetIndexBuffer(0, ZeroHistBuffer);
   SetIndexBuffer(1, ZeroSignalBuffer);
   
   SetIndexStyle(0, DRAW_NONE);
   SetIndexStyle(1, DRAW_NONE);
     
   IndicatorDigits(Digits+2);
   
   arrayticker[0] ="AUDUSD"; 
   arrayticker[1] ="EURUSD"; 
   arrayticker[2] ="GBPUSD"; 
   for(int a = 0; a <=pocet-1; a++) { Bar[a]= iBars(arrayticker[a],PERIOD_M5)-1; } 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  i=0;
  while(i<pocet)   
  { 
    if (Bar[i] < iBars(arrayticker[i],PERIOD_M5))  
    {  
       Bar[i] = iBars(arrayticker[i],PERIOD_M5);   
       CalcZero_and_MA();
       Alert (arrayticker[i],"(5), Zero: Hist= ",DoubleToStr(ZeroHistBuffer[1],6)," Signal= ",DoubleToStr(ZeroSignalBuffer[1],6));
    }  
    i++;  
  }  // end while i
   
  return(0);
}
//+------------------------------------------------------------------+
void CalcZero_and_MA()
{
   int limit;
   //if (iBars(arrayticker[i],TF[j])<1000) return(0);
   //limit = 1000;// limit=Bars - counted_bars; // 
   //limit= iBars(arrayticker[i],TF[j]);
   limit=Bars;

   for(int x = 0; x < limit; x++)
     ZeroSignalBuffer[x] = iMA(arrayticker[i],PERIOD_M5, 10, 0, MODE_EMA, PRICE_CLOSE, x);   
   for(x = 0; x < limit; x++)  // problem is here....!!!
       ZeroHistBuffer[x]=iMAOnArray(ZeroSignalBuffer,0,100,0,MODE_EMA,x);
   
}

I insert indicator on EURUSD.

Last Alert window: ZeroHistBuffer[] for EURUSD and GBPUSD is the same as AUDUSD! Why?!? Absurd situation for me.....

 
I don´t know really where is error...
 

I am unhappy, flustrated from my code...

Can you someone see it, please?

Reason: