Download MetaTrader 5

Bad handle returned from iCustom

To add comments, please log in or register
Doji Starr
12
Doji Starr  

The following code creates 2 custom indicators using iCustom. Each call passes different parameters and yet the same handle is returned for both calls. Obviously I should have got 2 different handles.

The code prints the different parameter with the returned handle.

int OnStart()
  {
    string units, strUnit[2];
    units = "aaa;bbb";

    strUnit[0] = StringSubstr(units, 0, 3);
    strUnit[1] = StringSubstr(units, 4, 6);
    
    string unit;
    for (int i=0; i<2; i++)
    {
        unit = strUnit[i];
        int m_handle1=iCustom(NULL,0,"iTest",unit);
        Print(unit, " ", m_handle1);
    }

    return(0);
  }

Is this an expected behaviour? How can I force MT to create two different indicators (with two different handle) for different parameters (that are supplied in this format)?

Step on New Rails: Custom Indicators in MQL5
  • 2009.11.23
  • Андрей
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
Slava
Moderator
6961
Slava  
dojistarr:

The following code creates 2 custom indicators using iCustom. Each call passes different parameters and yet the same handle is returned for both calls. Obviously I should have got 2 different handles.

The code prints the different parameter with the returned handle.

Is this an expected behaviour? How can I force MT to create two different indicators (with two different handle) for different parameters (that are supplied in this format)?

 

Thank You, we'll check it asap
Doji Starr
12
Doji Starr  
stringo:
Thank You, we'll check it asap

Here is a more correct snippet

int OnStart()
  {
    string units, strUnit[2];
    units = "aaa;bbb";

//    this produces expected results
//    strUnit[0] = "aaa";
//    strUnit[1] = "bbb";
    
    // this doesn't    
    strUnit[0] = StringSubstr(units, 0, 3);
    strUnit[1] = StringSubstr(units, 4, 6);
    
    string unit;
    int handle;
    for (int i=0; i<2; i++)
    {
        unit = strUnit[i];
        handle = iCustom(NULL,0,"iTest",unit);
        Print(unit, ": ", handle);
    }

    return(0);
  }

 

To add comments, please log in or register