Close all position at the specific time only one time everyday.

 

I want to trade the XAUUSD at the market but doesn't want to have overnight trade. The market closed at 23:59. When I using this EA, all position will closed at 23:50. But another EA will automate open the order after 23:50 and then this EA will close immediately. How can I turn the code to close all the position everyday at 23:50 everyday or make the close all position EA only work one time? Here is the code: 


    

//---- input parameters extern int CloseHour = 7; // Time to close, hours extern int CloseMinute = 0; // Time to close, minutes extern bool UseCurrSymbol = False; // Use one symbol only extern bool UseOneAccount = False; // Use one account only extern int NumberAccount = 11111; // Account number extern int Slippage = 3; // Slippage extern color clCloseBuy = Blue; // Color of closing buy extern color clCloseSell = Red; // Color of closing sell void start() { double pBid, pAsk; if (UseOneAccount && AccountNumber()!=NumberAccount) { Comment("Working on the account: "+AccountNumber()+"is PROHIBITED!"); return; } else Comment(""); if (Hour()==CloseHour && Minute()>=CloseMinute) { for (int i=OrdersTotal()-1; i>=0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (!UseCurrSymbol || OrderSymbol()==Symbol()) { if (OrderType()==OP_BUY) { pBid=MarketInfo(OrderSymbol(), MODE_BID); OrderClose(OrderTicket(), OrderLots(), pBid, Slippage, clCloseBuy); } if (OrderType()==OP_SELL) { pAsk=MarketInfo(OrderSymbol(), MODE_ASK); OrderClose(OrderTicket(), OrderLots(), pAsk, Slippage, clCloseSell); } } } } } }

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
Account Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.

NB! Very important! DO NOT create a new post. EDIT your original post.

 
Fernando Carreiro #:

Please edit your post (don't create a new post) and replace your code properly (with "</>" or Alt-S), or attach the original file directly with the "+ Attach file" button below the text box.

NB! Very important! DO NOT create a new post. EDIT your original post.

thanks you! 

Reason: