2 questions about arrays

 

Hi, 

I'm trying to understand the Didi_index indicator

1st question: Does 1 and 2 provide the same outcome for CurtaBuffer [i]?

double A;

int i = 1;

1)  CurtaBuffer [i] /= MediaBuffer [i];

2) A = CurtaBuffer [i] / MediaBuffer [i];

    CurtaBuffer [i] = A;

2nd question: 

In the code below I received this error: Didi_Index USDCHF, Daily; zero deivide in 'Didi_Index.mq4' (75,25) when I use it with my EA code. What could be causing that? Could it be that some of my tick data is incorrect?

//+------------------------------------------------------------------+
//|                                                   Didi Index.mq4 |
//|                                                Rudinei Felipetto |
//|                                         http://www.conttinua.com |
//+------------------------------------------------------------------+
#property copyright "Rudinei Felipetto"
#property link      "http://www.conttinua.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3

//--- plot Curta
#property indicator_label1 "Curta"
#property indicator_type1  DRAW_LINE
#property indicator_color1 clrLime
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot Media
#property indicator_label2 "Media"
#property indicator_type2  DRAW_LINE
#property indicator_color2 clrWhite
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- plot Longa
#property indicator_label3 "Longa"
#property indicator_type3  DRAW_LINE
#property indicator_color3 clrYellow
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- input parameters
extern int Curta=3;
extern ENUM_APPLIED_PRICE CurtaAppliedPrice = PRICE_CLOSE;
extern ENUM_MA_METHOD CurtaMethod = MODE_SMA;

extern int Media=8;
extern ENUM_APPLIED_PRICE MediaAppliedPrice = PRICE_CLOSE;
extern ENUM_MA_METHOD MediaMethod = MODE_SMA;

extern int Longa=20;
extern ENUM_APPLIED_PRICE LongaAppliedPrice = PRICE_CLOSE;
extern ENUM_MA_METHOD LongaMethod = MODE_SMA;

//--- indicator buffers
double CurtaBuffer[];
double MediaBuffer[];
double LongaBuffer[];

int init()
{
   SetIndexBuffer(0, CurtaBuffer, INDICATOR_DATA);
   SetIndexBuffer(1, MediaBuffer, INDICATOR_DATA);
   SetIndexBuffer(2, LongaBuffer, INDICATOR_DATA);
   
   return(0);
}

int start()
{
   if(Bars<=Longa) return(0);

        CalculateDidiIndex();

   return(0);
  }
//+------------------------------------------------------------------+
void CalculateDidiIndex()
{
   for(int i = 1; i <= Bars; i++)
   {
      CurtaBuffer[i] = iMA(_Symbol, 0, Curta, 0, CurtaMethod, CurtaAppliedPrice, i);
      MediaBuffer[i] = iMA(_Symbol, 0, Media, 0, MediaMethod, MediaAppliedPrice, i);
      LongaBuffer[i] = iMA(_Symbol, 0, Longa, 0, LongaMethod, LongaAppliedPrice, i);
      
      CurtaBuffer[i] /= MediaBuffer[i];
      LongaBuffer[i] /= MediaBuffer[i];
      MediaBuffer[i] = 1;
   }
 
drinkyd: 1st question: Does 1 and 2 provide the same outcome for ShortBuffer [i]?
CurtaBuffer [i] /= MediaBuffer [i];     // 1)
//////////////////////////////////////////
int i = 1;                              // 2)
int A = CurtaBuffer [i] / MediaBuffer [i];
    CurtaBuffer [i] = A;

2nd question: 

In the code below I received this error: Didi_Index USDCHF, Daily; zero deivide in 'Didi_Index.mq4' (75,25) when I use it with my EA code. What could be causing that? Could it be that some of my tick data is incorrect?

  1. You didn't provide anything about ShortBuffer[i]

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  3. double/double is not the same as int/int.  № one and № two would be identical if A was a double.
              On MT4 v434, division quotient don't give floating point values(Bug??) - MQL4 programming forum 2012.09.18

  4.    for(int i = 1; i <= Bars; i++){
          CurtaBuffer[i] = iMA(_Symbol, 0, Curta, 0, CurtaMethod, CurtaAppliedPrice, i);
          MediaBuffer[i] = iMA(_Symbol, 0, Media, 0, MediaMethod, MediaAppliedPrice, i);
    There are Bars candles on the chart. Their indexes are [0 … Bars-1]. When i equalsBars you got zeros from iMA, thus your "zero divide." You would know that if you had used strict.

    Always use strict. Fixing the warnings will save you hours of debugging.

  5. In addition you can't get the moving average(length) until you have length bars.
              How to do your lookbacks correctly.