How can I close all trades

 

How can I close all open trades and pending orders together ?

Thanks for help.

 

Close All

Here try these

Files:
 

1. CloseAll-PL EA is here.

2. CloseTrades_After_Account_Profit_Reached Ea is here.

SpreadToCheck EA (spread checker): expert will record current time and current spread in *.csv file.

spread monitor indicator is here.

EA to delete pendind orders on specify pairs only: original thread.

EA to delete all pendind orders: original thread.

EA to close the orders on specify pairs only: original thread.

EA to close open trades based on equity or account floating loss reaches: public thread.

 
newdigital:
1. CloseAll-PL EA is here.

2. CloseTrades_After_Account_Profit_Reached Ea is here.

SpreadToCheck EA (spread checker): expert will record current time and current spread in *.csv file.

spread monitor indicator is here.

EA to delete pendind orders on specify pairs only: original thread.

EA to delete all pendind orders: original thread.

EA to close the orders on specify pairs only: original thread.

EA to close open trades based on equity or account floating loss reaches: public thread.

Please explain how to use the first one if I've already got an EA on the chart. Let's say I have an Full EA running on USD/CAD but don't like its internal SL and TP code would I add another USD/CAD chart then attach the close EA on it?

Thanks

 
Jovager:
How can I close all open trades and pending orders together ? Thanks for help.

My new EA can do that and more.

https://www.mql5.com/en/forum/176995

 

Will something like this work??

while(OrdersTotal()>0)

{

OrderSelect(0,SELECT_BY_POS);

if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);

if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);

if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP||OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket());

}

 
wolfe:
Will something like this work??

while(OrdersTotal()>0)

{

OrderSelect(0,SELECT_BY_POS);

if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);

if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);

if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP||OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket());

}

Yes, that will work.

 

Will it work with this EA?

Hi Ryan:

Do I attach this EA to a duplicate chart of the pairs I am trading or attach it to the working chart I am running with the other EA? (no conflict?)

The other EA is the Bless FifthElement EA

Also, after it closes the trades, will it stop trading until I reset it? (This is what I want)

Will it do this?

Thanx ryan

 

close all open positions per chart or one pair only

fxgold:
Here try these

Quoted scripts don't work with 5 digit broker

"Close All open orders" scripts closes all positions on all pairs. But most of the time I have to close positions on one pair only.

So is there a script (not an EA) to close all positions per chart and not all positions per account.

Also there should be "Close all pending per chart script"

I wonder if there is anything of practical use here besides great code samples for aspiring coders?

 

HELP WITH My Ozfx

Hello!

It's nice to meet you all on this forum.

I'm a newbie, and I need your help. I'm trying to set up "My OZFx Squeeze refined v3[1][1].1" EA.

Please, I do want you to help me with the best setting you think I can use for it, i.e. the best currency pairs, best charts, etc.

I use FXDD presently, and may use IBFX in the nearest future.

Thanks to all.

Daresfile

---------------------------------------------------------------

God, the Author of all kowledge and wisdom.

 
wolfe:
Will something like this work??

while(OrdersTotal()>0)

{

OrderSelect(0,SELECT_BY_POS);

if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);

if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);

if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP||OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket());

}

How about "sleep" after every closing? Not every broker will let you close 2+ orders within 1 second. Other than that it should work perfectly.

daresfile:
I'm trying to set up "My OZFx Squeeze refined v3[1][1].1" EA. Please, I do want you to help me with the best setting you think I can use for it, i.e. the best currency pairs, best charts, etc.

Wow... did you try testing it at all? Best pairs, settings ect - it all depends on you only. You want it to trade in a specific way on a specific pair. It doesn't work any other way because its you who's responsible for the risks you take so you should know what you're doing...

greg108:
Quoted scripts don't work with 5 digit broker

For 5 digits brokers you need to normalize ask and bid values (like,

NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),Digits)

)

Hope this helps.

Example:

while(OrdersTotal()>0)

{

OrderSelect(0,SELECT_BY_POS);

if(OrderType()==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),Digits),999,Red); Sleep(1000); }

if(OrderType()==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),Digits),999,Orange); Sleep(1000); }

if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP||OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT) { OrderDelete(OrderTicket()); Sleep(1000); }

}
greg108:
"Close All open orders" scripts closes all positions on all pairs. But most of the time I have to close positions on one pair only.

So is there a script (not an EA) to close all positions per chart and not all positions per account.

Also there should be "Close all pending per chart script"

Script? Per chart? Um... why? I'm asking because all currency pair's trades are put on every chart. So basically it means "per currency pair" or "per symbol". And for that we have OrderSymbol() and Symbol(). But the quoted script won't do the trick any more.

I don't know how to write a script that closes trades, I prefer using EAs for that. Don't know why you're against them though.

The EA to close trades is attached. It normalizes Ask and Bid, can be used to close ALL orders or specific orders on all symbols or only on the symbol its attached to (see settings for details).

Please note: Magic number is a number that only EAs can set. Magic number can't be changed after the order is opened. Orders opened manually have magic number of 0.

Hope it helps. Details on how to use can be found inside the settings.

Reason: