Only One Trade - page 2

 
FXpipclash:


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.


  // retrieving info from trade history
  int i,hstTotal=OrdersHistoryTotal();
  for(i=0;i<hstTotal;i++)
    {
     //---- check selection result
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
       {
        Print("Access to history failed with error (",GetLastError(),")");
        break;
       }
     // some work with order
    }
Reason: