Errors, bugs, questions - page 1394

 
Ilya Malev:

OK, here is the code

I'm not really good with indicators, but this line is questionable

return(CopyBuffer(hnd, buf, index, 1, Arr)==1?Arr[0]:EMPTY_VALUE);

Return value

The number of copied array elements or -1 in case of error.

If only 1 element is copied, the function will return its value. If there are no elements or if there are more than 1, the function will return EMPTY_VALUE.

Maybe it would be better?

return(CopyBuffer(hnd, buf, index, 1, Arr)>=1?Arr[0]:EMPTY_VALUE);
 
Ilya Malev:

OK, here's the code

Corrected the line and it seems to be working ))))

buffer2[i]=-MathRand()%5*Point();
 
Vladimir Pastushak:

Corrected the line and it seemed to work ))))

I ended up tweaking it that way myself. But I wonder why they changed the logic (in MT4 the scale was good without multiplication by Point). And why is there no possibility to make buffers without drawing (c DRAW_NONE) have no effect on chart scale.

 
Vladimir Pastushak:

I'm not really good at indicators, but this line is questionable

1. Returned valueNumber of copied array elements or -1 in case of error.

2. If 1 element is copied, the function will return its value

Statements 1 and 2 are in contradiction, don't you think?
 
Ilya Malev:
Statements 1 and 2 are in contradiction don't you think?

No )))

1 It can be from 1 to the limit

2 only if 1 element is copied If 2 or more, it returns EMPTY_VALUE

In the help it says

Return value

Number of copied array elements or -1 in case of error. Under which condition will 1 element be copied ?

 
Ilya Malev:

I ended up tweaking it that way myself. But I wonder why they changed the logic (in MT4 the scale was good without multiplication by Point). And why is there no possibility for the buffers without drawing (c DRAW_NONE) not to affect the chart scale.

You don't go through the whole indicator buffer. Writing

for(int i=rates_total-MathMax(1, prev_calculated); i>=0; i--)

is not correct at all. You have variables rates_total, prev_calculated and indicator offset iStdDev. On the first pass you need to fill in the empty indices:

indicator shift

and then go through the remaining indices of the indicator buffer (to go through means to assign values).

 
Karputov Vladimir:

You do not go through the entire indicator buffer. The entry

is not correct at all. You have variables rates_total, prev_calculated and indicator offset iStdDev. On the first pass you need to fill in the empty indices:

and then go through the remaining indices of the indicator buffer (to go through means to assign values).

In the original version, I had a function that fills everything with zeros of the type

      for(int i=(int)SeriesInfoInteger(Symbol(), Period(), SERIES_BARS_COUNT)-1; i>=0; i--){
         buffer1[i]=0;
         buffer1[i]=0;
      }

This does not matter in this case. If there were empty values, they would be at the beginning of the chart and they would not affect the scale of the window at the very end. This is not the case here, the comrade above has already figured it out.

 
Ilya Malev:

I ended up tweaking it that way myself. But I wonder why they changed the logic (in MT4 the scale was good without multiplication by Point). And why there is no possibility for buffers without drawing (c DRAW_NONE) not to affect the chart scale.

Here's how to try it:

PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
PLOT_EMPTY_VALUE >>>
 
Vladimir Pastushak:

No )))

Under what condition will 1 element be copied ?

Yes )))

int  CopyBuffer(
    int       indicator_handle,     // handle индикатора
    int       buffer_num,           // номер буфера индикатора
    int       start_pos,            // откуда начнем 
    int       count,                // сколько копируем
    double    buffer[]              // массив, куда будут скопированы данные
    );
 
Ilya Malev:

Yes )))

Yes, then your line is correct.
Reason: