problem trying to assign value from one loop to a set of arrays

To add comments, please log in or register
beee
26
beee  

hi all,


i'm mql4 newbeee, this is my first post, trying my best to ask the clearest question.

i've got some problem trying to assign value from one loop to a set of arrays  

from zigzag indicator, at certain point it gives out various high and low bars along the way

i'm trying to store some of those H/L for further processing but somehow i couldn't figure out the way to assign those 

bars' value, eg. bar number and its corresponding value into another set of arrays i declare separately 

in the partial code, this loop start finding High bars and their values eg. currentHigh, previousHigh and i as its bar position.

which i want to store in my array called Hbarnum[n] and Hbarval[n]

by incrementing 'n' along with the main loop but after many possible placements of the assigning code and n++ at various positions 

in the code that i can think of, i still couldn't get those values into my arrays, please help


thank you

beee 

void Highbar (int shift)
{
   string status = "";
   double currentHigh = HighMapBuffer[shift];
   double previousHigh;

// int Hbarnum[10];
// double Hbarval10];
// int n = 0;
// these are arrays i've setup to store previoushigh of each bar 
// where n is the starting of the index in both arrays 



   for (int i=shift+1; i<shift+1000; i++)
   {
      if (HighMapBuffer[i] != 0 && ZigzagBuffer[i] != 0)
      {
         previousHigh = HighMapBuffer[i];
// i've tried put it here--- Hbarval[n]=previousHigh;  
         break;   
      }
   }
// and increment n here but not working --- n++;

}

Minions Labs
1702
Minions Labs  

your code is incomplete.

You are mentioning 2 arrays

HighMapBuffer, ZigzagBuffer

that we don`t know where they come from. Are they globals? are they initialized correctly? If you are new to MQL5, take a look at Variables Scope. Maybe this is your problem.


;)

whroeder1
17927
whroeder1  
beee:

i've got some problem trying to assign value from one loop to a set of arrays  

from zigzag indicator, at certain point it gives out various high and low bars along the way

i'm trying to store some of those H/L for further processing but somehow i couldn't figure out the way to assign those bars' value, eg. bar number and its corresponding value into another set of arrays i declare separately 

in the partial code, this loop start finding High bars and their values eg. currentHigh, previousHigh and i as its bar position. which i want to store in my array called Hbarnum[n] and Hbarval[n]

  1.    double previousHigh;
    variable has no initial value.

  2. Don't use a set of arrays. Keep the data together in an array of a struct.
    struct Hbar{ int num; double val; }
    Hbar hBar[...]
    :
    hBar[i].num=n; hBar[i].val=previousHigh;
  3. "certain point" "some of those". Until you can state your want with concrete terms, it can not be coded.

  4.  if (HighMapBuffer[i] != 0 && ZigzagBuffer[i] != 0)
    You appear to be trying to get values out of ZigzagBuffer, therefor the HighMapBuffer test is irrelevant, just store them. Assuming you want the last n higher fractals, you need, counter and the shift
    double hh=0;
    int    count=0;
       for (int i=shift+1; i<shift+1000; i++)
       {
         if (ZigzagBuffer[i] > hh)
          {
             hh = ZigzagBuffer[i];
             hBar[count].num=i; hBar[count].val=hh;
             ++count;
          }
       }
    

Lorentzos Roussos
24073
Lorentzos Roussos  
I'm guessing you are trying to create a "Map" of where the highs are and where the lows are for future fast access.

Provided you are starting the scan from right to left , keep a value of the previous found point (high or low,bar value) and when you find a high or low 
with the zigzag then pass the point of the current high/low (bar value) into your storing array.
The HighsMap and the LowsMap must be a series array just like OHLC arrays so that HighsMap[0] corresponds to bar 0.
Now since data is always coming into the chart , the Map must be constructed as a distance from the next high/low (hence the right to left scan)
beee
26
beee  
whroeder1:
  1. variable has no initial value.

  2. Don't use a set of arrays. Keep the data together in an array of a struct.
  3. "certain point" "some of those". Until you can state your want with concrete terms, it can not be coded.

  4. You appear to be trying to get values out of ZigzagBuffer, therefor the HighMapBuffer test is irrelevant, just store them. Assuming you want the last n higher fractals, you need, counter and the shift

thank you very much for your guidance,

however, i've got error msg after inserting your suggestion 

if i need to learn more about struct, please let me know otherwise what did i do wrong?

struct hBar{int num; double val;};
double hh=0;
int    count=0;
   for (int a=shift+1; a<shift+1000; a++)
   {
     if (ZigzagBuffer[a] > hh)
      {
         hh = ZigzagBuffer[a];
         hBar[count].num=a; hBar[count].val=hh; 

//got this error msg for the above line---------> '[' - name expected for both hBar[count].num and hBar[count].val

         ++count;
      }
   }


whroeder1
17927
whroeder1  
Your code My post #2.2
struct hBar{int num; double val;};
:
:
hBar[count].num=a; hBar[count].val=hh;
struct Hbar{ int num; double val; }
Hbar hBar[...]
:
hBar[i].num=n; hBar[i].val=previousHigh;
beee
26
beee  
whroeder1:
Your code My post #2.2

thank you for your patience.

i adjusted your code according to my limited understanding which is incorrect. i might've not fully understood what your meant so i tried various ways in applying what you've suggested. 

the first time i declared struct without ;  and  Hbar hBar[...] without valued index, code compilation failed but passed if i put in ; and value in hBar[10]; 

so here's what i've done to pass the compilation but got the array out of range runtime error msg, which i managed to accidentally solved, read below: 

void DrawHighLabel(int shift)
{
   string status = "";
   double currentHigh = HighMapBuffer[shift];
   double previousHigh;
   int n;
      
struct Hbar{ int num; double val; };         //whroeder1
Hbar hBar[10];                               //whroeder1

   for (int i=shift+1; i<shift+1000; i++)
   {
      if (HighMapBuffer[i] != 0 && ZigzagBuffer[i] != 0)
      {
         previousHigh = HighMapBuffer[i]; 
         hBar[i].num=n; hBar[i].val=previousHigh;     //whroeder1
         Alert ("hBar.num ", n, "hbar.val ", previousHigh);
         break;   
      }
   }
}

i didn't get the array error msg when i changed to hBar[1000], however  hBar[i].num still 0 at every high bar, please advice.

whroeder1
17927
whroeder1  
beee
hBar[i].num=n; 
hBar[i].num still 0 at every high bar, please advice.

What is the value of n? Why are you using i as a store index? Look at my example (#2.4) and what your post (#4) had.

beee
26
beee  
whroeder1:

What is the value of n? Why are you using i as a store index? Look at my example (#2.4) and what your post (#4) had.to

please don't be annoyed, i've no idea, i just tried your 2.2 suggestion first, may be out of "unknown context", to me at least, haha. then i'll probably try your 2.4 later but just wanted to let u know the outcome of my first try on 2.2, make sense?

so, the value of n as per your 2.2 suggestion, i presume that it's the high bar number n. and i just copied your code from 2.2  with i as the index into this 1st trial.

since i'm new to mql4 programming, i haven't learned about struct yet, i don't know really where to put what. at first i thought assigning those high values to a couple of arrays would be sufficient and easy enough, didn't realize it's this complicated, sorry if i'm wasting your time though. i don't know if it'll save you time just coding the whole thing out for me to try or you've already done that in post #2.4, ?? :(

whroeder1
17927
whroeder1  

You're in a nuclear facility and are just poking buttons. You don't know what any button does. Stop pressing buttons.

I gave you code in 2.4 but you change it. You changed count to a shift. You changed a shift to an uninitialized variable. etc.

Don't change code unless you understand what is the problem how to fix it.

You must learn how to code. Stop what your doing.

I have no idea what your trying to do so I can't really help you.

And I'm not going to code it for you. You learn nothing that way.

beee
26
beee  
whroeder1:

You're in a nuclear facility and are just poking buttons. You don't know what any button does. Stop pressing buttons.

I gave you code in 2.4 but you change it. You changed count to a shift. You changed a shift to an uninitialized variable. etc.

Don't change code unless you understand what is the problem how to fix it.

You must learn how to code. Stop what your doing.

I have no idea what your trying to do so I can't really help you.

And I'm not going to code it for you. You learn nothing that way.

totally agree with u there and the last thing i wanted u to do is coding it for me. 

but trying to understand each other povs from chat is extremely challenging, for me at least. it took me hours to get my point across sometimes by ordinary face to face communication with the others, so chatting is out of the question.

if we can talk may be we can understand each other better or if i know what the right question to ask, haha.

as for the reason of changing your variable to some other alphabet is because yours has been used in the main program other than that i just copied your code and inserted them into the program.

anyway, thank for all the time and help u r trying for me, a person like yourself helps the community grows, keep up the good work, i'll figure out some other way to solve my problems, and trying to pay it forward, but not through chat only though, haha,

cheer, beee

12
To add comments, please log in or register