Value Captures in a Dynamic Array

 

Hi All, I have the following code on my editor. My questions are written in RED. I debug my program on a EURUSD M30 chart. Appreciate if anyone can provide me the answers.

-------------------------------------------------------

void OnStart()
  {
  // the highest bar since market open
 
  double   high_price [];
  datetime time_period_d1 []; <- Initial value in Add Watch is Dynamic Array [0]. 
  datetime d2=D'17.01.2013 00:00:00';
  int      highest_bar, copied_high;
 
  //--- what time market is open
  if (CopyTime (_Symbol, PERIOD_M30 <- Why this has no value?, d2, 1, time_period_d1<- Why i do not need to write it as time_period_d1[]? Also why the value on Add Watch has now become Dynamic Array [1]?  ) > 0)  //--- when the market open
    {
    MessageBox("1. market open at ", TimeToString (time_period_d1[0] <- Why must this be time_period_d1[0] instead of time_period_d1[1]? I get an error message for changing it to time_period_d1[1],TIME_DATE|TIME_SECONDS)); 

------------------------------------------------------- 

Also, i notice the output on the MessageBox is 17012013 00:00:00. I was wondering how  time_period_d1[0] captures that value when nothing is declared on  time_period_d1[0].

Cheers 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Input/Output Constants / MessageBox
Documentation on MQL5: Standard Constants, Enumerations and Structures / Input/Output Constants / MessageBox
  • www.mql5.com
Standard Constants, Enumerations and Structures / Input/Output Constants / MessageBox - Documentation on MQL5
 
amkey:

Hi All, I have the following code on my editor. My questions are written in RED. I debug my program on a EURUSD M30 chart. Appreciate if anyone can provide me the answers.

-------------------------------------------------------

void OnStart()
  {
  // the highest bar since market open
 
  double   high_price [];
  datetime time_period_d1 []; <- Initial value in Add Watch is Dynamic Array [0]. 
  datetime d2=D'17.01.2013 00:00:00';
  int      highest_bar, copied_high;
 
  //--- what time market is open
  if (CopyTime (_Symbol, PERIOD_M30 <- Why this has no value?, d2, 1, time_period_d1<- Why i do not need to write it as time_period_d1[]? Also why the value on Add Watch has now become Dynamic Array [1]?  ) > 0)  //--- when the market open
    {
    MessageBox("1. market open at ", TimeToString (time_period_d1[0] <- Why must this be time_period_d1[0] instead of time_period_d1[1]? I get an error message for changing it to time_period_d1[1],TIME_DATE|TIME_SECONDS)); 

------------------------------------------------------- 

Also, i notice the output on the MessageBox is 17012013 00:00:00. I was wondering how  time_period_d1[0] captures that value when nothing is declared on  time_period_d1[0].

Cheers 

1. You've been told in here to use SRC button to post your code

 

2. You need to learn a lot, and that mean, first and all, if you don't understand something, read mql5 reference a lot, before asking any question. Just open MetaEdtor 5, click help menu and select MQL5 reference.

3. "<- Why this has no value?," Use your mql5 reference and search for PERIOD_M30, and you will find chart timeframe . That's why it has no value.

4. "<- Why i do not need to write it as time_period_d1[]? ", Because if you do, you have to specify the index number which also causing an error, because that is for the output to array, and so some number of element of array will be filled. See also pass by reference.

5. "<- Why must this be time_period_d1[0] instead of time_period_d1[1]? " Read the mql5 reference for CopyTime. The fourth parameter of CopyTime is the number of data to copy. Since the code set that parameter to 1, the code only copy one value to array. If you still don't understand it, array is counted from zero.

In the future, please read the MQL5 reference before asking a question.