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

 

Why do I have incorrectly copied closing prices from a specified time with a specified quantity. MQL5

copied = CopyClose(_Symbol,PERIOD_H4,Time[59],5,MPI); Alert(copied);
  for(int i = 0; i < 100; i++)
    {
     Alert(MPI[i]);
    };
 
Alexandr Sokolov:

Why do I have incorrectly copied closing prices from a specified time with a specified quantity. MQL5

Where in mql5 did you find Time[] or is it a custom array?

 
Alexey Viktorov:

And where in mql5 did you find Time[] or is it a custom array?

Yes, it is a custom array, into which I copied the opening times of the bars of the timeframe in which the indicator is located. Or how else to specify the date (especially considering that in the future it will have to be combined in several ways)?

 
Alexandr Sokolov:

Yes, it is a custom array, into which I copied the opening times of the bars of the timeframe in which the indicator is located. Or how else to specify the date (especially since in the future it will have to be combined in several ways)?

Yes, there is something wrong with copying "someone else's" TF. I started one indicator for severalfolds and I noticed that CopyRates() is not immediately copied. Apparently, it's because of unprepared data by period. Simply re-compiling it fixes the situation. It turns out that we should "pull" the period first, and then copy. But I haven't got around to it. I will check it tomorrow. But I hope that I am right.

And a puzzle for me: why copy opening times of bars in that timeframe window of which the indicator is located, if time[] can be used instead. And we should not forget about indexing direction.

 
Alexey Viktorov:

And a quick question: why copy the open time of bars in the timeframe window of which the indicator is located, if time[] can be used instead. And do not forget about indexing direction.

Time is used outside OnCalculate. Indexing direction ArraySetAsSeries(...,true) in all buffers


What's it for? - I made a trend indicator (posted in CodeBase), it's "noisy". I made a slowdown - not enough. Now I want to make the values on each candle of the lower timeframe calculated from the bars of the higher timeframe

What do you mean by "yank"?

 
Alexandr Sokolov:

Time is used beyond OnCalculate. Indexing direction ArraySetAsSeries(...,true) in all buffers


What is it for? - I made a trend indicator (posted in CodeBase), it's "noisy". I made a slowdown - not enough. Now I want to make the values on each candle of the lower timeframe calculated from the bars of the higher timeframe

What do you mean by "yank"?

"Yank" is not my expression. That's how I read on this forum the periodic reference to the data of the desired period.

I remember even me being angry that it wasn't working, expressing myself "yanking the period like a cat by its source", but it doesn't work. After many discussions on the problem, I wrapped the copying in a do while loop. If it copied at the first attempt, thank goodness. If it didn't, we give it N tries via an empty for loop for 200-500 iterations, which seems to be enough. We can go wider...

And that indicator, about which I've told a bit earlier, is still at the stage of the very beginning. That's why it's not done properly. I was just checking how many bars of high tf I need for available bars of current period. I ended up with 17 daily bars per 5000 M5 bars. And if you don't take that into account, then 5000 current M5 period, 5000 4h and 5000 daily are copied. Too many extra...

Another important note: some time ago we could reverse an array's indexing once, now we have to redirect it at each sneeze. I've written about this somewhere before. That's why I prefer to work with the default option. It's not hard to get used to it.

 

GlobalVariable by default can only be double

double close = GlobalVariableGet("close");


If I want a close value without a fractional part, would it be correct to write it like this:

int close = GlobalVariableGet("close");
 
Alexey Viktorov:

"Yank" is not my expression. That's how I read the periodic reference to the right period data on this forum.

I remember even me getting angry that it's not working, expressing myself "yanking the period like a cat by its causal place", but it doesn't help. After many discussions on the problem I wrapped copying in a do while loop. If it copied at the first attempt, thank goodness. If it didn't, we give it N tries via an empty for loop for 200-500 iterations, which seems to be enough. We can increase...

And that indicator I mentioned earlier is still in its infancy. That's why it's not done properly. I was just checking how many bars of high tf I need for available bars of current period. I ended up with 17 daily bars per 5000 M5 bars. And if you don't take that into account, then 5000 current M5 period, 5000 4h and 5000 daily are copied. That's a lot of extra...

Another important note: some time ago you could reverse an array's indexing once, now you have to redirect it at each sneeze. I've written about this somewhere before. That's why I prefer to work with the default option. It's not hard to get used to it.

Wait, did we miss something or misunderstand each other, because

Alert(copied);

... ...it returns 5, which is correct, but the values in my buffer are all the same.

 
Alexandr Sokolov:

Wait, did we miss something or misunderstand each other, because

... I return 5, which is correct, but the values in the buffer are all the same

Then we need to figure out the MPI array dimension and its indexing direction, if you copy 5 elements, why cycle to 100?

I prefer to use debugger in such cases. Get an array and check all array fields without restarting...

 
Alexey Viktorov:

Then we need to deal with the MPI array size and indexing direction, if you copy 5 elements, then why the cycle to 100?

I prefer to use the debugger in such cases. Get an array and check all array fields without restarting...

I set it to 100 because I thought it would start at 59, but it's the same at 6.

Reason: