Errors, bugs, questions - page 1679

 
fxsaber:
It would be good to make it private in the descendants too. For better understanding. Not the point, in short.
It should be called in descendants. )
 
Sergei Vladimirov:
It has to be summoned in the descendants. )
The whole point is precisely that you don't have to. See my example.
 
fxsaber:
The whole point is precisely that you don't have to. See my example.
Your example is just different, but the point is the same - the descendant overrides a virtual method of the base class. Okay, well, it's clear to everyone.
 

Error in indicator buffers

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1

class BUFFER
{
public:
  double Buffer[];
  
  BUFFER()
  {
    ::SetIndexBuffer(0, this.Buffer);
  }
};

BUFFER* Buf;

void OnInit()
{
  Buf = new BUFFER;
}

void OnDeinit( const int Reason )
{
  delete(Buf);
}

void Restart()
{
  OnDeinit(REASON_PARAMETERS);
  OnInit();
}

#define  PRINT(A) Print(#A + " = " + (string)A);

int OnCalculate( const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[] )
{
  static bool Flag = false;
  
  if (Flag)
    Restart();
  
  Flag = true;
  
  PRINT(ArraySize(Buf.Buffer));
  
  Buf.Buffer[0] = 0; // array out of range
  
  return(rates_total);
}

Result in log

2016.09.12 17:21:54.851 Test (RTS-9.16,H1)      array out of range in 'Test.mq5' (56,13)
2016.09.12 17:21:54.851 Test (RTS-9.16,H1)      ArraySize(Buf.Buffer) = 0
2016.09.12 17:21:54.828 Test (RTS-9.16,H1)      ArraySize(Buf.Buffer) = 2067

The debugger stubbornly says that Buf.Buffer ALWAYS is dynamic array[0],I. I.e. is an indicator buffer. But of a zero size, as it turns out.

It turns out that the debugger writes more to the log than the release does. The release doesn't report such things

2016.09.12 17:25:08.706 Test (RTS-9.16,M1)      Indicator buffer #0  detached
Is it possible to set the indicator buffer in MT5 only once?
 

Why the complications, if it's not a secret? Well, apart from the interest of research, of course.

Instead of this (which, by the way, is wrong in principle, because reinitialisation may be required during operation, not only at startup):

  static bool Flag = false;
  
  if (Flag)
    Restart();
  
  Flag = true;

Just like this:

if(prev_calculated == 0)
   ArrayInitialize(Buf.Buffer, 0.0);
 
Sergei Vladimirov:

Why the complications, if it's not a secret? Well, apart from the interest of research, of course.

I have cases where a dynamic array, fixed as an indicator buffer, is deleted. Then you have to create a dynamic array again and assign it as an indicator buffer. The debugger shows that it is assigned. But only its size is zero. This is an error.

The problem is old, as it turns out.

Forum on trading, automated trading systems & strategy testing

How to hide "Indicator buffer #x detached" message

Konstantin Ivanov, 2015.02.17 21:18

In my indicator I store arrays-buffers in instances of the object.
When deleting an object in OnDeinit(), a message is displayed for all arrays linked to buffers (SetIndexBuffer()):

"Indicator buffer #x detached"

How to detach an array from a buffer without this message?
Or how to hide this message?

Found the branch http://forum.mql4.com/63975, but the suggested option to save buffers in a global context doesn't work for me.


The option to save buffers in a global context doesn't work for me either. Interestingly, it works in MT4.

 

article A step-by-step guide to writing EAs in MQL5 for beginners There is code:


Isn't it necessary to divide at three digits?

 
Aleksey Rodionov:

article A step-by-step guide to writing EAs in MQL5 for beginners There is code:


Isn't it necessary to divide at three digits?

This is a rudiment left over from EURUSD (5 digits) and USDJPY (3 digits). There is no error, but it is better not to do so, especially for beginners.
 
I need to define a single interface for all inherited classes. It should always have Init method. But Init is like a constructor duplicate, so variants of input parameters cannot be defined ahead of time. How to specify such interface?
 
MK, why not make the following syntax acceptable for imported functions:
#import ...
 int send(SOCKET s, void &buf[], int len, int flags);
 int send(SOCKET s, void &buf, int len, int flags);
#import

Now we have to make ugly things:

#import ...
 int send(SOCKET s, char &buf[], int len, int flags);
 int send(SOCKET s, int &buf, int len, int flags);
 int send(SOCKET s, char &buf, int len, int flags);
 int send(SOCKET s, Cpoint &buf[], int len, int flags);
 ...
#import

I don't suggest it for internal inline functions, but for imported functions it should be safe.

Reason: