Doubt in OnCalculate

 

I'm trying to create a new indicator that calculates the sum of a array (matrix of 5 symbols with correlation) and divides by a specified number.

The calculation is correct, but i'm having problems with the indicator plot. Probably in the OnCalculate part.

i want the indicator look like a moving average....  

Here is the code:

//+------------------------------------------------------------------+
//|IBOV calculation                                                  |
//+------------------------------------------------------------------+
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_separate_window

#property indicator_type1   DRAW_LINE
#property indicator_label1  "IBOV"
#property indicator_color1  clrMagenta
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

//--- matrix
double   matrix[5][1];

//--- indicator buffers
double   AVXT[];

//--- global variable
double   constant = 2746.9902;
int pos;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
   IndicatorSetInteger(INDICATOR_DIGITS,2);
   SetIndexBuffer(0,AVXT,INDICATOR_DATA);
   
//--- sets first bar from what indicator will be drawn
//   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,0);
   
//--- name for DataWindow and indicator subwindow label
   string short_name="AVXT";
   IndicatorSetString(INDICATOR_SHORTNAME,short_name);
   PlotIndexSetString(0,PLOT_LABEL,short_name);
   
//--- Set AVXT as time series
   ArraySetAsSeries(AVXT,true);

   return(INIT_SUCCEEDED);
}
   
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |                                                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
matrix[ 0 ][0]=   4320157092 * (SymbolInfoDouble("Symbol1",SYMBOL_LAST));
matrix[ 1 ][0]=   2035474854 * (SymbolInfoDouble("Symbol2",SYMBOL_LAST));
matrix[ 2 ][0]=   1226268476 * (SymbolInfoDouble("Symbol3",SYMBOL_LAST));
matrix[ 3 ][0]=   629085664  * (SymbolInfoDouble("Symbol4",SYMBOL_LAST));
matrix[ 4 ][0]=   3229206347 * (SymbolInfoDouble("Symbol5",SYMBOL_LAST));


//--- starting calculation
   if(prev_calculated>1) pos=prev_calculated-1;
   else pos=0;
      
//--- main cycle   
   for(int i=pos;i<rates_total && !IsStopped();i++)   AVXT[i] = sum()/constant;
      
//--- return value of prev_calculated for next call
   return(rates_total);
}

//+------------------------------------------------------------------+
//|Calculate Sum of indicator                                        |
//+------------------------------------------------------------------+
double sum () 
{
//--- variables
   double sum_value=0.0;  
   
//--- calcualte sum_value
   for(int a=0;a<5 && !IsStopped();a++)  sum_value += matrix[a][0];   
     
//--- return calculated value          
   return (sum_value);   
}
 
santosphm: , but i'm having problems

"Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless.

There are no mind readers here and our crystal balls are cracked.

 
As global variable you declare matriX but in OnCalculate you try to use matriZ. I can see where is declared array matriZ. When compile program compilator need to warn it for this.
 
Nikolay Yurgandzhiev:
As global variable you declare matriX but in OnCalculate you try to use matriZ. I can see where is declared array matriZ. When compile program compilator need to warn it for this

when i pasted here, i translated and forgot to change this, but thanks. 

The error that occurs is: The indicator line is straight, it dosn't change with the close price, like the moving average. 

the pink is my indicator and the red is the moving average. 


 
whroeder1:

"Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless.

There are no mind readers here and our crystal balls are cracked.

Sorry, 

The error that occurs is: The indicator line is straight, it dosn't change with the close price, like the moving average for example .

I think the problem is how to transform it on a time series. The previous data is the same as the current data. 

 
santosphm: The indicator line is straight, it dosn't change with the close price,\
That is exactly what it should do. No problem. PICNIC
AVXT[i] = sum()/constant;
Both sum and constant do not depend on i.
 

whroeder1:


Both sum and constant do not depend on i.

It is my first attempt to create an indicator

Any ideia how can i change that, now that you understood my intencion with this indicator?

 
  1. Don't double post!
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. I have no idea what your intention is. Decide what you want to display, change your buffer assignment to that.
 
I have deleted your other post. Please do not duplicate posts again.
 
Keith Watford:
I have deleted your other post. Please do not duplicate posts again.
Sorry for duplicates. 
 
whroeder1:
That is exactly what it should do. No problem. PICNIC
Both sum and constant do not depend on i.
I fixed it, thanks man !!!
Reason: