# Principal question : how to handle my indicator issue ... (basic)

108
2012.12.09 23:05

Hi Forum ,

maybe someone can help out with this basic question:

In my Indicator I want to calculate the extremest values of each osma intervall ( high an low).

to do so , I loop through the values like this :

for(i=prev_calculated;i<rates_total;i++)
{

if(aktintervall==true && osma[i]>0)
{
if(myposHI[HI].value<osma[i])
{
myposHI[HI].value=osma[i];
myposHI[HI].candlepos=i;
}

}
else if(aktintervall==false && osma[i]<0)
{
if(myposLO[LO].value>osma[i])
{
myposLO[LO].value=osma[i];
myposLO[LO].candlepos=i;
}

}
else
{
aktintervall=!aktintervall;
if(aktintervall==true)
LO++;
else
HI++;
}
if (HI>=100 || LO >=100 ){

return(rates_total);
}
}

as result I have in my mypos array only the highest values.

the question now is, if next tick arrives, I need to copy the whole array to make space at position 0... this seems for me a bit circuitous, is there a way more elegant ?

thanks for help

2184
2012.12.17 12:54
lynckmeister:

Hi Forum ,

maybe someone can help out with this basic question:

In my Indicator I want to calculate the extremest values of each osma intervall ( high an low).

to do so , I loop through the values like this :

...

as result I have in my mypos array only the highest values.

the question now is, if next tick arrives, I need to copy the whole array to make space at position 0... this seems for me a bit circuitous, is there a way more elegant ?

thanks for help

Please use SRC button to post the code

Basically, finding the highest is just comparing current value with the historical value and the future value, and vice versa for finding lowest. If I were you, I will add two buffer, say Highest_OSMA and Lowest_OSMA and write the code something like this :

``` int limit ;
double prev, current, next;

if (prev_calculated == 0)
limit = 1;
else
limit = prev_calculated -1

for(int i = prev_calculated -1; i < rates_total; i++)
{

current = osma[i];
prev    = osma[i-1];

if (i >= rates_total)
next = osma [i];
else
next = osma [i + 1];

if (current > 0 && current >= prev && current > next)
Highest_OSMA [i] = current;
else
Highest_OSMA [i] = 0.0;

if (current < 0 && current <= prev && current < next)
Lowest_OSMA [i] = current;
else
Lowest_OSMA [i] = 0.0;
}```