OnChartEvent randomly not received by one chart

 

Hi,

I want to broadcast a message to all the open charts. The code is already written and there was no issue, but then I noticed that sometimes one chart's OnChartEvent is not getting triggered. It's always the same. Because I am still developping, only two charts have the OnChartEvent function so far.

I have no idea why one function is seemingly invisible on a whim. id is the same and the functions are located at the same place in each file.

void OnChartEvent(const int id, const long &lparam, const double &dparam,  const string &sparam)
  {
   
   if(id>CHARTEVENT_CUSTOM)
     {
      Alert("Got broadcast message");
      if(id==broadcastEventID)
        {
        // do something
        } 
    }  
 }

I loop through all the open charts from 0 to CHARTS_MAX, so the troubled chart is not missed. Yet, the Alert() is not triggered.

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
  • www.mql5.com
Other Constants - Named Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
dc3463456:

Hi,

I want to broadcast a message to all the open charts. The code is already written and there was no issue, but then I noticed that sometimes one chart's OnChartEvent is not getting triggered. It's always the same. Because I am still developping, only two charts have the OnChartEvent function so far.

I have no idea why one function is seemingly invisible on a whim. id is the same and the functions are located at the same place in each file.

I loop through all the open charts from 0 to CHARTS_MAX, so the troubled chart is not missed. Yet, the Alert() is not triggered.

Why are you using CHARTS_MAX that is a constant?

Which chart is missed, the last one?

Show your code that loops the charts..

 
dc3463456:

Hi,

I want to broadcast a message to all the open charts. The code is already written and there was no issue, but then I noticed that sometimes one chart's OnChartEvent is not getting triggered. It's always the same. Because I am still developping, only two charts have the OnChartEvent function so far.

I have no idea why one function is seemingly invisible on a whim. id is the same and the functions are located at the same place in each file.

I loop through all the open charts from 0 to CHARTS_MAX, so the troubled chart is not missed. Yet, the Alert() is not triggered.

Not enough details...

Use Print() instead of Alert(). Print ChartID and all 4 parameters, maybe include also Symbol and Period.

Then see if multiple sending of event will always be missed by the same chart.

Check your loop that is iterating the charts. Make sure it addresses all currently open charts.

 
Paul Anscombe #:

Why are you using CHARTS_MAX that is a constant?

Which chart is missed, the last one?

Show your code that loops the charts..


CHARTS_MAX = The maximum possible number of simultaneously open charts in the terminal


bad chart id=133315345830123751

good chart id=133315345830123736

int eventID=broadcastEventID-CHARTEVENT_CUSTOM;
long currChart=ChartFirst();

int i=0;
   while(i<CHARTS_MAX)              
     {
	EventChartCustom(currChart,eventID,lparam,dparam,sparam);
	currChart=ChartNext(currChart);
 	if(currChart==-1)
          break;     
        i++;
 }

I had two functions with the same name but different parameters sending the broadcast. I just deleted the old version I was not calling. Still, I suspect it might be the cause. I'll see.



 
dc3463456 #:


CHARTS_MAX = The maximum possible number of simultaneously open charts in the terminal


bad chart id=133315345830123751

good chart id=133315345830123736

I had two functions with the same name but different parameters sending the broadcast. I just deleted the old version I was not calling. Still, I suspect it might be the cause. I'll see.



Again don’t use charts_max.  That is going to send charts_max events and you are probably over running the event queue so some charts may not get the event

 
Paul Anscombe #:
Again don’t use charts_max.  That is going going to send charts_max events and you are probably over running the event queue so some charts may not get the event

I took this code from the documentation. What alternative do you recommend?

 

All charts are correctly sent the message by

EventChartCustom

... but the problem is still happening  :-/

 
dc3463456 #:

I took this code from the documentation. What alternative do you recommend?

Use chartfirst() and chartnext() to loop through only the open charts
 
Paul Anscombe #:
Use chartfirst and chart next to loop through only the open charts

That's what I'm doing. I posted the code above.

 
dc3463456 #:

That's what I'm doing. I posted the code above.

Ok I can see that but you still don’t need the charts_max.  Use a while loop with the chartnext instead. Simpler easier to understand 

You were checking the duplicate function ?

Change the alert to a print statement on the receiver to eliminate any alert queue issue 
 
Paul Anscombe #:
Ok I can see that but you still don’t need the charts_max.  Use a while loop with the chartnext instead. Simpler easier to understand 

You were checking the duplicate function ?

I deleted the duplicate function. It didn't change anything.

I am now testing with the same  

OnChartEvent

function as the working chart.

I don't know why the body would prevent the function from being executed but I am trying anyway.
Reason: