First few values of iDEMA buffer is garbage and probably others too

 

Calculating a moving average on price data usually means the first few values of the MA buffer (usually the period), is empty. That makes sense. But on closer inspection I found that the first 8 values of the iDEMA buffer with period of 5 contains a random float value, far removed from the price data:

I initialized the buffer to 0.0 before I called CopyBuffer.

case PCS_DEMA  :c=CopyBuffer(hPreCalcDema,0,0,rates_total,smoothBuffer); break;

My question is is there a way to filter out that data, and other first garbage values from copied buffers? I can't search for empty or 0 values obviously. Using the period of the MA also won't work, as it seems to me that there is no relationship between the period and the amount of values that are unusable.

In other words is there a global solution for all CopyBuffer results on all moving averages? 

Anyone with an idea? Thank you very much.

 
Those garbage values are probably the farthest back in time. Why do you need them at all?
 
Yashar Seyyedin #:
Those garbage values are probably the farthest back in time. Why do you need them at all*

*Sorry I only realised now this is in the wrong section, but thanks for replying.

Actually I don't need them all. I am coding a function to calculate the RSI on any buffer. But smoothing price before rsi calculation brought up this problem.

I suppose I could just ignore the first 200 values or so but that is a cheap trick. There must be a logical way to filter out those first nonsense values.

 
CobusSteyn0105 #:

*Sorry I only realised now this is in the wrong section, but thanks for replying.

Actually I don't need them all. I am coding a function to calculate the RSI on any buffer. But smoothing price before rsi calculation brought up this problem.

I suppose I could just ignore the first 200 values or so but that is a cheap trick. There must be a logical way to filter out those first nonsense values.

I believe the number of garbage values have something to do with the period. Although it might not be a simple formula.
 
This is the EMPTY_VALUE, it is often used to prime plot buffers because it will not be plotted. It is the highest double value that can be expressed, see documentation.

And yes, it has to do with the period. It prevents the buffer won't being plotted before the peroid is full because otherwise that would be real garbage values. 

Be reminded that if you want to calculate the average over the last 8 periods you first need 8 periods.
 
Yashar Seyyedin #:
I believe the number of garbage values have something to do with the period. Although it might not be a simple formula.

Thanks that's what I'm thinking too.

 
Tobias Johannes Zimmer #:
This is the EMPTY_VALUE, it is often used to prime plot buffers because it will not be plotted. It is the highest double value that can be expressed, see documentation.

And yes, it has to do with the period. It prevents the buffer won't being plotted before the peroid is full because otherwise that would be real garbage values. 

Be reminded that if you want to calculate the average over the last 8 periods you first need 8 periods.

Thanks Tobias. I knew I was missing something obvious. Appreciate your help.

 
CobusSteyn0105 #:

Thanks Tobias. I knew I was missing something obvious. Appreciate your help.

You're welcome