Download MetaTrader 5
To add comments, please log in or register
Interested in MQL5 features? Find them in documentation!
Automated-Trading
Admin
88366
Automated-Trading 2015.12.02 12:48 

Close At Time:

Close At Time is an EA that closes open positions or deletes pending orders or both. You can also specify how it should be closed – by symbol, magic number or ticket number.

extern bool bAllClose = false; //Close All
extern bool bSymClose = false; //Close by Symbol
extern bool bMNClose = false; //Close by Magic Number
extern bool bTNClose = false; //Close by Ticket Number
extern bool PO = false; //Close Pending Orders
extern bool MO = false; //Close Market Orders
extern string TimeToClose="YYYY.MM.DD HH:MI"; //Local time to close

Author: Algofxsolution

Jim Salib
237
Jim Salib 2015.12.10 01:53  

Hi Alfofxsolution,

I use a Martingale EA that trades with a number of baskets of trades. Can your EA be attached to mine and have it close a particular basket of trades, instead of closing all the other baskets of trades. And also close at an Equity Stop level of that particular basket.

Regards

Jimbos181

Algofxsolution
730
Algofxsolution 2015.12.10 09:03  

Hi Jimbos181,

It depend on how do you marked individual baskets of trades. If it can be selected by magic number or symbol, then yes. Close at an Equity Stop level not. By the way, consider if is martingale good approach. Do you want to spend months or years with not perspective idea? You will waste your time on it. But, just my opinion.

mql4student
147
mql4student 2015.12.15 01:51  
This EA would be better if it has a function to close all open trades if it's been open for too long of time. such as 5 days, 10 days, ect...
Alain Verleyen
Moderator
28517
Alain Verleyen 2015.12.15 22:47  

This code is of very poor quality.

Never use it on a real account as you are risking very bad surprise.

Algofxsolution
730
Algofxsolution 2015.12.16 11:17  
Alain Verleyen:

This code is of very poor quality.

Never use it on a real account as you are risking very bad surprise.

Hi Alain, what do you exactly mean? Because we use Close at Time for months without any fails. Two different brokers, live and demo account too. Thanks for your comments
Alain Verleyen
Moderator
28517
Alain Verleyen 2015.12.16 12:56  
Algofxsolution:
Hi Alain, what do you exactly mean? Because we use Close at Time for months without any fails. Two different brokers, live and demo account too. Thanks for your comments

My previous message was not very constructive, should not post so late ;-)

It all depends on the context...but sooner or later someone will have problems.

The main issue is you ALWAYS need to count down when processing orders :

      for(int i=OrdersTotal()-1; i>=0; i--)

.And when you try 3 times in a row to close, you need to refresh your price :

         if(OrderClose(OrderTicket(),OrderLots(),AskOrBid,MaxSlippage)==false)
           {
            // Your AskOrBid could be obsolete : need RefreshRates()
            ...

            //Retries 2//
            if(OrderClose(OrderTicket(),OrderLots(),AskOrBid,MaxSlippage)==false)
              {
               // Your AskOrBid could be obsolete : need RefreshRates()
               ...

               //Retries 3//
               if(OrderClose(OrderTicket(),OrderLots(),AskOrBid,MaxSlippage)==false)
                 {
                  error=GetLastError();
                  Print("Error closing order for ticket:"+StringConcatenate(OrderTicket())+" Error: "+StringConcatenate(error)+" : "+ErrorDescription(error));
                 }
              }
           }
You don't process errors you just report it and retry. Believe my on a live trading environment that could lead to problems. Other points are minor.
Algofxsolution
730
Algofxsolution 2015.12.16 14:55  
Alain Verleyen:

My previous message was not very constructive, should not post so late ;-)

It all depends on the context...but sooner or later someone will have problems.

The main issue is you ALWAYS need to count down when processing orders :

.And when you try 3 times in a row to close, you need to refresh your price :

You don't process errors you just report it and retry. Believe my on a live trading environment that could lead to problems. Other points are minor.
Thank you Alain, good point. It could lead in problems in some specific situations. New version is waiting for approve.
Alain Verleyen
Moderator
28517
Alain Verleyen 2015.12.16 15:28  
Algofxsolution:
Thank you Alain, good point. It could lead in problems in some specific situations. New version is waiting for approve.
You are welcome. Good reaction.
/
To add comments, please log in or register