How to stop EA whem total profit reaches target?

 

I've been struggling with this problem for a little while. I want the close all positions and stop my EA when total profit reaches a certain value.


Where :

TotalProfit += OrderProfit();

Across all positions:


If the same EA is used on multiple charts, how can I close all positions and stop all EAs at the same time?

1. I've tried using a script to check for the total profit target and then close the positions, but there's no way to stop EAs from script.

2. I've tried unsuccessfully to get the EAs to stop themselves. Some of them reopen their positions because I guess they don't all see profit target being hit.

Does anyone have any suggestions?

 

Use a Global Variable of the Client Terminal.

When an EA detects that all profits must be closed, it can assign a value to the GV.

Have the EAs check the value of the GV and if it is a certain number, stop trading.

 
Thanks GumRai, I didn't konw about GlobalVariables. Just what I needed!
 
  1. Don't need GVs Just do your orderSelect loop and create your sum, return from start on your limit.
  2. But if you insist: Remove an EA through MQL4 code - MQL4 forum
Reason: