- the logic is simple - i just inserted IF function - if ( accountbalance() - accountequity() ) / accountbalance() >= DDpercent / 100 { CloseAll; } which sends the EA to the void function which has to close all open and pending orders.
if ( accountbalance() - accountequity() ) / accountbalance() >= DDpercent / 100 { CloseAll; }
if ( accountbalance() - accountequity() ) / accountbalance() >= DDpercent / 100 //What does this do? CloseAll; //Is this supposed to be a function call?
I don't see how that can compile
Try this.
if( ( accountbalance() - accountequity() ) / accountbalance() >= DDpercent / 100) { CloseAll(); }
Try this.
if( ( accountbalance() - accountequity() ) / accountbalance() >= DDpercent / 100) { CloseAll(); }
Yes, that will compile, but that is not the code that was posted by the OP.
I would think that everyone who posts code (that is not working as expected) would simply copy and paste from their actual code, so there should be no typos.
Yes, that will compile, but that is not the code that was posted by the OP.
I would think that everyone who posts code (that is not working as expected) would simply copy and paste from their actual code, so there should be no typos.
It compiled the way I did it and I found out why it wasn't working - I just moved the if function in void(start) so it will check it every time. And yes, CloseAll is a function call as I wrote in the first post if you read it carefully. Thank you for your assistance!
There is no way that the code you wrote in your first post compiled.
Hiltos corrected your code. As follows--
if( ( accountbalance() - accountequity() ) / accountbalance() >= DDpercent / 100) { CloseAll(); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I was experimenting with an EA but I got stuck when I tried to make it close all orders when 20% drawdown is reached. The code is extremely simple, in fact it is randomly opening orders, I just wanted to see if I have basic coding skills.
So, up to the question - I tried to limit the maximum drawdown in a very simple way (which didn't work and I don't know why). There are the few lines that somehow I got wrong:
- there is a variable (in my case DDpercent) which I set to 20.
- the logic is simple - i just inserted IF function - if ( accountbalance() - accountequity() ) / accountbalance() >= DDpercent / 100 { CloseAll; } which sends the EA to the void function which has to close all open and pending orders.
The void function is working pretty well when it has to take profit but I think that there is something wrong with the way I do the math for balance and equity. I would be very thankful if someone is willing to help me.