Download MetaTrader 5
To add comments, please log in or register
Deposit to your account using bank cards via Gate2Shop
Pierre Rougier
386
Pierre Rougier 2015.03.08 18:25 
Hello,

I rewrote a pivot point indicator in OOP.
At the time of the removal of the indicator I got error messages, how to avoid them?
It seems that if I place the buffers out of the class, I have no more error messages.
I wish I linked buffers and class without error messages, a solution?

If proposals for improvement of the code? 

 

2015.03.08 17:51:05.958 idPivotPoints SILVER,H1: indicator buffer #0 detached
2015.03.08 17:51:05.958 idPivotPoints SILVER,H1: indicator buffer #1 detached
2015.03.08 17:51:05.958 idPivotPoints SILVER,H1: indicator buffer #2 detached
2015.03.08 17:51:05.958 idPivotPoints SILVER,H1: indicator buffer #3 detached
2015.03.08 17:51:05.958 idPivotPoints SILVER,H1: indicator buffer #4 detached
2015.03.08 17:51:05.958 idPivotPoints SILVER,H1: indicator buffer #5 detached
2015.03.08 17:51:05.958 idPivotPoints SILVER,H1: indicator buffer #6 detached
Files:
Ovo Cz
2955
Ovo Cz 2015.03.08 19:45  

I do not consider it as an error, but rather a message, that the buffer has been released before the indicator has been destroyed. It is harmless, but annoying.

The only solution is avoiding premature buffer destruction. When you want the indicator buffer array encapsulation into an object, you have to ensure the wrapping object gets destroyed at the global level.

I have it coded like this, a single object holding all buffer arrays is declared at global level. Its destructor destroys all captured members. It gets destroyed naturally at the end of its validity scope (i.e. after OnDeinit), and destroys the captured buffers without error message.

/**
 *  Global holder for system buffer wrappers.
 *  Will get destroyed automatically by MT4 at program end.
 */
MT4Set allIndicatorBuffers(true);      // <<-- DECLARATION OF INDICATOR BUFFERS HOLDER, DESTROYS ELEMENTS IN DESTRUCTOR



/**
 *  Implementation of MT4DrawingBuffer for use in Indicators
 */
class MT4SystemBuffer : public MT4DrawingBuffer {

   /**
    * Total number of buffers in the script scope. 
    */
   static int bufferCount;

   int bars;

protected:
.......
public:

   /**
    *  Constructor.
    *  @param [in] aLabel Name of the buffer appearing in the Data window. If empty, _ValueN_ is used.
    *  @return 
    */
   MT4SystemBuffer(string aLabel="") : drawType(DRAW_NONE), label(aLabel){      
      index = bufferCount++;      
      allIndicatorBuffers.add(_this);               // <<-- adds self to the global object
      ::IndicatorBuffers(bufferCount);
      ::SetIndexBuffer(index, value);
      if(""==label) label="Value " + IntegerToString(index);
      ::SetIndexLabel(index, label);
   }
Pierre Rougier
386
Pierre Rougier 2015.03.11 11:26  

Hi Ovo,

 Thanks.

/
To add comments, please log in or register