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

 
Roman:

Really handy...

Print on different timeframes.

Because the predefined variable _Period outputs the value that:

The _Period variable stores the value of the timeframe of the current chart.

And this timeframe is defined by the value of the constant from the ENUM_TIMEFRAMES enumeration that corresponds to the period of the chart.

Ok, work it out:

//+------------------------------------------------------------------+
//|                                         TestTimeframe_Period.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                             https://mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://mql5.com/ru/users/artmedia70"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   Print
     (
      "Значение предопределённой переменной _Period на графике ",TimeframeDescription(Period())," = ",(string)(int)_Period,"\n",
      "Значение константы перечисления ENUM_TIMEFRAMES ",EnumToString(Period())," = ",(string)(int)Period(),"\n",
      "Период графика, соответствующий константе перечисления ENUM_TIMEFRAMES ",EnumToString(Period()),", со значением ",(string)(int)Period()," = ",TimeframeDescription(Period())
     );
  }
//+------------------------------------------------------------------+
//| Возвращает описание таймфрейма                                   |
//+------------------------------------------------------------------+
string TimeframeDescription(const ENUM_TIMEFRAMES timeframe)
  {
   return StringSubstr(EnumToString((timeframe>PERIOD_CURRENT ? timeframe : (ENUM_TIMEFRAMES)Period())),7);
  }
//+------------------------------------------------------------------+
Документация по MQL5: Предопределенные переменные / _Period
Документация по MQL5: Предопределенные переменные / _Period
  • www.mql5.com
Предопределенные переменные / _Period - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Roman:

I did not use mql4 )) and did not get used to it.
Why do we have to divide by 60 more ???
Where does it say so in the reference?
It's already your crutches that bypass the bug.
Now check your crutch, on all timeframes

A bug? So you think that having timeframes M1, M2, M3, M4, M5, M6, and then M10 is a bug too?

Why don't you ask the developers to eliminate the bugs of missing timeframes

M7, M8, M9, M11, M13, M14, M16, M17, M18, M19, M21, M22, M23, M24, M25, M26, M27, M28, M29, M31 - M59, N1_M1, N1_M2, N1_M3, --- , ---, HUNDRED_YEARS ?

Why is the internal representation of transfer constants suddenly a bug ?

Doesn't the lack of three hundred ruble notes bother you?

 
Artyom Trishkin:

A bug? So you think that having timeframes M1, M2, M3, M4, M5, M6, and then M10 is a bug too?

Why don't you ask the developers to eliminate the bugs of missing timeframes

M7, M8, M9, M11, M13, M14, M16, M17, M18, M19, M21, M22, M23, M24, M25, M26, M27, M28, M29, M31 - M59, N1_M1, N1_M2, N1_M3, --- , ---, HUNDRED_YEARS ?

Why is the internal representation of enum constants suddenly a bug ?

Aren't you bothered by the lack of three hundred ruble notes?

Can you please tell me if the value of 16385 corresponds to the period value of the H1 chart?
And all other period values above H1.
Igor even showed you the binary format, and my next post is the same, but in a different format.

You are going in a completely different direction, don't bring up something you haven't said.
What bothers me is that the moderator muzzles bugs with his crutches!
Not contributing to their elimination.

Here's another bug for you.

Print(PeriodSeconds(PERIOD_MN1)*1000);

And the same thing on the MN graph.

Print(PeriodSeconds(PERIOD_CURRENT)*1000);
 
Roman:

Tell me please, does the value of 16385 correspond to the period value of the H1 chart?
And all other period values above H1.

You're going in a completely different direction, don't bring up something that hasn't been talked about.
What bothers me is that the moderator is washing out bugs with his crutches!
And not contributing to their elimination.
Here's another bug for you.

Don't you have time to study the help?

Anything you don't understand is a bug that you think the developers should fix?

Or maybe you should learn to read in this case, instead of passing the buck to a moderator?

Print((string)(uint)PeriodSeconds(PERIOD_MN1)*1000)

Why are you overflowing the int ?

So print it out for yourself:

Print
  (
   "(int)PeriodSeconds(PERIOD_MN1) = ",(int)PeriodSeconds(PERIOD_MN1),
   ", (ulong)PeriodSeconds(PERIOD_MN1)*1000 = ",(ulong)PeriodSeconds(PERIOD_MN1)*1000,
   ", INT_MAX = ",INT_MAX
  );

and please correct the bug in your own thinking.

And if you want milliseconds, represent them as ulong.

 
Artyom Trishkin:

Don't you have time to study the help?

Anything you don't understand is a bug that you think the developers should fix?

Or maybe you'd better learn to read in this case, instead of passing the buck to a moderator?

Why are you overflowing the int ?

So print it out for yourself:

and please correct the bug in your own thinking.

Overcrowding, yes, that was an oversight, I did not take that into account. Thanks here.
But your example doesn't compile.

As it prints fine, guess when you need a string and when you don't ))

Print((uint)PeriodSeconds(PERIOD_MN1)*1000);


And concerning the _Period variable, there is something wrong there above H1.

 
Roman:

Tell me please, does the value of 16385 correspond to the value of period of H1 chart?
And all other period values above H1.
Igor even showed you the value in binary format, and the next is my post, where you see the same value in another format.

You are going in a completely different direction, don't bring up something you haven't said.
What bothers me is that the moderator muzzles bugs with his crutches!
Not contributing to their elimination.

Here's another bug for you.

And the same on the MN chart.

1. Yes, corresponds to the value of the constant.

2. And all the others correspond to the value of the constant.

Try to print it out.

Print("SYMBOL_BID=",SYMBOL_BID); 

Do you think the current Bid price will be printed out to you, or something else?

Why then do you expect from

Print("PERIOD_H1=",PERIOD_H1);

that you will be given something like H1 or 60 ?

And Igor didn't print it out for me, but showed you the internal representation of constant values of ENUM_TIMEFRAMES enumeration in the binary format.

You claimed that the values of enumeration constants you showed me are a bug and my explanation is a crutch. This is not so - it's just your ignorance of simple basics.

I now take my leave - learn the basics, and please do not show your ignorance in bugs and crutches from developers - it's not good to throw a blank. Yes, and you choose some "tight words", while forgetting that it turns out you do not know something.

You'll figure it out, but your sketch will remain for others who are just as "knowledgeable". It's a pest...

 
Roman:

With overflow, yes, overreacted, did not take this point into account. Thank you.
But your sample will not compile.

But it prints fine, so guess when you need a string and when you don't ))


And concerning the _Period variable, something must be wrong there above H1.

I mean, what do you mean "it doesn't compile"? Copied from forum to script and compiled:


And the _Period variable returns the value of the ENUM_TIMEFRAMES enumeration constant of the current graph as int. That is, not the number of minutes, not the number of seconds, but the value of the constant from ENUM_TIMEFRAMES corresponding to the current graph.

 
Roman:

But it prints all right, so guess when you need a string and when you don't ))

You don't have to guess. You have to think and understand what is being done and for what purpose. When something needs to be written and when it doesn't need to be.

 
Artyom Trishkin:

Why then would you expect

that you are going to get something like H1 or 60 ?

Because the minute timeframes below H1 return the correct values.
As described in the help, they return the value of the timeframe, not a random constant.

Print("PERIOD_M1=",PERIOD_M1);
Print("PERIOD_M5=",PERIOD_M5);
Print("PERIOD_M30=",PERIOD_M30);
Print("PERIOD_H1=",PERIOD_H1);
2020.04.10 03:19:50.600 VP (EPM20,H4)   PERIOD_M1=1
2020.04.10 03:19:50.600 VP (EPM20,H4)   PERIOD_M5=5
2020.04.10 03:19:50.600 VP (EPM20,H4)   PERIOD_M30=30
2020.04.10 03:19:50.600 VP (EPM20,H4)   PERIOD_H1=16385

This is why it is logical to expect this from higher timeframes, continuing the sequence in minutes.
PERIOD_H1=60

etc.

 
Roman:

Because the minute timeframes below H1 return correct values.
As it is described in the help, they return the timeframe value, not the arbitrary constants.

This is why it is logical to expect this from higher timeframes, continuing the sequence in minutes.
PERIOD_H1=60

etc.

... continuing to compose evil songs, expecting communism, trench-branding and *** collecting...

It is logical not to use constant values in expectation of returning expected "logical" values.

Once again (for the last time) let me remind you of the SYMBOL_BID constant. It is "logical" to expect from it the value of the current Bid price instead of 1 for some reason, right? Or is it not?

That's it. I'm tired of the liquorice, and I didn't take up teaching, as it were.

Reason: