need mql4 basics hint

 

Dear Experts,

how can I make an EA stop opening new positions at a certain AccuntEquity level? I hardly got it to close all positions, but it keeps opening new ones.

Fo Rex

 

your entry code needs to have a condition for accountequity().


if(blah blah blah && AccountEquity()<1000){then enter}
 
c0d3:

your entry code needs to have a condition for accountequity().



Doesn't really helps :(

I am modifying a script, and I dont know how and where to add the entry code. But I'll try.

 

You can add this after start()


if(AccountEquity()<1000) return(0);
This will stop the Expert after the equity drop.
 
codersguru:

You can add this after start()


This will stop the Expert after the equity drop.


ok, with this I can make it closing open positions when AccountBalance>1000. But it doesnt work in the other direction, when the equity drops. I feel a little helpless there.

And the EA is still opening new positions right after :(

 
AccountBalance()<1000

not

AccountBalance>1000. 
 
qjol:


yes, yes...I tried both. With the brackets. But only using AccountEquity()>1000 seems to have an effect. Even if it doesnt finally stops trading, it closes positions there.

But with AccountEquity()<1000, the EA does not stop.

I will keep on trying, but I am thankful for every new hint and repeated explanations to solve my problem. I am thinking about further modifications, but I cant go on if I dont even get this thing right.

 
double REQUIRED_EQUITY_LEVEL = 1000.0;

bool GlobalError = false; 

 

int start()

{

   if ( GlobalError )  { return(0); }

   if ( AccountEquity() < REQUIRED_EQUITY_LEVEL )  { GlobalError = true; }

   //...

}

Try to use additional variable. Maybe AccountEquity() changes when you close all positions and your initial check fails.

 
hasayama:

Try to use additional variable. Maybe AccountEquity() changes when you close all positions and your initial check fails.


finally! some positive results. it is not exactly doing what i want it to, but its going to the right direction.
thx to you all, so far.
 

Does it make sense to write my next question right here in the bottom?

Now I would like to know how to make my EA close all positions and stop trading when the AccountEquity drops to a certain % of the AccountBalance.

Fo Rex

 
fo.rex:

Does it make sense to write my next question right here in the bottom?

Now I would like to know how to make my EA close all positions and stop trading when the AccountEquity drops to a certain % of the AccountBalance.

Fo Rex

double Percent = 30.0;

if ( AccountEquity()*100.0/AccountBalance() <= Percent ) { /*use your imagination here*/ }

Reason: