Add " Max trade of the day"

 

I have an simple EA that keep on placing trades until margin out, and that is no problem with that fro competition purpose.

The thing is how can i add a line of "maximum Trades of the day" ??

This line u see below "extern double MaxOpenOrders = 3;" is just simply mean everytime it places 3 orders same time.Once it TP or SL, it will place another 3 orders immediately.

What i think is how to limit the TOTAL ORDERS of the day? Example says total of the day is 30 orders, so this EA only can do 10X of placeing 3 orders

Can anyone pls add some codes in?

Many thanks




//--------------------------------------------------------------------
// simpleopenbuy.mq4
//
//--------------------------------------------------------------------
extern double lots = 0.1;
extern double TakeProfit = 20;
extern double Stoploss = 17;
extern double MaxOpenOrders = 3;


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
// Special function start()

{ // Opening BUY
OrderSend(Symbol(),OP_BUY,lots,Ask,3,Bid-Stoploss*Point,Bid+TakeProfit*Point);
return; // Exit start()
 
int todayOrdersTotal() {
  int count = 0;
  for(int cnt=0; cnt<OrdersTotal(); cnt++)
   if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
    if (OrderType() == OP_BUY || OrderType() == OP_SELL)
     if (TimeDayOfYear(TimeCurrent()) == TimeDayOfYear(OrderOpenTime())) count++;
  return (count);
}
 
  1. That won't work. OP wants to prevent opening more orders after the current ones close.
    Once it TP or SL, it will place another 3 orders immediately
  2. In addition, the select loop should be filtering by magic number and pair so it is compatable with other chart/pairs.
    int todayOrdersTotal() {
        datetime    BOD     = Time[0] - Time[0] % 86400;    // Beginning of today
                    // Use  = TimeCurrent() - 86400 for last 24 hours
        int         count   = 0;
        for(int pos=OrdersHistoryTotal()-1; pos >= 0; pos--) if (
            OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair,
        &&  OrderCloseTime()    > BOD                       // closed today.
        &&  OrderType()         <= OP_SELL){// Avoid cr/bal https://www.mql5.com/en/forum/126192
            count++;
        }
        return (count);
    }