Not logged in

Forums

Viewing 9 posts - 1 through 9 (of 9 total)
  • #115445 |
    Customer
    916 Posts

    Hi,

     

    I have a strategy that replaces pending orders.  However there is an issue with the MQ4 that SQ generates, in that during a small window of time when the ECN does not accept orders, if the EA generated by SQ attempts to delete a pending order it will fail, and it won’t them delete the order:

     

    2016.08.14 22:00:25.027    ‘946624’: deleting of pending order #9901877 sell stop 0.01 EURUSD at 1.11528 sl: 1.14488 tp: 1.11008 failed [Market is closed]

    2016.08.11 22:00:04.839    ‘946624’: deleting of pending order #9877449 buy stop 0.01 EURUSD at 1.11581 sl: 1.08621 tp: 1.12101 failed [Market is closed]

     

    There needs to be a retry mechanism for deleting the pending order.

     

    Thanks,

     

    Mike

    #138831
    Customer
    376 Posts

     In Ninjatrader the Strategy kills it self when this happens. So it is a problem for that platform as well.

    #138835
    Customer
    734 Posts

    Also “exit on Friday” seems to exit on Monday open. I’ve never mentioned it before because it tends to work out in my favor (gaps tend to be in the direction of Friday’s momentum).

    #138836
    Customer
    292 Posts

    My problem too. Exit on friday is exit on Thursday at 22.00; i had to turn off this option. Mikeyc same problem .

    #138838
    Moderator
    2349 Posts

    Hello,

    Friday exit should work correctly. What time do you have set with your EA?

    #201039
    FILIPE BONALDO ACERBI
    Customer
    30 Posts

    Hello,

    I have the same problem once a day at 22:00 broker time. I got the error “Market is closed”:

    2017.11.08 22:02:12.599
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:02:19 Order modified, StopLoss: 0, Profit Target: 0
    2017.11.08 22:02:12.599
    USDJPY D1 23.46 USDJPY.m,Daily: modify #175062574 sell stop 0.86 USDJPY.m at 111.617 sl: 112.141 tp: 108.668 ok
    2017.11.08 22:02:12.162
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:02:19 Setting SL/PT, SL: 112.141, PT: 108.668
    2017.11.08 22:02:12.162
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:02:19 Order opened: 175062574 at price:111.617
    2017.11.08 22:02:12.162
    USDJPY D1 23.46 USDJPY.m,Daily: open #175062574 sell stop 0.86 USDJPY.m at 111.617 ok
    2017.11.08 22:02:11.677
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:02:19 Opening order, direction: 5, price: 111.617, Ask: 113.893, Bid: 113.864
    2017.11.08 22:01:37.521
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:01:44 Error opening order: 132 : market is closed
    2017.11.08 22:01:37.396
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:01:44 Opening order, direction: 5, price: 111.617, Ask: 113.893, Bid: 113.864
    2017.11.08 22:01:03.677
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:01:12 Error opening order: 132 : market is closed
    2017.11.08 22:01:03.521
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:01:11 Opening order, direction: 5, price: 111.617, Ask: 113.893, Bid: 113.864
    2017.11.08 22:00:29.568
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:00:35 Error opening order: 132 : market is closed
    2017.11.08 22:00:29.365
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:00:35 Opening order, direction: 5, price: 111.617, Ask: 113.893, Bid: 113.864
    2017.11.08 21:59:55.349
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:00:03 Error opening order: 132 : market is closed
    2017.11.08 21:59:55.052
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:00:02 Opening order, direction: 5, price: 111.617, Ask: 113.893, Bid: 113.864
    2017.11.08 21:59:55.052
    USDJPY D1 23.46 USDJPY.m,Daily: 2017.11.09 00:00:02 Cannot close existing previous pending order with ticket: 174815678, reason: 132

    If we look to the history above, the EA made 4 attempts until successfully open the order 175062574. But, the problem are the failed attempts to change or close the previous order. In the example above, the EA tried to close without success the order 174815678. It tried once and failed, so I have an open order that should have been closed, but because this error, its still opened.

    I have to close the order 174815678 manually and restart the EA. When I did this, the EA opened the right order (see the attachment)

    I tried to solve this problem putting the function if(sqIsTradeAllowed() == 1) before the OrderDelete, but nothing happened:

    bool closePendingOrder() {

    int ticket = OrderTicket();

    if(sqIsTradeAllowed() == 1)  

    if(OrderDelete(ticket)) {

    lastDeletedOrderTicket = ticket;      return(true);   }

    return(false);}

    I think the solution is implement more attempts to close or change a order when it fail.

    What Can I do to solve this?

    #201067
    FILIPE BONALDO ACERBI
    Customer
    30 Posts

    I searched in the EA code all funtions that modify, delete e close orders. For this functions, I added the same logic that made retries to open orders when failed, which is described by openPosition() function. Today I get “market closed” error but the EA tried until successfully modify/delete/close the orders . If somebody has problem with market closed error, I attached the changed functions to make retries in closing, modifying or deleting orders. You need only replace the functions in EA code.

    Attachments:
    You must be logged in to view attached files.
    #201276
    Customer
    52 Posts

    Hi Filipe:

    I have a similar problem and was wondering if your modifications will resolve the issue. On an ECN account, the pending trade would get set by the EA, then before the modify pending order to set the SL and TP could be processed, the trade was activated. So the modify pending order failed because it is no longer pending, but activated. In this case, if the modify pending fails, I need the EA to check to see if the order was opened and if so, is the TP and SL set correctly. If not, set the TP and SL for the open order. If the attempts to set the TP/SL fail several times, then close the open order.

    Is that something that your modifications will do and if not, will you help me with code to do this? I would be happy to compensate you for your time.

    #201294
    FILIPE BONALDO ACERBI
    Customer
    30 Posts

    Hello Afhampton,

    I think if the EA make some retries to change the ST/TP for the opened order will work. For the opened stop/limit orders, I think that EA need test if the pending order is opened before try to close or change. If are opened, the EA will call start() function to manage the newly opened orders. It could be a solution. I attached the modified functions and you could try if it work with these modified functions that make retries and test if the pending order is open. Follow this steps:

    1- MAke a backup of “MT4Functions.inc” in C:\StrategyQuant\code\Mql_MT4.

    2 – Download the attached file rename and replace “MT4Functions.inc” in C:\StrategyQuant\code\Mql_MT4.

    3 – Export EA mql4 file again in SQ.

    4 – Test on demo account.

    If The EA fail to change/delete orders, it will make 60 attempts within 30 seconds each one until successfully change/delete the order. If not work, restore the backup.

     

    Attachments:
    You must be logged in to view attached files.
Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.