Questions from Beginners MQL5 MT5 MetaTrader 5 - page 740

 

I'm just duplicating the question here, no one is answering in the indicators...

I have started studying MQL5. I am not experienced in programming and therefore I have some questions and doubts. Some of them can be solved by myself, by analyzing examples and partly by 'gut feeling', but some aspects are difficult to understand right away. I started to study a simple thing - to have two toollines displayed in the main chart window. I draw the Close for the current and additional (related, the note will follow) instrument for the current timeframe by 1000 bars backwards. The related instrument is the futures of the next series, it is illiquid and always has some gaps in the data, i.e. the number of deals is not as frequent as in the main futures series. The task would seem to be accomplished, but there are errors. I can't say whether smoothing is useful, so I used iMA with period 1, so that if necessary it can be smoothed without rework.

Here are the questions:

1. When compiling, when I copy the iMA buffer to an array, I see a warning "possible loss of data due to type conversion". What is this and why, what type conversion are we talking about? The lines are drawn normally and nothing seems to be missing.

2. after the indicator has worked and the lines of the two instruments appear on the main chart window, I see that they are not synchronized. I.e. the first instrument is normal and corresponds to the candlestick chart of the main window. The second (less liquid) has gaps and therefore it is gradually "squeezed", causing the desynchronization. I need it to be synchronized in time somehow. This is so far beyond my capabilities. I have to see it visually to understand what is missing.

Here is a screenshot of what it looks like. The yellow line is what needs to be synchronized relative to the green line. So that the yellow line, where the gaps in the dates are just "connections" of the previous values to the next, rather than a squeeze with missing dates. The code is in the attachment.

Files:
 
ottenand:

I'm just duplicating the question here, no one is answering in the indicators...

I have started studying MQL5. I am not experienced in programming and therefore I have some questions and doubts. Some of them can be solved by myself, by analyzing examples and partly by 'gut feeling', but some aspects are difficult to understand right away. I started to study a simple thing - to have two toollines displayed in the main chart window. I draw the Close for the current and additional (related, the note will follow) instrument for the current timeframe by 1000 bars backwards. The related instrument is the futures of the next series, it is illiquid and always has some gaps in the data, i.e. the number of deals is not as frequent as in the main futures series. The task would seem to be accomplished, but there are errors. I can't say whether smoothing is useful, so I used iMA with period 1, so that if necessary it can be smoothed without rework.

Here are the questions:

1. When compiling, when I copy the iMA buffer to an array, I see a warning "possible loss of data due to type conversion". What is this and why, what type conversion are we talking about? The lines are drawn normally and nothing seems to be missing.

2. after the indicator has worked and the lines of the two instruments appear on the main chart window, I see that they are not synchronized. I.e. the first instrument is normal and corresponds to the candlestick chart of the main window. The second (less liquid) has gaps and therefore it is gradually "squeezed", causing the desynchronization. I need it to be synchronized in time somehow. This is so far beyond my means. I have to see it visually to understand what is missing.

Here is a screenshot of what it looks like. The yellow line is what needs to be synchronized relative to the green line. So that the yellow line, where the gaps in the dates are just "connections" of the previous values to the next, rather than a squeeze with missing dates. The code is in the attachment.


The indicator handle must have int type. Example see here:CopyBuffer

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


The indicator handle must be of int type. Example see here:CopyBuffer

Right, I missed that point, the compilation error is gone, thanks!

But the main problem at the moment is the timing difference, it is still relevant. Without its solution it will be impossible to perform, for example, mathematical operations between the tools, which I plan to test.

 
ottenand:

Right, I missed that point, the compile-time error is gone, thanks!

But the main problem at the moment, the timing issue, is still relevant. Without solving it, it would be impossible, for example, to perform mathematical operations between instruments, which I plan to test.


If I were you I would start with proper coding - the thing is that your style now is reckless "quadruple" - that is, there are no checks, everything is at random.

Start fixing OnInit():

  1. after getting the handle, you need to check for correctness
  2. if everything is correct, return NOT "0", but "INIT_SUCCEED".
All this is in theiMA example. Only then we can move on.

 
Vladimir Karputov:


If I were you, I'd start by writing the code correctly - the thing is, your style is now a reckless "quaternary" - i.e. no checks, everything at a whim.

Start correcting OnInit():

  1. after getting the handle, you need to check for correctness
  2. if ok, return NOT "0" but "INIT_SUCCEED".
All this is in theiMA example. Only then can you move on.

So who told you, friend, that you can't staple on a five and write beautifully on a four?

It's not about the PLATFORM, it's about the head of the particular scribe...

Professor Preobrazhensky was right when he said that it's not in the toilets, it's in the heads...


 
Vladimir Karputov:


If I were you, I'd start with proper code writing - the thing is that your style is now a reckless "quaternary" - that is, there are no checks, everything is on the off-chance.

Start correcting OnInit():

  1. after getting the handle, you need to check for correctness
  2. if ok, return NOT "0" but "INIT_SUCCEED".
All this is in theiMA example. Only then you can move on.

Well, now I'll know what my style is called) True, I'm starting right from version 5, from scratch)

Thanks, I've corrected points 1 and 2. The whole snag is in the calculation block. I will think how to prescribe the location of bars of two instruments in accordance with the time. Otherwise there is a lag and the same warning #4806.

Files:
 
ottenand:

Well, now I'll know what my style is called) Really, I'm starting right from version 5, from scratch)

Thanks, I fixed points 1 and 2. The whole snag is in the calculation block. I will think how to prescribe the location of the bars of two instruments according to the time. Otherwise a lag and the same warning #4806.

Right! So, for example, on M1 on the futures "A" there are bars at 13 minutes, 14 minutes and 15 minutes. But futures "B" has bars at 13 minutes and 15 minutes only - i.e. a gap. There were articles somewhere, search for the word "hole".
 
Vladimir Karputov:
That's right! Because, for example, M1 futures "A" has bars at 13 minutes, 14 minutes and 15 minutes. But futures "B" has bars at 13 minutes and 15 minutes only - i.e. a gap. There were articles somewhere, search by the word "hole".
That's what I'm talking about) Error #4806 seems to be the reason why. OK, I'll look for it.)
 

Good afternoon.

Can you please tell me how to find the price of the trend line for the current bar? Tried via ObjectGetDouble, but it doesn't give the desired result. Example code:

   ObjectCreate(0,"O_Resistance",OBJ_TREND,0,UpTime_2[0],UpFractal_2,UpTime_1[0],UpFractal_1);
   ObjectMove(0,"O_Resistance",0,UpTime_2[0],UpFractal_2);
   ObjectMove(0,"O_Resistance",1,UpTime_1[0],UpFractal_1);
   ObjectSetInteger(0,"O_Resistance",OBJPROP_RAY_RIGHT,true);
   ObjectSetInteger(0,"O_Resistance",OBJPROP_COLOR,O_Resistance_Color);
   ObjectSetInteger(0,"O_Resistance",OBJPROP_STYLE,O_Resistance_Style);
   ObjectSetInteger(0,"O_Resistance",OBJPROP_WIDTH,O_Resistance_Width);


double O_ResistancePrice = ObjectGetDouble(0,"O_Resistance",OBJPROP_PRICE,0); // при любом баре дает координату изначальной точки луча, а нужна цена
                                                                              // соответствующая текущему бару или первому
 
MaksGroup:

Good afternoon.

Can you please tell me how to find the price of the trend line for the current bar? Tried via ObjectGetDouble, but it doesn't give the desired result. Example code:

ObjectGetValueByShift() (MT4 only), ObjectGetValueByTime()(MT4, MT5)