Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1308

 
Hi!!! Can you tell me how to pass enum data type to class methods? Let's say I want to pass a timeframe. I create an enum in the header of an advisor
   enum frame1 // перечисление именованных констант
     {
      PERIOD_M1,
      PERIOD_M5,
      PERIOD_M15,
      PERIOD_M30,
      PERIOD_H1,
      PERIOD_H4,
      PERIOD_D1,
      PERIOD_W1,
      PERIOD_MN1
     };


Then I declare a method in a class.
public:
                     Signal_Line();
                    ~Signal_Line();
   double               Time_Frame(double &Trend_Line_Down[][], int Frame, int Down);

   int               Short_Proboy(double &Trend_Line_Down[][], string Name_Static, int Down, ENUM_TIMEFRAMES);
And when calling a method from an EA, if I need to pass the third value from the enumeration - frame - PERIOD_M30, what should I write in the code questions below?
         Trend_Line_Down[Timer_Down][1]=Signal.Short_Proboy(Trend_Line_Down, Name_Static, ???);     // Флаг пробоя трендовой нулевой свечой
 
If you think about it, it's kind of tempting to write
 Trend_Line_Down[Timer_Down][1]=Signal.Short_Proboy(Trend_Line_Down, Name_Static, frame1 3);     // Флаг пробоя трендовой нулевой свечой

But it writes an error when compiling. What might be the catch?

 
Kira27:
Hi!!! Can you tell me how to pass enumeration data type in class methods? Let's say I want to pass a timeframe. I create in the header of EA of enumeration
Then I declare method in class.
And when calling a method from an EA, if I need to pass the third value from the enumeration - frame - PERIOD_M30, what should I write in the code questions below?

Question 1: Why create your own enumeration when you have the standardENUM_TIMEFRAMES

 

A question about the cost of a tick.

For which contract size (lot size) is this value calculated?

For example, for the EURUSD currency pair this script gives the same values, but for metals the difference is 10 times. How, why, and how do I know?

int OnStart()
  {
//---
    // цена тика для символа
    double symb_tick_price = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
    // рассчитаная цена символа (для Forex, CFD - формула из справки)
    // Profit  = (close_price - open_price) * Contract_Size * Lots
    // т.е. берем размер тика и считаем по этой формуле
    // -> TickPrice  = TickSize * Contract_Size * Lots
    double symb_lot_size = 1.0;
    double symb_tick_size = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
    double symb_contract_size = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_CONTRACT_SIZE);
    double calc_symb_tick_price = symb_tick_size * symb_contract_size * symb_lot_size;
    PrintFormat("Цена тика SYMBOL_TRADE_TICK_VALUE=%f, Цена тика ВЫЧИСЛЕННАЯ=%f", symb_tick_price, calc_symb_tick_price);
//---
   return(INIT_SUCCEEDED);
  }


NG      0       13:31:42.450    testTickPrice (EURUSD,H1)       Цена тика SYMBOL_TRADE_TICK_VALUE=1.000000, Цена тика ВЫЧИСЛЕННАЯ=1.000000
OE      0       13:31:56.924    testTickPrice (XAGUSD,H1)       Цена тика SYMBOL_TRADE_TICK_VALUE=0.500000, Цена тика ВЫЧИСЛЕННАЯ=5.000000
CE      0       13:40:00.848    testTickPrice (XAUUSD,H1)       Цена тика SYMBOL_TRADE_TICK_VALUE=0.100000, Цена тика ВЫЧИСЛЕННАЯ=1.000000
 
Kira27:
If you think about it, it seems to be asking to write

But it gives an error when compiling. What could be the catch?

If you do this enumeration

enum frame1 // перечисление именованных констант
 {
  m1  = PERIOD_M1,
  m5  = PERIOD_M5,
  m15 = PERIOD_M15,
  m30 = PERIOD_M30,
  h1  = PERIOD_H1,
  h4  = PERIOD_H4,
  d1  = PERIOD_D1,
  W1  = PERIOD_W1,
  MN1 = PERIOD_MN1
 };

