Is mult-threading possible in Expert Advisors?

 

First, look at this scenario in an Expert Advisor:

 

STEP 1:  ChartSetInteger(chart_ID,CHART_BRING_TO_TOP,0,true)); // bring a chart to the foreground;

STEP 2: Sleep(2000);

STEP 3:  do a job;

 

We know that each single Expert Advisor runs in its own thread. But when I run the above code, I got strange results. Sometimes the chart comes to the foreground and the STEP 3 runs 'immediately'.  Sometimes the chart doesn't come to the foreground 'at all'. Sometimes it comes to the foreground sooner than 2 seconds (2000 milliseconds).

 I'm guessing it's something to to with threads running independent from each other. Also I'm guessing the STEP 1 doesn't actually bring the chart to the foreground, but instead it just sends a request to the User Interface Thread and I cannot predict when it actually runs.

Do you think I am mis-interpreting this problem? Do you have any suggestions/guide/...? Can I have any control on threads in mql5?

Do you know any alternative way to achieve the above scenario?

 
josephcom:

First, look at this scenario in an Expert Advisor:

 

STEP 1: bring a chart to the foreground;

What that means exactly ?

STEP 2: Sleep(2000);

STEP 3:  do a job;

 

We know that each single Expert Advisor runs in its own thread. But when I run the above code, I got strange results. Sometimes the chart comes to the foreground and the STEP 3 runs 'immediately'.  Sometimes the chart doesn't come to the foreground 'at all'. Sometimes it comes to the foreground sooner than 2 seconds (2000 milliseconds).

 I'm guessing it's something to to with threads running independent from each other. Also I'm guessing the STEP 1 doesn't actually bring the chart to the foreground, but instead it just sends a request to the User Interface Thread and I cannot predict when it actually runs.

Do you think I am mis-interpreting this problem? Do you have any suggestions/guide/...? Can I have any control on threads in mql5?

No.

Do you know any alternative way to achieve the above scenario?

Which scenario, your real problem is not clear ?
 
Alain Verleyen:
What that means exactly ?
No.Which scenario, your real problem is not clear ?
Yes, it is. Like I said, I want to bring a chart window to foreground, and after EXACTLY 2 seconds, do something else. The problem is this sequence cannot be achieved. Most of the time, after running the code in an Expert Advisor, the chart comes to foreground and then IMMEDIATELY the code in STEP 3 runs!

ChartSetInteger  (chart_ID,  CHART_BRING_TO_TOP,  true));
Sleep  (2000);
DoSth(...);


 
josephcom:
Yes, it is. Like I said, I want to bring a chart window to foreground, and after EXACTLY 2 seconds, do something else. The problem is this sequence cannot be achieved. Most of the time, after running the code in an Expert Advisor, the chart comes to foreground and then IMMEDIATELY the code in STEP 3 runs!

ChartSetInteger  (chart_ID,  CHART_BRING_TO_TOP,  true));
Sleep  (2000);
DoSth(...);


Ok, it is.
 
I have followed your comments everywhere in the forum. Apparently you're not happy with your job, cause most of the time you're too out of mood to reply users. Do you think "OK, it is" is a perfect reply for someone who's spent one whole day to find out a way out of his problem IN VEIN?
 

This is standard reply sorry ...

Welcome,

  • Usually people who can't code don't receive free help on this forum, though it could happen if you are lucky, be patient.
  • If you show your attempts and describe well your problem, you will most probably receive an answer from the community.
  • If you don't want to learn to code, nothing bad, you can either look at the Codebase if something free already exists, or in the Market for paid products (sometimes free also).
  • Finally, you also have the option to hire a programmer in the Freelance section.
Good luck.
 
First, you should check if ChartSetInteger returns success, and if not - analyze error code.
 
josephcom:
I have followed your comments everywhere in the forum. Apparently you're not happy with your job, cause most of the time you're too out of mood to reply users. Do you think "OK, it is" is a perfect reply for someone who's spent one whole day to find out a way out of his problem IN VEIN?
  • You should avoid to draw conclusions from partial information, that will help you in coding too.
  • I am helping who I want, when I want, nothing to do with my job
  • If you really want help you should stop attack people who are trying to help you.
  • The chart is managed by the platform in it's own thread, I already said you there is no way to control threads on mql5.
  • You real problem is still unclear to me, what are you trying to achieve exactly ?
Reason: