Same Indicator Handle value for different indicators on same chart. Bug?

 
Hi,
should not an indicator handle value be unique for each Indicator on the same chart ?

I have this scenario:
- EA create indi A using iCustom in onInit, and add A to chart using ChartIndicatorAdd(0,0,A)
- indi A, in its onInit, create indi B using iCustom and add B to chart using ChartIndicatorAdd(0,0,B)


First, i noted that A and B have the same indicator handle value, that is 10. Is it expected behaviour?

More, adding B to chart with ChartIndicatorAdd(0,0,B) is not working (B is not added to chart) in Strategy Tester, how can i do it?


Thanks



Documentation on MQL5: ChartIndicatorAdd / Chart Operations
Documentation on MQL5: ChartIndicatorAdd / Chart Operations
  • www.mql5.com
Adds an indicator with the specified handle into a specified chart window. Indicator and chart should be generated on the same symbol and time...
 
antony23:

This is a technical forum. If you want any help, you need to provide all the evidence you can so that moderators and other readers can see what you are on about.

Typical evidence at a minimum is posting of the exact code that you used to come to your conclusions. If your scenario is replicable, then, moderators will forward a bug report onto the devs.

 
antony23:
Hi,
should not an indicator handle value be unique for each Indicator on the same chart ?

I have this scenario:
- EA create indi A using iCustom in onInit, and add A to chart using ChartIndicatorAdd(0,0,A)
- indi A, in its onInit, create indi B using iCustom and add B to chart using ChartIndicatorAdd(0,0,B)


First, i noted that A and B have the same indicator handle value, that is 10. Is it expected behaviour?

Yes. A handle is not unique among all applications.

More, adding B to chart with ChartIndicatorAdd(0,0,B) is not working (B is not added to chart) in Strategy Tester, how can i do it?

Try to use ChartID() instead of 0.

 
Hi, i'm simply asking if it is expected behaviour or not.
 
I make it simpler: are indicators handles values unique for overall chart or each mql program (on the same chart) has its own set of handles? Or maybe each thread (EA thread and Indicator thread) has its own set?

Reading doc i understood chart has its own set, but maybe i misunderstood.


 
antony23 #:
Hi, i'm simply asking if it is expected behaviour or not.
 
I make it simpler: are indicators handles values unique for overall chart or each mql program (on the same chart) has its own set of handles? Or maybe each thread (EA thread and Indicator thread) has its own set?

Reading doc i understood chart has its own set, but maybe i misunderstood.


Already answered.

First, i noted that A and B have the same indicator handle value, that is 10. Is it expected behaviour?

Yes. A handle is not unique among all applications.
 
Alain Verleyen #:

Already answered.

Yes. A handle is not unique among all applications.

Hi Alain, when I posted I haven't seen your answer.

Ok, i understand each mql program has its own set of handles value. So no problem here.

About adding ChartIndicatorAdd, yes, i tried with ChartId() but nothing changes. I found a very old thread having my same problem: https://www.mql5.com/en/forum/98373

I'm trying to do the same stuff in that old thread. So summarizing the problem on TESTER: 

- inside EA, i call iCustom of A, add A to chart using ChartIndicatorAdd. A call B using iCustom, but i can't be able to add B to chart, because chartIndicatorAdd does not work, no error from the function, using ChartID() not help. 

- i also tried changing logic: inside EA i call iCustom of B, then i call iCustom of A, add both to chart using ChartIndicatorAdd, working correctly. But the call of iCustom of B inside A, instead of use already existant instance of B created in EA, create an other instance! So I have two instances of B, having same properties, symb, period etc, and this seems to be a bug. I can figure out that I have two instances of B because I can see in the tester journal double logs.

ChartIndicatorAdd not working with strategy tester ?
ChartIndicatorAdd not working with strategy tester ?
  • 2016.10.20
  • www.mql5.com
Hi, i'm working on custom indicator but when i added ChartIndicatorAdd that doesn't work on strategy tester, but that's work fine on the main MT5 p...
 
antony23 #:

Hi Alain, when I posted I haven't seen your answer.

Ok, i understand each mql program has its own set of handles value. So no problem here.

About adding ChartIndicatorAdd, yes, i tried with ChartId() but nothing changes. I found a very old thread having my same problem: https://www.mql5.com/en/forum/98373

I'm trying to do the same stuff in that old thread. So summarizing the problem on TESTER: 

- inside EA, i call iCustom of A, add A to chart using ChartIndicatorAdd. A call B using iCustom, but i can't be able to add B to chart, because chartIndicatorAdd does not work, no error from the function, using ChartID() not help. 

- i also tried changing logic: inside EA i call iCustom of B, then i call iCustom of A, add both to chart using ChartIndicatorAdd, working correctly. But the call of iCustom of B inside A, instead of use already existant instance of B created in EA, create an other instance! So I have two instances of B, having same properties, symb, period etc, and this seems to be a bug. I can figure out that I have two instances of B because I can see in the tester journal double logs.

If you provide the minimum code to reproduce the issue, I will check.
 

EA

int OnInit()
  {
      int B = iCustom(_Symbol,_Period, "B");
      ChartIndicatorAdd(0,0,B);
  
      int A = iCustom(_Symbol,_Period, "A");
      ChartIndicatorAdd(0,0,A);



   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
  }
  
void OnTick()
  {
  }

A

#property indicator_chart_window

int OnInit()
  {
      int B = iCustom(_Symbol,_Period, "B");

   return(INIT_SUCCEEDED);
  }

int OnCalculate(const int32_t rates_total,
                const int32_t prev_calculated,
                const int32_t begin,
                const double &price[])
  {
   return(rates_total);
  }

B

#property indicator_chart_window

int OnInit()
  {
   return(INIT_SUCCEEDED);
  }

int OnCalculate(const int32_t rates_total,
                const int32_t prev_calculated,
                const int32_t begin,
                const double &price[])
  {
   
      if(prev_calculated<rates_total)
         Print("B ["+GetMicrosecondCount()+"]-> "+prev_calculated+"/"+rates_total);
  
   return(rates_total);
  }


Testing EA in Strategy Tester, you can see double logs from B, i suppose two instances of B was created, and it should not happen.

Weird stuff, testing this simple code, i now also have same (wrong) behavior in terminal chart too...