then you could try writing it like this

 Trend_Line_Down[Timer_Down][1]=Signal.Short_Proboy(Trend_Line_Down, Name_Static, (ENUM_TIMEFRAMES)m30);     // Флаг пробоя трендовой нулевой свечой
 
Alexey Viktorov:

If you do this enumeration

you could try writing it like this

... and then in a month you'll be trying to understand what it means ))))

If you must write such a code, at least write it in int

enum frame1 // перечисление именованных констант
 {
  m1  = (int)PERIOD_M1,
  m5  = (int)PERIOD_M5,
  m15 = (int)PERIOD_M15,
  m30 = (int)PERIOD_M30,
  h1  = (int)PERIOD_H1,
  h4  = (int)PERIOD_H4,
  d1  = (int)PERIOD_D1,
  W1  = (int)PERIOD_W1,
  MN1 = (int)PERIOD_MN1
 };

so you can at least understand what the author gets in output

...Although it's a perversion ))))

 
Igor Makanu:

... and then a month later you'll be trying to understand what it means ))))

If you're going to write such a code, at least write it in int

so you can at least understand what the author gets in output

...Although it's a perversion ))))

Why convert it to int? Because in mql5, starting from H1, the enumeration value is not equal to the number of minutes. And on the contrary, I think it will cause a lot of confusion.

 
Alexey Viktorov:

Why convert to int? Because in mql5, starting from H1, the enumeration value is not equal to the number of minutes. And in my opinion, on the contrary, it will cause a lot of confusion.

Because enum is a named 4-byte constant = int

not the number of minutes

 
Vladimir Karputov:

Question 1: Why create your own enumeration if there is standardENUM_TIMEFRAMES

Answer)) Drawing a graphical object in the name of the object there is a substring M30 saying where this object was created, and when writing the object data to array double, using the division of the name into substrings, I compare the 0-index of the array with a broken name, by brute force enumeration with an array

//____________________string Массив таймфреймов______________________________
   NameFrame_Trend_Line[1]="M1";
   NameFrame_Trend_Line[2]="M5";
   NameFrame_Trend_Line[3]="M15";
   NameFrame_Trend_Line[4]="M30";
   NameFrame_Trend_Line[5]="H1";
   NameFrame_Trend_Line[6]="H4";
   NameFrame_Trend_Line[7]="Daily";
   NameFrame_Trend_Line[8]="Weekly";
   NameFrame_Trend_Line[9]="Monthly"; 

Finding the index of the equal string in the array

NameFrame_Trend_Line

associate the index with the int array

//___________________int Массив таймфреймов__________________________________________
   TimeFrame[1]=1;
   TimeFrame[2]=5;
   TimeFrame[3]=15;
   TimeFrame[4]=30;
   TimeFrame[5]=60;
   TimeFrame[6]=240;
   TimeFrame[7]=1440;
   TimeFrame[8]=10080;
   TimeFrame[9]=43200;

obtained, I write the value in the array double, storing characteristics of graph objects. Then, to track the breakdown, fixing and test line, I use a method, in which I should pass the timeframe parameter from the written double array; because lines are created on different timeframes, the breakdown calculation, fixing, test should be calculated according to the timeframe of objects created, regardless of what period is on the chart at the moment. I planned to associate the value of the array

TimeFrame

written to the array of features of graphical objects to be pulled from the array by the index

   enum frame1 // перечисление именованных констант
     {
      PERIOD_M1,
      PERIOD_M5,
      PERIOD_M15,
      PERIOD_M30,
      PERIOD_H1,
      PERIOD_H4,
      PERIOD_D1,
      PERIOD_W1,
      PERIOD_MN1
     };
and transfer to the breakdown, anchoring and test calculation method.
 
Igor Makanu:

because enum is a named 4-byte constant = int

not the number of minutes.

So? Do they have something different in the ENUM_TIMEFRAMES enum? Or is there a fear of running out of memory? I don't know how to mess around like that...


ps; Ah, how slow I am typing...)))) While I was typing a single line Kira27 typed a lot of......... And something I suspect this will be used in mql4.

Reason: