Discussion of article "Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator" - page 2

 
Rosh:

For indicator buffers it says SetIndexBuffer:

For Expert Advisors it should be similar, check

No analogy yet. When checking this code

//+------------------------------------------------------------------+
//|Test002.mq5 |
//+------------------------------------------------------------------+
double high[];
int bars;
//+------------------------------------------------------------------+
//| Expert initialisation function|
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   bars=Bars(Symbol(),PERIOD_CURRENT);
   ArraySetAsSeries(high,true);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialisation function|
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function|
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int copied=CopyHigh(Symbol(),0,0,bars,high);
   return;
  }
//+------------------------------------------------------------------+

I put a breakpoint opposite the return operator. The debugger produces the following result: high "dynamic array[8563], S". I understand that S stands for "Series".

 
Yedelkin:

The analogy doesn't work yet. When checking this code

I put a breakpoint opposite the return operator. The debugger generates the following result: high "dynamic array[8563], S". I understand that S stands for "Series".

So why doesn't it work? If you doubt, set an explicit check for series by the ArrayGetAsSeries function:

//+------------------------------------------------------------------+
//|Test_ArraySetAsSeries.mq5 |
//| Copyright Copyright 2010, MetaQuotes Software Corp. | |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
double high[];
int bars;
//+------------------------------------------------------------------+
//| Expert initialisation function|
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   bars=Bars(Symbol(),PERIOD_CURRENT);
   ArraySetAsSeries(high,true);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function|
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int copied=CopyHigh(Symbol(),0,0,bars,high);
   bool IsSeries=ArrayGetAsSeries(high);
   return;
  }
//+------------------------------------------------------------------+

Result


 
Rosh писал(а) :

Why it doesn't work. If in doubt, set an explicit check for seriality with the ArrayGetAsSeries function:

Let me remind you what I'm talking about. I was asking whether arrays should always be indexed only after they have been copied. You referred to the SetIndexBuffer function note and said that it should be the same for EAs. This SetIndexBuffer function note implies that "after linking, the dynamic array buffer[] will be indexed as in regular arrays, even if the linked array is pre-set to be indexed as in timeseries".

Accordingly, I saw an analogy for EAs in that after using the CopyTime, CopyHigh and CopyLow functions, the receiving arrays will also have to be indexed as in regular arrays. To test this analogy, I placed the ArraySetAsSeries function before the CopyHigh function, in the OnInit() function. But my example and the explicit check for serialisation by the ArrayGetAsSeries function you suggested show that after using the CopyHigh function, the pre-set indexing (as in timeseries) of the receiving array high[] has not changed. This, in turn, indicates that the analogy with the SetIndexBuffer function you mentioned is not observed yet, because otherwise the explicit seriality check should have shown that IsSeries=false.

 

Yedelkin:

To test this analogy, I placed the ArraySetAsSeries function before the CopyHigh function, in the OnInit() function. But my example and the explicit check for serialisation by the ArrayGetAsSeries function you suggested show that after using the CopyHigh function, the pre-set indexing (as in timeseries) of the receiving array high[] has not changed.

Actually, I meant that after setting the serialisation for the global array in OnInit() or some other function, this serialisation will not change anywhere else. The only exception is related to the SetIndexBuffer() function.

I believe that we have come to an agreement on this issue and we can consider it exhausted.

 

Yes, the question has been answered. Thank you for the clarification!

 

A few questions.

1.

   if(CopyTime(Symbol(),0,0,i,t)<i || CopyHigh(Symbol(),0,0,i,h)<i || CopyLow(Symbol(),0,0,i,l)<i)
     {
      Print("Failed to copy the time series!");
      return;
     }

It is said that "In the if... operator, the return operator is used to terminate the OnTick function execution."

Is OnTick? and not from if (....) {...}?

2.

   for(i=0;i<PositionsTotal();i++) {…}

In MQL4 the reverse search was recommended.

for(i= PositionsTotal();i>0;i--) {…}
what is better ?

3. Downloaded the Expert Advisor and indicator (for Opera 10.54 moderators, problems with downloading attached files). All compiled. Started in the tester on M5 selecting the last month.

Log

2010.05.15 13:16:02 Core 1 Disconnected

2010.05.15 13:16:01 Core 1 Log file "D:\MetaTrader 5\Tester\Agent-127.0.0.0.1-3000\logs\20100515.log" written

2010.05.15 13:16:01 Core 1 EURUSD,M5: 553908 ticks (2580 bars) generated within 1431016 ms (total bars in history 100352)

2010.05.15 13:16:01 Core 1 OnTester result 0

2010.05.15 12:52:13 Core 1 EURUSD,Daily: history begins from 2009.01.02 00:00

2010.05.15 12:52:13 Core 1 EURUSD,Daily: history cache reserved for estimated 355 bars

2010.05.15 12:52:13 Core 1 EURUSD: contains 484483 M1 records of beginning data from 2009.01.02 06:01 to 2010.05.03 00:00

2010.05.15 12:52:10 Core 1 Lots=0.100000

2010.05.15 12:52:10 Core 1 MAper=240

2010.05.15 12:52:10 Core 1 EndHour=19

2010.05.15 12:52:10 Core 1 StartHour=7

2010.05.15 12:52:10 Core 1 EURUSD,M5: testing of Experts\expert.ex5 from 2010.05.01 00:00 to 2010.05.14 00:00 started with inputs:

It took a very long time to execute and did not open a single trade. Auto trading is allowed. There are no messages in the log ((( (edit probably I do not know how to find them yet). Indicator and Expert Advisor are located where they should be. Windows XP, MT (build 274).

4. Tried debugging mode, it doesn't work. Probably because of Saturday. No quotes. I made the stop point the same way as in the article. If I am right it is a pity, it turns out that you can debug only on a working day. It would be nice for debugging to be able to upload your own file with the necessary data and (or) with some typical data (let it be a piece of history for a day), it will be enough for debugging.

5. If someone has researched the Copy function... please share information on how it works if there are missing bars. Although it would probably be better to order an article.

 
Prival:

A few questions.

1. It is said that "In the if... operator, the return operator is used to terminate the OnTick function execution."

Is OnTick? and not from if (....) {...}?

From the description of the return operator return:

Оператор return прекращает выполнение текущей функции и возвращает управление 
вызвавшей программе. Результат вычисления выражения возвращается вызываемой 
функции. Выражение может содержать оператор присваивания.

The current function for the return statement in this example is OnTick().

Prival:

4. Tried debug mode, it doesn't go. Probably because of Saturday. No quotes. I made the stop point the same way as in the article. If I am right it is a pity, it turns out that you can debug only on a working day. It would be nice for debugging to be able to upload your own file with the necessary data and (or) with some typical data (let it be a piece of history for a day), it will be enough for debugging.

The site has already discussed similar questions about debugging. If you are interested, use search and search word "Debugging".

 

After loading the automatic update (build 275), the compiler started generating warnings on lines where conditions of the following type are checked

if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
The warnings are of the same type:
implicit enum conversion Perito02-04 temp3.mq5 1233 45
Questions: does the correct operation of the compiler imply the appearance of these warnings in the specified situation? What "conversion" are we talking about?
 
Yedelkin :

After loading the automatic update (build 275), the compiler started generating warnings on lines where conditions of the type are checked

The warnings are of the same type: Questions: does the correct work of the compiler imply the appearance of these warnings in the specified situation? What "conversion" are we talking about?

The warning was introduced to make programmers pay attention and double-check their code.

You can get rid of warnings by explicitly casting the function result to an enumerator or enumerator to int.

 
Prival:

A few questions.

1. It is said that "In the if... operator, the return operator is used to terminate the OnTick function execution."

Is OnTick? and not from if (....) {...}?

If at least one of the conditions in the operator

if(CopyTime(Symbol(),0,0,i,t)<i || CopyHigh(Symbol(),0,0,i,h)<i || CopyLow(Symbol(),0,0,i,l)<i)

at least one of the conditions is fulfilled, i.e. at least one of the arrays could not be copied completely (there is not enough historical data or an error occurred) - the OnTick function is terminated, since further calculations are impossible without this data.

2. in MQL4 the reverse enumeration was recommended.

what is better ?

Variants

for(i=0;i<PositionsTotal();i++)

и

for(i=PositionsTotal()-1;i>=0;i--)

are equivalent, but the first variant is shorter in text form, so it was used.

3. Downloaded the Expert Advisor and indicator (for moderators Opera 10.54 problems with downloading attached files). All compiled. I ran it in the tester on M5, selecting the last month.

It took a very long time to execute and did not open a single trade. Auto trading is allowed. There are no messages in the log ((( (I probably don't know how to find them yet). Indicator and Expert Advisor are located where they should be. Windows XP, MT (build 274).

4. Tried debugging mode, it doesn't go. Probably because of Saturday. No quotes. I made the stop point the same way as in the article. If I am right it is a pity, it turns out that you can debug only on a working day. It would be nice for debugging to be able to upload your own file with the necessary data and (or) with some typical data (let it be a piece of history for a day), it will be enough for debugging.

5. If someone has researched the Copy function... please share information on how it works if there are missing bars. Although it would probably be better to order an article.

To be honest, my tester does not work very well either: testing takes much longer than testing a similar EA in MQL4; trades are opened only in the first one or two days of the testing interval (this is observed when testing different Expert Advisors).

The OnTick and OnCalculate functions are launched when a new quote is received, so for their debugging it is necessary to receive quotes (it will not work on a weekend). Otherwise, the debugger works normally (try it out, ask me if you need anything).

Regarding arrays-timeseries: - the direction of arrays can be changed at any time in both directions, the location of arrays in memory does not change, only the indexing changes (from 0,1,2,...,last to last,...,2,1,0) .