My Close For Profit/Loss EA isn't functioning properly.

 
This EA closes all the trades when everything either reaches a set positive or negative amount. However, when no trades are open it has a problem. "Zero Dived in EA" (see attachment) then the entire EA stops. I need help in what to do to my EA to make it so when no trades are open it will continue to wait until more trades open and the profit/loss criteria are met. (Then continue on, and so on and so forth)
 

Means you are dividing by 0

Please check if you are dividing something by 0 before you do the division

 
fly2hi:
This EA closes all the trades when everything either reaches a set positive or negative amount. However, when no trades are open it has a problem. "Zero Dived in EA" (see attachment) then the entire EA stops. I need help in what to do to my EA to make it so when no trades are open it will continue to wait until more trades open and the profit/loss criteria are met. (Then continue on, and so on and so forth)

Hi,

When there is no open position, then you may check your code :

"                            MarginPercent        ", MathRound((AccountEquity()/AccountMargin())*100), NL,
 
Yohana Parmi:

Hi,

When there is no open position, then you may check your code :

Ah, gotcha thanks, what should I change it to then?
 
fly2hi:
Ah, gotcha thanks, what should I change it to then?

The easiest way is a condition for your string Comment before you use it :)
similar with this :

if (position_total>0) 
    sComment = sComment + " | Current Margin Level: "+DoubleToString((AccountEquity()/AccountMargin())*100,2)+"% |";

and fyi -- you can find some experienced coders are available at
https://www.mql5.com/en/job

good luck

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • www.mql5.com
Hi, I would like to offer a Job for MQL4 Expert Advisor Update - Adding or replacing an indicator in an Expert Advisor. Current Expert Advisor working charming. And I would like to make it more aggressively charms and powerful. I have been dealing with Phil so many times. Really likes his works. Thank you Hi Abhishek, I got a new task for...