[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 275

 
alsu:

I don't see your int i string and index initialisation. Please, in the studio.

ZZY I don't speak Lithuanian well, the comments in the code throw me off a bit)))

I have zeros in the array. The array is increasing normally. It is visible in the print.

2013.04.08 23:18:37 2013.04.04 20:00 testavimas naktini fleta EURUSD,M15: ArraySize 19

but it writes zeros in the array

2013.04.08 23:18:37 2013.04.04 20:00 testavimas naktini fleta EURUSD,M15: avgPriceC[8]=0.00000000
2013.04.08 23:18:37 2013.04.04 20:00 testavimas naktini fleta EURUSD,M15: avgPriceC[7]=0.00000000
04.04 20:00 testavimas naktini fleta EURUSD,M15: avgPriceC[6]=0.00000000
2013.04.08 23:18:37 2013.04.04 20:00 testavimas naktini fleta EURUSD,M15: avgPriceC[5]=0.00000000
2013.04.08 23:18:37 2013.04.04 20:00 testavimas naktini fleta EURUSD,M15: avgPriceC[4]=0.00000000
2013.04.08 23:18:37 2013.04.04 20:00 testavimas naktini fleta EURUSD,M15: avgPriceC[3]=0.00000000
2013.04.08 23:18:37 2013.04.04 20:00 testavimas naktini fleta EURUSD,M15: avgPriceC[2]=0.00000000
2013.04.08 23:18:37 2013.04.04 20:00 testavimas naktini fleta EURUSD,M15: avgPriceC[1]=0.00000000
2013.04.08 23:18:37 2013.04.04 20:00 testavimas naktini fleta EURUSD,M15: avgPriceC[0]=0.00000000
All elements with value 0

avgPriceC[i] = Close[1];

but don't know how. May be the reason for something else. I even reinstalled my MetaTrader. It did not help.

I want to get infinite array with beginning by primary data, but end is not specified.

//greitas MA
extern int     MA_Period1     =  8;
extern int     plius1         =  100;
extern int     MA_Shift1      =  0;
extern int     MA_Method1     =  0;                                                 
//Letas MA
extern int     MA_Period2     =  13;
extern int     plius2         =  100;
extern int     MA_Shift2      =  0;
extern int     MA_Method2     =  3;                                                 
//Fleto pradzia
//fleto ipradzios eskojimas pagal indikatoriu arba laika
extern bool  start       =  true;    // true ->pagal indikatoriu, false->pagal laika
// pagal indikatoriu fleto pradzios pradesim ieskoti nuo sio laiko
extern int     startHourFlatMA        =  16;    
extern int     startMinFlatMA        =  00;
extern string  startstartFlatMA       = "16:00";
extern string  endstartFlatMA       = "00:00";
//suradus pagal indikatoriu dar lauksim kol uzsidarys BarEnd zvake
extern bool    zvakes_pabaiga = true;//ar lauksim kol uzsidarys M240 zvake, ar priimsim kad fletas prasidejo nuo susikirtimo
extern int     BarEnd         =  240;
datetime       LastTime;
//datetime       startTime;
// pagal laika fleto pradzios pradesim ieskoti nuo sio laiko
extern int     startHourFlat        =  0;   //
extern int     startMinFlat         =  0;    //

//fleto pabaiga
//Fleto pabaiga jei indikatorius duoda signala siame laiko tarpe
//Laiko tarpo pradzia
extern int     startHourEnd        =  4;    
extern int     startMinEnd         =  45;
//laiko tarpo pabaiga arba fleto pabaiga
extern int     endHourEnd        =  7;    
extern int     endMinEnd         =  30;

//Ar naudosom Volumes filtra
extern bool volFiltr = true;            //true -> naudosim,   false -> nanaudosim

//skirtumas tarp penktadienio uzdarymo ir pirmadienio atidarymo
extern int   gep = 300;  



//Naktinio-fletinio pipsavimo ijungimas
bool nightFlat = false; //true -> ijungtas,   false -> neijungtas



bool           susikirtimas = false;      
bool           flat; 
//masyvai
double chPriceH[], chPriceL[], chPriceO[], chPriceC[], chTime[];
double avgPriceH[], avgPriceL[], avgPriceO[], avgPriceC[]; 
int i = -1; // masyvu indeksas -1, nes toliau pridesim 1, o masyvu indeksacija prasideda nuo 0
int j = -1; // masyvu indeksas -1, nes toliau pridesim 1, o masyvu indeksacija prasideda nuo 0
int n = -1;                          // kintamasis naujo masyvo indeksacijai
int iH, iL ,iO, iC, iT;
double C[], T[], y[];
double max;                               //max skirtumas tarp LR median ir Close
//*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*--*-*--*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-* 

int init ()
{
ArrayResize(chPriceH, 0);
ArrayResize(chPriceL, 0);
ArrayResize(chPriceO, 0);
ArrayResize(chPriceC, 0);
ArrayResize(chTime, 0);
ArrayResize(avgPriceH, 0); 
ArrayResize(avgPriceL, 0); 
ArrayResize(avgPriceO, 0); 
ArrayResize(avgPriceC, 0); 
ArrayResize (C, 0); 
ArrayResize (T, 0);
ArrayResize (y, 0);
}
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-**-*-*-*-*-*-*-*-*-*-
 int start()
 {
   double volMA11, volMA12, volMA21, volMA22;  
   double x[], y[]; 
   
   Print("******************STARTAS*****************************************");
   
   if(!TF_F_NewBar())return(0);
 
   volMA11 = iCustom(NULL, 15, "volumeMA",  2, 1);         
   volMA12 = iCustom(NULL, 15, "volumeMA",  2, 2);
   volMA21 = iCustom(NULL, 15, "volumeMA",  3, 1);
   volMA22 = iCustom(NULL, 15, "volumeMA",  3, 2);
    
   if(DayOfWeek()==1 || DayOfWeek()==2 || DayOfWeek()==3 || DayOfWeek()==4)                             //jei pirmadienis antradienis ar treciadienis, ar ketvirtadienis
   {         
      if(TimeCurrent()>= StrToTime(startstartFlatMA) && TimeCurrent()<= StrToTime(endstartFlatMA)+24*60*60)
      {
         //Print("fleto starto ieskojimo laikas prasidejo  "+TimeToStr(TimeCurrent())+" >= "+TimeToStr(StrToTime(startstartFlatMA))+
               //"  &&  "+TimeToStr(TimeCurrent())+" <= "+TimeToStr(StrToTime(endstartFlatMA)+24*60*60));
         bool laikas = true;
         Print("laikas = "+laikas);         
         if(volMA21 - volMA11 > 0 && volMA12 - volMA22 > 0)
         {                                                                                   //jei buvo susikirtimas
            susikirtimas = true;           
         }
         if(susikirtimas == true) 
         {
            if(zvakes_pabaiga)
            {
               if(iTime(NULL, BarEnd, 1)!= LastTime)
               {            
                  LastTime = iTime(NULL, BarEnd, 1);
                  flat = true;           
                  LastTime = iTime(NULL, BarEnd, 1);
              }
              else return(0);            
           }
           else flat = true;
           if(flat == true)
           {
               i++; 
             //Zinodami indekso eiles numeri galim keisti masyvo ilgi
            
            ArrayResize(avgPriceH,i); 
            ArrayResize(avgPriceL,i);
            ArrayResize(avgPriceO,i); 
            ArrayResize(avgPriceC,i);        
           Print("ArraySize     "+ArraySize(avgPriceC));
            //jei fletas prasidejo renkam duomenis i masyva zvakiu HL ir OC skaiciavimui
            
            avgPriceH[i] = High[1];    
            avgPriceL[i] = Low[1];     
            avgPriceO[i] = Open[1];   
            avgPriceC[i] = Close[1];
         
            j++; 
            
            ArrayResize(chPriceC,i); 
            ArrayResize(chTime,i);    
           } 
         for(int a=0; a<=i; a++)Print("avgPriceC["+a+"]="+avgPriceC[a]);
         for(int b=0; b<=j; b++)Print("chPriceC["+b+"]="+chPriceC[b]);
         for(int c=0; c<=j; c++)Print("chTime["+c+"]="+chTime[c]);
        }        
     }
  }
    
  return(0);
}
 
gince:


In the KIM example also


no, there is no global declaration, each function has its own y[].


As for your code and zeros, let me explain with an example.

If int a[],n=5; ArrayResize(a,n), then the last array element has an index n-1, not n. You have:

               i++; 
            
            ArrayResize(avgPriceH,i); 
            ArrayResize(avgPriceL,i);
            ArrayResize(avgPriceO,i); 
            ArrayResize(avgPriceC,i);        
            
            avgPriceH[i] = High[1];    
            avgPriceL[i] = Low[1];     
            avgPriceO[i] = Open[1];   
            avgPriceC[i] = Close[1];

Obviously, it's outside the array's boundaries. Hence, there are zero values. The correct way is

            avgPriceH[i-1] = High[1];    
            avgPriceL[i-1] = Low[1];     
            avgPriceO[i-1] = Open[1];   
            avgPriceC[i-1] = Close[1];
 
tara:
Not the same at all, but very different. Read global and local data.
I'm sorry I missed it. CMM has a local variable.
 


tara and alsu





Thank you very much.

 

Good afternoon, I need help with this question: there is an array Mas[10]. I need to find the product of each cell with each cell. I made such a construct, where operator if(i==j) eliminates the product of the cell itself. The problem is, I get double math, i.e. for example for i=1 and j=2 the result will be the same as for i=2 and j=1. What additional condition should be written to prevent double calculations?

for(i=0; i<10; i++)
{
   for(j=0; j<10; j++)
   {
      if(i==j) continue;
      x = Mas[i]*Mas[j];
   }
}
 
for(i=0; i<10; i++)
{
   for(j=i+1; j<10; j++)
   {
      //if(i==j) continue;
      x = Mas[i]*Mas[j];
   }
}
 
Roger:
Thank you.
 

Hi all!

I am not familiar with MQL4 coding. I want to try to write a good Expert Advisor based on support and resistance levels, but I don't know how to write code and program to look for support and resistance levels. I am not able to search for it in code base, I am clumsy and my time is limited.

Thanks in advance! May profits come to you, and may elks go around!)

 
Roger:
For a number of reasons related to the process of writing to the array, we had to make it two-dimensional, i.e. now the array looks like Mas[2][5]. Now, to solve the same problem, instead of two for loops, we have to make four loops. In this case, the variant suggested by Roger will not work. How to solve this problem when using a two-dimensional array?
 
Ekburg:

Hi all!

I am not familiar with MQL4 coding. I want to try to write an EA based on support and resistance levels, but I don't know how to write code for a program that will look for these levels. I am not able to search for it in code base, I am clumsy and my time is limited.

Thanks in advance! May profits come to you, and may elks go around!)


Look at the indicator in CodeBase DailyPivotPoints! I think it will help you! Good Luck!
Reason: