Questions from a "dummy" - page 63

 
masharov:

The expert advisor uses the indicator on a different timeframe. On tests the EA shows incorrect data from the indicator.

The EA itself works on M5, and the indicator on H4. Indicators which are called on the same timeframe (M5) return the correct values.

Returned values are similar to the indicator values, but are different from the real values which are visible when the indicator is applied to the price chart window.

What is the problem?

Example code of indicator call:

Possible causes:

- the rule of the first 14 bars is not respected: https://www.mql5.com/ru/articles/15 in the indicator;

- the correlation between the current and the preset TF is not complied with (for example the serial number of the bar with the required value of the extremum on another TF will probably be different, than on the preset one, and consequently the high, low, etc. will be entirely different) - all this depends on the specific realization of the indicator; you should clearly understand what exactly needs to be correlated and recalculate by the formula using the ratio of different periods;

- maybe, old indicator values from the previous tick are left in the buffer, and it may be necessary to reinitialize the buffer with empty values: ArrayInitialize(array,EMPTY_VALUE).

Индикатор от индикатора в MQL5
Индикатор от индикатора в MQL5
  • 2010.02.08
  • MetaQuotes Software Corp.
  • www.mql5.com
При написании индикатора, который использует краткую форму вызова функции OnCalculate(), можно упустить то обстоятельство, что индикатор может рассчитываться не только на ценовых данных, но и на данных другого индикатора (встроенного или пользовательского - не имеет значения). Вы хотите улучшить индикатор, чтобы он правильно считался не только на ценовых данных, но и значениях другого индикатора? В этой статье мы по шагам пройдем все необходимые этапы такой модификации и выведем дополнительные полезные правила для правильного написания индикатора.
 
x100intraday:

Possible causes:

- the rule of the first 14 bars is not observed: https://www.mql5.com/ru/articles/15 in the indicator;

- Correlation between the current and the preset TF is not observed (for example the serial number of the bar with the required value of an extremum in another TF must be different, than in the preset one, and consequently the high, low, etc. will be different) - all this depends on the particular implementation of the indicator;

- maybe, old values from the previous tick are left in the indicator, and it may be necessary to reinitialize the buffer with empty values: ArrayInitialize(array,EMPTY_VALUE).

1. the indicator is drawn on all bars on the price chart.

2. Everything is OK here.

3. did not help

 

The reference says that the date/time is allowed to be represented like this:

D'12:00:00'

I assign a value to a variable of datetime type:

 datetime start = D'12:00:00'

A warning pops up on compilation:

Why?

 
Urain:
Because no date is specified, only the time 12:00:00 is specified. The date is spelled with a full stop, not a colon.

The reference says that:

Either the date (year, month, date) or the time (hours, minutes, seconds) or all together can be omitted. The range of values is from 1 January 1970 to 31 December 3000.

Examples:

D'2004.01.01 00:00' // New Year
D'1980.07.19 12:30:27'
D'19.07.1980 12:30:27'
D'19.07.1980 12' //new year d'1980.07.19 12:00:00'
D'01.01.2004' //equivalent D'01.01.2004 00:00:00'
D'12:30:27' //equivalent to D'[compile date] 12:30:27'
D' '//equivalent to D'[compile date] 00:00:00''

...

Or am I misunderstanding this?

 
masharov:

The EA itself runs on M5 and the indicator on H4. The indicators that are called on the same timeframe (M5) return the correct values.

I continue to insist on the second point.

You yourself write that on the same TF the correct values are returned. On different ones, of course, values that are not expected for the current TF will be returned.

masharov:

The returned values are similar to the indicator values, but they are different from the real values that are visible when the indicator is attached to a price chart window.

Similar values are probably not coming from the ceiling, but from one of the TFs not equal to M5. If the current TF is H4, then the values are probably coming from it, while values from M5 are expected. If we resharpen the code from M5 to H4, most probably when finding values on H4 it will be possible to catch correct values exactly for H4 (for other TF they will look incorrect).

If the indicator is able to return the correct values in accordance with one or another TF, but is not able, say, on M5, to display what it does on H4, then what can we expect from the returned values when working together with the Expert Advisor that is not on the same TF?

 
tol64:

The reference says that:

Either the date (year, month, date) or the time (hours, minutes, seconds) or all together can be omitted. The range of values is from 1 January 1970 to 31 December 3000.

Examples:

D'2004.01.01 00:00' // New Year's Eve
D'1980.07.19 12:30:27'
D'19.07.1980 12:30:27'
D'19.07.1980 12' //new year d'1980.07.19 12:00:00'
D'01.01.2004' //equivalent D'01.01.2004 00:00:00'
D'12:30:27' //equivalent to D'[compile date] 12:30:27'
D' '//equivalent to D'[compile date] 00:00:00''

...

Or am I misunderstanding this?

Yes yes, you got it right, I wasn't paying attention in a hurry.

Apparently it was like that originally and then it was cancelled and the certificate was not corrected.

Anyway the question still stands, is this a help inaccuracy or a bug?

 

Urain:

...

Anyway the question still stands, is this a help inaccuracy or a bug?

An example of a script:

void Set_Start_And_End_TradeSession()
{
 datetime start = D'00:45:00';
 datetime array[];
 int s = 0, e = 0, i = 0;
 long chart_ID = ChartID();
 long count_bars = Bars(Symbol(),0);
 
 CopyTime(Symbol(),0,0,(int)count_bars,array);
 
 ArraySetAsSeries(array,true);
 
 for(s = 0; s < count_bars; s++)
   {
    ObjectCreate(chart_ID,"start_date",OBJ_VLINE,0,array[s],0); ChartRedraw();
    Sleep(50);
    if(array[s]==start) { Comment("Ok!!!"); break; }
    if(i==1441) { Comment("Error!!!"); break; }
    i++;
   }
}
That's how it works. I just don't like the warnings after compiling)). Maybe one of the developers can comment.
 
Urain:

Either way the question still stands, is it an inaccuracy in the help or a bug?

Compiler warnings do not yet mean there is an error. Print it out: everything is reflected according to the Help.
 
masharov:

The expert advisor uses the indicator on a different timeframe. On tests the EA shows incorrect data from the indicator.

The EA itself works on M5, and the indicator on H4. Indicators which are called on the same timeframe (M5) return the correct values.

Returned values are similar to the indicator values, but are different from the real values which are visible when the indicator is applied to the price chart window.

What is the problem?

Example code of indicator call:

The AS_SERIES flag cannot be set in multidimensional arrays and in static arrays.

Try

void OnNewBar() // моя функция
{
 double wave[];
 ArraySetAsSeries(wave, true);
 CopyBuffer(W_handle,0,(int)0,2,wave);
 if (wave[1] > 0) Buy(); 
}

or as follows

void OnNewBar() // моя функция
{
 double wave[1];
 if(CopyBuffer(W_handle,0,(int)1,1,wave)<1) return;
 if (wave[0] > 0) Buy(); 
}
 
  string Symb="EURUSD";
  for(i=0;i<OrdersTotal()+PositionsTotal();i++)
     {
      if(Symb==PositionGetSymbol(i)) Orders_Total++;
     }
     Alert(Orders_Total);
Could you please tell me why the alert shows Orders_Total=1, when in fact there is one position and one order, i.e. in theory it should show 2, not 1.
Reason: