Experts: Close At Time

 

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

 

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

 

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.

 
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...
 

This code is of very poor quality.

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

 
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
 
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.
 
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.
 
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.
 
Hello guys you can change EA, I'll explain better, I would like to close the open order, at the closing of the bar, is it possible?
Reason: