Questions from Beginners MQL5 MT5 MetaTrader 5 - page 866

 
Aleksey Vyazmikin:

OK, moving on to visualisation of thoughts :)

White shows where we are making the request, yellow the bar time we should get.

Is this clearer? If not, please ask questions to clarify.

Alexey, in the post above you made a request for a REVEAL task...

"I need the date of the last bar of the current timeframe, which refers to the selected bar of the upper timeframe.

Is that clear?"

So it's hard to understand what you really need.

On the previous request - I answered - https://www.mql5.com/ru/forum/6343/page869#comment_7537714.

If on the last one "with visualisation of thoughts", then just ask for the opening time of the bar of the upper TF with a shift of 0.

Not quite clear - what is the problem?

Вопросы от начинающих MQL5 MT5 MetaTrader 5
Вопросы от начинающих MQL5 MT5 MetaTrader 5
  • 2018.05.23
  • www.mql5.com
Подскажите пожалуйста, такой показатель тестера в жизни реален? И хороший это или плохой результат за год с депо 3000...
 
Kirill Belousov:

Alexey, in the post above you made a request for a REVERSE task...

"I need the date of the last bar of the current timeframe, which refers to the selected bar of the upper timeframe.

Is that clear?"

So it's hard to understand what you really need.

On the previous request - I answered - https://www.mql5.com/ru/forum/6343/page869#comment_7537714.

If on the last one "with visualisation of thoughts", then just ask for the opening time of the bar of the upper TF with a shift of 0.

Not quite clear - what's the problem?

Sorry, missed your reply.

Kirill Belousov:

If I understood your request correctly, then:

1. determine the closing time of the required bar of the upper TF.

That's what I can't do!

Kirill Belousov:

If by the latter "with visualization of thoughts", then simply request the open time of the bar of the upper TF with an offset of 0.

I am not quite clear - what is the problem?

If I request it that way, I get 10:00 and I need to get the time 23:49!

 
Aleksey Vyazmikin:

OK, moving on to visualisation of thoughts :)

White shows where we are making the request, yellow the bar time we should get.

Is this clearer? If not, please ask questions to clarify.

Question:

At 10:30 we should get the number of bar of period H1 with the time 23:45 on the M5 chart

Did I get it right?

 
Alexey Viktorov:

Question:

At 10:30 I need to get the H1 period bar number with a time of 23:45 on the M5 chart

Did I get it right?

I need to get the time 23:45 in this case (in fact I have not M5, but M1 of the current TF, but it does not matter) - it is the time of the last bar of the current TF in the structure of the last bar of the TF above. The shift on the chart is 1 bar for H1, but there may be another shift, let's say I need information at 11 o'clock, i.e. the shift will be 2.

 
Aleksey Vyazmikin:

Sorry, missed your reply.

That's what I can't do!

If I request that, I get 10:00 and I need to get a time of 23:49!

1. define the shift (bar) you want for the high TF. - The time between the opening and closing of this bar (as far as I understand) you are analyzing for bars from the lower TF within it.

2. Obtain its opening time

3. Add the duration of the TF in seconds for this TF to the opening time. - i.e. this is how you will get the closing time of the bar of the major TF.

4. subtract the duration of the junior TF (if M1, then 60 seconds) - this is the opening time of the last bar of the junior TF in the structure of the senior TF. Find the shift of this bar based on the calculated time. (You can simply subtract 2-3 seconds from the time of the closure of the bar of the major TF and find the bar of the junior TF to which this time refers). If the query is NOT strict, just get the closest available bar on the left (from the requested time), if suddenly the last bar on the junior TF is absent.

 
Kirill Belousov:

1. determine the shift (bar) you need for the higher TF. - The time between the opening and closing of this bar (as I understand you) you are analysing for bars from the lower TF within it.

2. Obtain its opening time

3. Add the duration of the TF in seconds for this TF to the opening time. - i.e. this is how you will get the closing time of the bar of the major TF.

4. subtract the duration of the junior TF (if M1, then 60 seconds) - this is the opening time of the last bar of the junior TF in the structure of the senior TF. Find the shift of this bar based on the calculated time. (You can simply subtract 2-3 seconds from the time of the closure of the bar of the major TF and find the bar of the junior TF to which this time refers). If the request is not strict, then just get the nearest available bar to the left (from the requested time), in case the last bar on the youngest timeframe is absent.

You won't believe it, but an hour ago I wrote a similar algorithm on paper! But it's a bit of a pain, I thought there was a simpler way.

Only point 4 may not work, my check is on the contrary - if the situation is not standard, I have to cycle the time until the bar goes out of the range.

 
Comments not related to this topic have been moved to "Questions from MQL4 MT4 MetaTrader 4 beginners".
 

I want to declare an array of structures - no problems until I saw somewhere that a structure can have a constructor...

How do I declare an array of structures with a constructor? (I know how to get rid of this constructor)

it works:

struct MyStruct
  {
   int               arr[];
   int               size;
                     MyStruct(int sz){ if(ArrayResize(arr,sz)>0) size=sz; else Print(__FUNCTION__,"Ошибка инициализации массива"); }
                    ~MyStruct(){ ArrayFree(arr); size = -1; }
  };
//+------------------------------------------------------------------+
MyStruct cluster(100);

doesn't work, but I want it to:

struct MyStruct
  {
   int               arr[];
   int               size;
                     MyStruct(int sz){ if(ArrayResize(arr,sz)>0) size=sz; else Print(__FUNCTION__,"Ошибка инициализации массива"); }
                    ~MyStruct(){ ArrayFree(arr); size = -1; }
  };
//+------------------------------------------------------------------+
MyStruct cluster(100)[47];
 

A bad solution. It is better to use classes instead of struct. It's the same, but you can work with pointers.

class MyClass : 
  {
   public:
   int               arr[];
   int               size;
                     MyStruct(int sz){ if(ArrayResize(arr,sz)>0) size=sz; else Print(__FUNCTION__,"Ошибка инициализации массива"); }
                    ~MyStruct(){ ArrayFree(arr); size = -1; } // этого не надо
  };
//+------------------------------------------------------------------+
MyClass * cluster[47];

for(int n = 0; n < 47; n++)
        cluster[n] = new MyClass;

I wrote it in my browser, I don't think I messed up. I ran out for an hour.

 
I know, I know that putting variables in public is uncomfortable, but I don't have the time.