Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1898

 
Valeriy Yastremskiy #:

kasher of course, but the same).

Not the same. If we first write a tick and then shift the array, it is shifted 1 bar to the left, along with the rest of the ticks we shifted. But if we shift the array first and then write the value of the tick at the zero index, we first make room for the tick and then write it there. And, as a result, it is not shifted anywhere.

 
Mihail Matkovskij #:

I've said it many times before: you can't do without a cycle!

I think I'm getting it right.


Trying to swap out the fillings, I get an error


 
Vitaly Muzichenko #:

Tried to swap the fill in, I get an error


Strange, why is it like this...? It looks like everything should work, only the ticks will be in their places, not shifted to the left.

P.S. The extra array should still have been added (as I said at the beginning). Otherwise, when a new bar appears, all the ticks will automatically shift to the left, because they are indicator buffers! Or we can track the moment when a new bar appears and shift the buffers, but already to the right.
 
What if you don't move the array, but use it as a circular buffer, remembering the current location of the first element?
 
Mihail Matkovskij #:

Not the same. If we first write a tick and then shift the array, it is shifted 1 bar to the left, along with the rest of the ticks we shifted. But if we shift the array first and then write the value of the tick at the zero index, we first make room for the tick and then write it there. And, as a result, it's not shifted anywhere.

Yes, in my case we should start with the first one, not the zero one.) good point.

SZY, although yes. first you have to shift and then assign null. no matter which way.

SZZY By overwriting the value of zero before the shift, we lose the value of the zero index.

 
JRandomTrader buffer, remembering the current location of the first element?

What is ring buffer in µl

 
Valeriy Yastremskiy #:

Yes, in my case you have to start with the first one, not the zero bar) is a good point.

Why? Zero bar is shifted together with all other bars to the left. And if we shift all the bars except for zero, we will get two equal values by the first and second indexes.

P.S. If we shift data, a free cell must always be overwritten. Otherwise, there will be two identical values in a row.

 
Valeriy Yastremskiy #:

ZZZY overwriting the value of zero before the shift, we lose the value of the zero index.

That's my point exactly!

 
Valeriy Yastremskiy #:

What is a ring buffer in an µl

Something like

static int head=0;
for(i=head,count=0;count<ArraySize(A);i++,count++)
  {
   if(i>=ArraySize(A))i=0;
   DoSomething(A[i]);
  }

or even

static int head=0;
for(i=head,count=0;count<ArraySize(A);count++)
  {
   if(++i>=ArraySize(A))i=0;
   DoSomething(A[i]);
  }
 
JRandomTrader #:

Something like.

or even

index shift in the array in µl. Although it should work. And by the way, weight of the index change cycle (which is a cycle) and assignment cycle should not differ much.

Reason: