Any ideas on how to have my EA stop trading once it has closed out its first trade of the day?
Thanks,
pat
you need to use the following: datetime OrderOpenTime(
)
Write code which will scan all closed trades(mode_history), and will compare if any trades have been opened on today's date. If there weren't any matches of dates in the orders of the history pool, then continue to the rest of the code in the EA. Else, if the history order pool contains an order with today's date, stop the EA from executing. This approach will make your request very robust, and you would not have to use HOURs() limits. The EA will scan each closed order and will compare today's date to each orders date, and if there is a match, then don't execute orders. If there isn't a match, then the EA will open one order. But you would also have to scan the live orders, and apply the same logic. Below is the sample code for running through each closed order.
// retrieving info from trade historyint i,hstTotal=OrdersHistoryTotal();for(i=0;i<hstTotal;i++){//---- check selection resultif(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false){Print("Access to history failed with error (",GetLastError(),")");break;}// some work with order}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Fellow Coders:
Any ideas on how to have my EA stop trading once it has closed out its first trade of the day?
Thanks,
pat
you need to use the following: datetime OrderOpenTime( )
Write code which will scan all closed trades(mode_history), and will compare if any trades have been opened on today's date. If there weren't any matches of dates in the orders of the history pool, then continue to the rest of the code in the EA. Else, if the history order pool contains an order with today's date, stop the EA from executing. This approach will make your request very robust, and you would not have to use HOURs() limits. The EA will scan each closed order and will compare today's date to each orders date, and if there is a match, then don't execute orders. If there isn't a match, then the EA will open one order. But you would also have to scan the live orders, and apply the same logic. Below is the sample code for running through each closed order.