how to open pending order at 23:58

 

how to open a pending order at 23:58h ?

i have tested w/ following but did not work:

int start()

  {

int     OpenTradeTime = 2358;

int     MinutesToWaitForTick = 1;
int ct, EndTradeTime;

ct = Hour() * 100 + Minute();

EndTradeTime = OpenTradeTime + MinutesToWaitForTick;


int expire = CurTime() + 48 * 3606;


   total=OrdersTotal();


      if(((DayOfWeek()==5) && (ct >= OpenTradeTime && ct < EndTradeTime) && (OrdersTotal() == 0)))
      {

           for ( cnt = 0; cnt < NumBuys; cnt++)

           {

             ticket=OrderSend(Symbol(),OP_BUYSTOP,Lot,MyAsk,SlipPage,MyBid+(Distance-SL)*Point,MyAsk+(Distance+TP)*Point,OrdComment,Magic,expire,Green);
             ticket=OrderSend(Symbol(),OP_SELLSTOP,Lot,MyBid,SlipPage,MyAsk-(Distance-SL)*Point,MyBid-(Distance+TP)*Point,OrdComment,Magic,expire,Green);

             if(ticket>0)

             {

              if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("order opened : ",OrderOpenPrice());

             }

             else Print("Error opening order : ",GetLastError()); 

           }

          }



   return(0);

  }
 
Actually it should work. What error do you have on logs?
 
fulltilt:

how to open a pending order at 23:58h ?

i have tested w/ following but did not work:

  1. int expire = CurTime() + 48 * 3606;
    If you mean expires in 48 hours - there's only 3600 seconds per hour.
  2. int     OpenTradeTime = 2358;
    int     ct = Hour() * 100 + Minute();
    int     MinutesToWaitForTick = 1;
    int     EndTradeTime = OpenTradeTime + MinutesToWaitForTick;
    if(((DayOfWeek()==5) && (ct >= OpenTradeTime && ct < EndTradeTime) && (OrdersTotal() == 0)))
    If your broker is using GMT time, that will never work - as the market is CLOSED on Friday at 2200z http://www.forexmarkethours.com/
  3. The * 100 is confusing. I would code it:
    #define HR2400 86400 // 24*3600
    #define HR2358 86280 // 23*3600 + 58*60
    datetime now = TimeCurrent(),
             tod = now % HR2400;  // Time of day
    if(((DayOfWeek()==5) && (tod >= HR2358...
    or alternately
    datetime now           = TimeCurrent(),
             OpenTradeTime = StrToTime("23:58");
    if(((DayOfWeek()==5) && (now >= OpenTradeTime...

  4. ticket=OrderSend(Symbol(),OP_BUYSTOP,Lot,MyAsk,SlipPage,MyBid+(Distance-SL)*Point,MyAsk+(Distance+TP)
    On a buy stops are relative to Bid (TP) Bid+(Distance-SL) makes no sense. Maybe Bid-(Distance+SL)*point
  5. Always test return codes and print errors so you find out WHY.
        int ticket = OrderSend(...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
    

  6. EA's must adjust TP, SL, AND slippage for 4/5 digit brokers
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
         if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
    

  7. On ECN brokers you must open first and THEN set stops
        int ticket = OrderSend(...)
        if (ticket < 0)
           Alert("OrderSend failed: ", GetLastError());
        else if (!OrderSelect(ticket, SELECT_BY_POS))
           Alert("OrderSelect failed: ", GetLastError());
        else if (!OrderModify(OrderTicket()...)
           Alert("OrderModify failed: ", GetLastError());
    

  8.    total=OrdersTotal();
    
    This makes the EA incompatible with every other including itself on other charts and manual trading. Always filter
    int nOrders=0;
        for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol()                 // and my pair.
        ){
            nOrders++;
        }
    if (nOrders == 0 && ...

 
fulltilt:

how to open a pending order at 23:58h ?

i have tested w/ following but did not work:

this kind of trades, its the best you contact directly to your broker, quote "weekend fill", and you should be able to know whether they're accepting. Markets can "move" erratically, substantially on Asian Monday opening bell side, esp after undisclosed meetings happening over the weekend. We just got to know about it much, much later while the rest of the world still sleeping.

There are business circumstances which are not possible, to the best of interest for both sides. same for the rest of strategy in this category of weekend OTC measures.

And you may like to know, that I know personally traders (professionals or otherwise) have flouted their money badly on this...if they do make money, its just gambler's luck. All the best!

 

thanks guys, very usefull information!

for this part I need another solution so that I can set expire time as extern ...

int expire = CurTime() + 48 * 3606;

expire time should be +48h + expire hour and minute as extern parameter

 
sorry I mean, expire time should be every monday 00:02 - is this possible?
 
if TimeCurrent is Friday 23:58 then Monday 00:02 is TimeCurrent() + 48*3600 + 4*60 // 2 days + 4 minutes
 

In the first place, does your broker accept expiry time on all their stop orders? Do you ever know, that brokers, except for some/few I know out there, who not accept expiry time?