Reply

CLOSE all trades

11 replies

Patrick

Customer, bbp_participant, community, 424 replies.

Visit profile

7 years ago #115440

Does anyone have/use EA, which close all trades when equity falls below certain level?

0

daveng

Customer, bbp_participant, community, 93 replies.

Visit profile

7 years ago #138786

I can write you a function which u can insert into your EA if you want. I am out at the moment, so I can only code when I am back home to my laptop.

0

Karish

Customer, bbp_participant, community, sq-ultimate, 443 replies.

Visit profile

7 years ago #138790

double MyAccountEquityGuard = 1000; //<< your equity that you want to guard. (Leave 0 if you dont want to use it.)

//Add this under OnStart():   
if(MyAccountEquityGuard!=0){if(AccountEquity()<=MyAccountEquityGuard){
   closeActiveOrders();
   closePendingOrders();
   Alert("Your AccountEquityGuard Was triggerd, All Active&Pending orders was closed.");
   return(true);
   }}

*THE CODE WAS UPDATED AT: 01/02/2017 by a request from member pupsik, please update to the current code setup.

0

Patrick

Customer, bbp_participant, community, 424 replies.

Visit profile

7 years ago #138791

i have a question, the idea was to let it run on another server alone, not as a part of EAs.

is it possible?

 

another Q, it check the equity every second/or minute?

 

Thx for your replies guys! i realy appreciate it. and i think this can be useful for everybody who has brker with very low stop out level.

0

daveng

Customer, bbp_participant, community, 93 replies.

Visit profile

7 years ago #138796

Ok, I’ve coded an EA for you as attached in mq4 format.

 

Note that I assumed once your equity limit is triggered you would want all orders to be closed regardless of which orders from which EAs or Symbols are running in your account. As such I did not set the EA to compare the Magic Number or Symbols of the orders as I think it is not necessary (assuming you want to close all orders).

 

Also I’ve broken down the EA into 2 parts, one is to close opened orders, and the other part is to delete pending orders.

You can choose to enable or disable according to your needs.

For example, if you would only want to close opened orders but not the pending orders, please set “CloseOpenedOrders” to true, and set “DeletePendingOrders” to false.

Just drag the EA onto any one chart, set its parameters and let it do its work.

 

Last but not least, please note that I’ve NOT test this EA on my account as all my live and demo accounts are all ‘busy’ running strategies, so I prefer not to touch them 🙂

So please do test it on your demo account first before using it on live.

For your info, I’ve did a compilation and its error free 🙂

Let me know if this works for you!

 

0

Patrick

Customer, bbp_participant, community, 424 replies.

Visit profile

7 years ago #138799

Thank You Dave.

 

if i understand it, it checks the equity on every tick?

And if i understand it right, even if the EAs will open another pending order, it will be closed in a while, because equity is still below certain level, right?

 

I will open a demo account for it and try it. If you need some help with SQ in return, send me PM.

 

I have another idea,to add option: If equity falls below certain level, send email notification. 

In this case you get warning before the trading is stopped. So its like double control mechanism.

 

i think this is very helpful, because FX is sometimes unpredictable…

0

daveng

Customer, bbp_participant, community, 93 replies.

Visit profile

7 years ago #138810

Yes, the EA checks the equity on every tick, hence it doesn’t matter which time frame you are using it on.

I’ve added 2 alert features to the EA – Email and Push 🙂

So I’ve recoded the EA to include these 2 features as attached in mq4 format. So please discard the old copy.

 

Email

– If you want to enable this feature, set “EquityEmailAlert” to true.

– When your equity drops to/below the “EquityLevelToAlert”, the EA will send you an email.

– You can specify your own email subject and message in the parameters. I’ve put in a default message for you.

– The email will only be sent once when the equity drops to the level.

– If your equity rise above the level and then drops back down again, another email will be sent.

– IMPORTANT: In order for this feature to work, you’ll need to configure your MT4 as illustrated in the link below:

https://www.forexboat.com/mt4-email-alert/

 

Push

– If you want to enable this feature, set “EquityPushAlert” to true.

– When your equity drops to/below the “EquityLevelToAlert”, the EA will send a push notification to your Mobile App (iPhone or Android).

– I set the message to be the same as the email message.

– The push notification will only be sent once when the equity drops to the level.

– If your equity rise above the level and then drops back down again, another push notification will be sent.

– IMPORTANT: In order for this feature to work, you’ll need to configure your MT4 as illustrated in the link below:

http://www.cmapllc.com/how-to-set-up-push-notifications-in-mt4-mobile-android-and-iphone.html

 

 

I’ve tested the alerts on my account and it is working for both email and push.

However please do test it intensively on your own demo account to confirm that if is working first before you use it on live.

 

 

Regards,

Dave

Your friendly neighbourhood coder 😛

0

Patrick

Customer, bbp_participant, community, 424 replies.

Visit profile

7 years ago #138832

Thank you Dave, ofc i will test it on demo first.  😉

0

daveng

Customer, bbp_participant, community, 93 replies.

Visit profile

7 years ago #138833

Thank you Dave, ofc i will test it on demo first. 😉

You’re welcomed!
Btw it is actually quite dangerous to have your EA keep opening market orders while this EA closing them. Your account could be depleted from the spread/comm costs from each transaction especially if your EA generates high trade volume. Just something to watch out for…

0

Patrick

Customer, bbp_participant, community, 424 replies.

Visit profile

7 years ago #138849

of course the best option would be to disable utomated trading. 🙂

0

daveng

Customer, bbp_participant, community, 93 replies.

Visit profile

7 years ago #138850

Or best is to incorporate the codes into your EA if u have the source codes.

0

Patrick

Customer, bbp_participant, community, 424 replies.

Visit profile

7 years ago #138851

but, if your VPS die and the code is in your EA you are in trouble. The idea was run this EA on another VPS provider in the same MT4. To protect the account from loss cuased by VPS provider x MT4 x Windows issue.

0

Viewing 11 replies - 1 through 11 (of 11 total)