Errors, bugs, questions - page 2016

 
fxsaber:

The entire CopyBuffer is INF there.

With a sliding counting algorithm, just two DBL_MAX prices are enough at the beginning to make the entire buffer become INF

DBL_MAX + DBL_MAX = INF

and then INF will not leave the calculation

You should change the code of all indicators to ignore EMPTY_VALUE
 
A100:

With a sliding counting algorithm, only two DBL_MAX prices are needed at the beginning to make the entire buffer become INF

DBL_MAX + DBL_MAX = INF

and then INF will no longer escape from the calculations

This variant is quite probable because it is DBL_MAX that is filled with values below the MAA period. Then there is a bug in the recurrent algorithm average - MODE_SMA.

It is so! I made some changes and it works!

// Вычисляем Машку от Машки через хэндл самого себя
#property indicator_separate_window 
#property indicator_buffers 1 
#property indicator_plots   1 

#property  indicator_type1   DRAW_LINE 
#property  indicator_color1  clrRed 
#property  indicator_style1  STYLE_SOLID 
#property  indicator_width1  1 

input bool CustomData = false; // true - кастомный режим для iCustom
input int MAPeriod = 1 e1;      // Период МАшки

string GetMyName( void )
{
  const int Length = StringLen(TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL5\\Indicators\\");
  const string Path = MQLInfoString(MQL_PROGRAM_PATH);
  
  return(StringSubstr(Path, Length, StringLen(Path) - Length - 4));
}

double Buffer[];
const bool Init = SetIndexBuffer(0, Buffer, INDICATOR_DATA);

const int handleMA = CustomData ? iMA(NULL, PERIOD_CURRENT, 100, 0, MODE_SMA, PRICE_OPEN) // от этой МАшки будет брать другую Машку, но не напрямую, а кастомно
                                : iMA(NULL, PERIOD_CURRENT, MAPeriod, 0, MODE_SMA, iCustom(_Symbol, PERIOD_CURRENT, GetMyName(), true));

int Replace( double &Array[], const double NewValue = 1 e3, const double PrevValue = EMPTY_VALUE )
{
  for (int i = ArraySize(Array) - 1; i >= 0; i--)
    if (Array[i] == PrevValue)
      Array[i] = NewValue;
      
  return(0);
}

int OnCalculate( const int rates_total,      // размер входных таймсерий 
                 const int prev_calculated,  // обработано баров на предыдущем вызове
                 const datetime& time[],     // Time 
                 const double& open[],       // Open 
                 const double& high[],       // High 
                 const double& low[],        // Low 
                 const double& close[],      // Close 
                 const long& tick_volume[],  // Tick Volume 
                 const long& volume[],       // Real Volume 
                 const int& spread[] )       // Spread 
{
  return(prev_calculated + CopyBuffer(handleMA, 0, prev_calculated, rates_total - prev_calculated, Buffer) + Replace(Buffer));
}

One can state for sure that the recurrent algorithm iMA does not take into account the case when DBL_MAX is fed to the input. Bug.


@A100, Thanks!

 

MetaEditor hangs when trying to compile an attached file

If it does not hang right away, wait a while or go to the summary line and see the compilation time

Files:
Test0.mq5  1 kb
 

Why not show the order/transaction number in a pop-up window when hovering with the mouse? Asked for it a thousand years ago, it's so lacking!

 
fxsaber:


return(prev_calculated + CopyBuffer(handleMA, 0, prev_calculated, rates_total - prev_calculated, Buffer) + Replace(Buffer));

Such constructs should be avoided. The order in which the operands are executed is not regulated in C++, so it's up to the individual compiler to decide. The exceptions are the && and || operators, where the operands are always executed left to right.

 
Alexey Navoykov:

Such constructs should be avoided. The order in which the operands are executed in C++ is not regulated, so it's up to the individual compiler to decide. The exceptions are && and || operators, where the operands are always executed left to right.

Well, we are in MQL!

 
fxsaber:

Well, we're in MQL!

Nowhere in the documentation does it say anything specific about any particular order. So they can change it as they see fit at any time.

I've already contacted service-desk once to clarify this issue.

 

Hello. Can you please tell me which functions can be used to get the list of indicators displayed on the chart and their parameters? I only found a function that returns the number of indicators on the chart

Списки наложенных объектов - Дополнительные возможности - Графики котировок, технический и фундаментальный анализ - Справка по MetaTrader 5
Списки наложенных объектов - Дополнительные возможности - Графики котировок, технический и фундаментальный анализ - Справка по MetaTrader 5
  • www.metatrader5.com
У каждого графика можно посмотреть списки наложенных объектов: индикаторов, аналитических объектов и советников. Там же можно можно редактировать их свойства и удалять их с графика. Список индикаторов Индикаторы сгруппированы на наложенные на основное окно графика и на те, что открыты в отдельных окнах. Выберите индикатор и нажмите "Свойства...
 
Aleksandr Teleguz:

Hello. Can you please tell me which functions can be used to get the list of indicators displayed on the chart and their parameters? I only found the function that returns the number of indicators in the chart

IndicatorParameters (+ IndicatorRelease)

Документация по MQL5: Доступ к таймсериям и индикаторам / IndicatorParameters
Документация по MQL5: Доступ к таймсериям и индикаторам / IndicatorParameters
  • www.mql5.com
//| Script program start function                                    |                          +                                    p,                                                                        parameters[p].integer_value,                                    parameters[p].double_value...
 
Alexey Navoykov:

Nowhere in the documentation does it say anything specific about any particular order. So they can change it as they see fit at any time.

I don't bother with that. There's a lot of things that aren't described there.

Off the top of my head

  • Sorting trading history records by time in MT4/5.
  • Possibility to initialize global/static variable by function - appeared relatively recently.
  • Preprocessor directives setting in one line - will be turned off soon, though.
  • Execution of operands from left to right.
  • OrderSend is 99% synchronized with the trading environment.
  • ChartApplyTemplate is asynchronous.
  • And there are a lot of other undocumented subtleties. And then there are cases where the documentation does not correspond to reality. And this is not a bug, but a rare bug that simply isn't mentioned.

The precedent was a casting rejection, but there was a reason there.

So not using something just because it's not described is a questionable decision.


I think such code would not cause programmers' doubts.

int Replace( double &Array[], int );

return(prev_calculated + Replace(Buffer, CopyBuffer(handleMA, 0, prev_calculated, rates_total - prev_calculated, Buffer)));

However, it's not very nice. It makes sense to write MyCopyBuffer but it is ugly to show in a short code that you need it to avoid a bug. So using undocumented operand execution priority is just right to show that this is a temporary solution.

Reason: