How to Fix error [Market is closed] error = 132

I make an EA, on D1 timeframe, sometimes when Open Order or Pending Order Error: failed [Market is closed] error = 132

I know Market is Closed can be caused by various things, but as we know, that the EA is run if there is a new candle that is formed so the EA certainly will not be run if it is a holiday, but the problem occurred at the beginning of the day.

  1. When a new Candle is formed, when the broker opens at the new day, Hour () == 0, Market at Low volume so that the order cannot be opened.
    2… Some brokers limit in the new Day, can open an order after 5-30 minutes.

The question:

  1. How do I deal with Market is Closed, I run EA on Timeframe D1, For example for the
    algorithm if I find Pinbar on D1 , if not executed it will be a long time waiting for the
    opportunity come again, maybe a few days or even weeks.

  2. My idea is that if I can use (Repeat Order or Loop) until Market Open (maybe after 5- 30
    minutes) and can accept order, can Repeat be run on Timeframe D1,
    to execute Repeat for up to 5 minutes to 30 minutes after the market open.
    How syntax the Repeat Order?

  3. I don’t need a way to check Market is Closed but rather how orders ensure can be executed.

Here are some examples of Market is Closed Errors in some Pairs, at beginning of the Day

2019.12.10 05:00:01.644 ‘xxx20xxxx’: order sell 0.09 GBPCAD opening at market sl: 1.74776 tp: 1.70923 failed [Market is closed]
2019.12.10 05:00:01.644 ‘xxx20xxxx’: pending order sell limit 0.09 GBPCAD at 1.73973 sl: 1.74776 tp: 1.71013
2019.12.10 05:00:01.816 ‘xxx20xxxx’: modification of order #1132350109 sell 0.11 EURUSD at 1.10807 sl: 1.10791 tp: 1.07807 -> sl: 1.10774 tp: 1.07807 failed [Market is closed]
2019.12.10 05:00:01.832 ‘xxx20xxxx’: modify order #1132350110 sell 0.11 EURUSD at 1.10900 sl: 1.10792 tp: 1.07897 -> sl: 1.10774 tp: 1.07897
2019.12.10 05:00:01.941 ‘xxx20xxxx’: order sell limit 0.09 GBPCAD opening at 1.73973 sl: 1.74776 tp: 1.71013 failed [Market is closed]
2019.12.10 05:00:01.941 ‘xxx20xxxx’: order sell market 0.09 GBPUSD sl: 1.31809 tp: 1.28383
2019.12.10 05:00:01.941 ‘xxx20xxxx’: pending order sell limit 0.09 GBPCAD at 1.74013 sl: 1.74776 tp: 1.71013
2019.12.10 05:00:02.066 ‘xxx20xxxx’: modification of order #1132350110 sell 0.11 EURUSD at 1.10900 sl: 1.10792 tp: 1.07897 -> sl: 1.10774 tp: 1.07897 failed [Market is closed]
2019.12.10 05:00:02.066 ‘xxx20xxxx’: modify order #1132367977 sell 0.15 EURUSD at 1.10901 sl: 1.10796 tp: 1.07908 -> sl: 1.10774 tp: 1.07908
2019.12.10 05:00:02.207 ‘xxx20xxxx’: order sell limit 0.09 GBPCAD opening at 1.74013 sl: 1.74776 tp: 1.71013 failed [Market is closed]
2019.12.10 05:00:02.207 ‘xxx20xxxx’: order sell 0.09 GBPUSD opening at market sl: 1.31809 tp: 1.28383 failed [Market is closed]
2019.12.10 05:00:02.207 ‘xxx20xxxx’: modification of order #1132367977 sell 0.15 EURUSD at 1.10901 sl: 1.10796 tp: 1.07908 -> sl: 1.10774 tp: 1.07908 failed [Market is closed]
2019.12.10 05:00:02.207 ‘xxx20xxxx’: pending order sell limit 0.06 GBPCAD at 1.74123 sl: 1.74776 tp: 1.70923
2019.12.10 05:00:02.207 ‘xxx20xxxx’: pending order sell limit 0.06 GBPUSD at 1.31433 sl: 1.31809 tp: 1.28473
2019.12.10 05:00:02.207 ‘xxx20xxxx’: modify order #1132367978 sell 0.15 EURUSD at 1.10958 sl: 1.10794 tp: 1.07998 -> sl: 1.10774 tp: 1.07998
2019.12.10 05:00:02.441 ‘xxx20xxxx’: order sell limit 0.06 GBPCAD opening at 1.74123 sl: 1.74776 tp: 1.70923 failed [Market is closed]
2019.12.10 05:00:02.457 ‘xxx20xxxx’: modification of order #1132367978 sell 0.15 EURUSD at 1.10958 sl: 1.10794 tp: 1.07998 -> sl: 1.10774 tp: 1.07998 failed [Market is closed]
2019.12.10 05:00:02.457 ‘xxx20xxxx’: order sell limit 0.06 GBPUSD opening at 1.31433 sl: 1.31809 tp: 1.28473 failed [Market is closed]
2019.12.10 05:00:02.457 ‘xxx20xxxx’: pending order sell limit 0.06 GBPCAD at 1.74203 sl: 1.74776 tp: 1.71013
2019.12.10 05:00:02.457 ‘xxx20xxxx’: modify order #1132367979 sell 0.15 EURUSD at 1.11050 sl: 1.10794 tp: 1.07998 -> sl: 1.10774 tp: 1.07998
2019.12.10 05:00:02.457 ‘xxx20xxxx’: pending order sell limit 0.09 GBPUSD at 1.31473 sl: 1.31809 tp: 1.28473
2019.12.10 05:00:02.691 ‘xxx20xxxx’: order sell limit 0.06 GBPCAD opening at 1.74203 sl: 1.74776 tp: 1.71013 failed [Market is closed]
2019.12.10 05:00:02.691 ‘xxx20xxxx’: modification of order #1132367979 sell 0.15 EURUSD at 1.11050 sl: 1.10794 tp: 1.07998 -> sl: 1.10774 tp: 1.07998 failed [Market is closed]
2019.12.10 05:00:02.691 ‘xxx20xxxx’: order sell limit 0.09 GBPUSD opening at 1.31473 sl: 1.31809 tp: 1.28473 failed [Market is closed]
2019.12.10 05:00:02.691 ‘xxx20xxxx’: pending order sell limit 0.06 GBPCAD at 1.74263 sl: 1.74776 tp: 1.71013
2019.12.10 05:00:02.691 ‘xxx20xxxx’: modify order #1132367981 sell 0.11 EURUSD at 1.11000 sl: 1.10794 tp: 1.07998 -> sl: 1.10774 tp: 1.07998
2019.12.10 05:00:02.691 ‘xxx20xxxx’: pending order sell limit 0.09 GBPUSD at 1.31583 sl: 1.31809 tp: 1.28383
2019.12.10 05:00:02.957 ‘xxx20xxxx’: order sell limit 0.06 GBPCAD opening at 1.74263 sl: 1.74776 tp: 1.71013 failed [Market is closed]
2019.12.10 05:00:02.957 ‘xxx20xxxx’: modification of order #1132367981 sell 0.11 EURUSD at 1.11000 sl: 1.10794 tp: 1.07998 -> sl: 1.10774 tp: 1.07998 failed [Market is closed]
2019.12.10 05:00:02.957 ‘xxx20xxxx’: order sell limit 0.09 GBPUSD opening at 1.31583 sl: 1.31809 tp: 1.28383 failed [Market is closed]
2019.12.10 05:00:02.957 ‘xxx20xxxx’: pending order sell limit 0.06 GBPCAD at 1.74343 sl: 1.74776 tp: 1.71013
2019.12.10 05:00:02.957 ‘xxx20xxxx’: pending order sell limit 0.06 GBPUSD at 1.31663 sl: 1.31809 tp: 1.28473
2019.12.10 05:00:03.175 ‘xxx20xxxx’: order sell limit 0.06 GBPCAD opening at 1.74343 sl: 1.74776 tp: 1.71013 failed [Market is closed]
2019.12.10 05:00:03.175 ‘xxx20xxxx’: order sell limit 0.06 GBPUSD opening at 1.31663 sl: 1.31809 tp: 1.28473 failed [Market is closed]
2019.12.10 05:00:03.207 ‘xxx20xxxx’: pending order sell limit 0.06 GBPCAD at 1.74573 sl: 1.74776 tp: 1.71013
2019.12.10 05:00:03.207 ‘xxx20xxxx’: pending order sell limit 0.09 GBPUSD at 1.31723 sl: 1.31809 tp: 1.28473
2019.12.10 05:00:03.394 ‘xxx20xxxx’: order sell limit 0.06 GBPCAD opening at 1.74573 sl: 1.74776 tp: 1.71013 failed [Market is closed]
2019.12.10 05:00:03.394 ‘xxx20xxxx’: order sell limit 0.09 GBPUSD opening at 1.31723 sl: 1.31809 tp: 1.28473 failed [Market is closed]
2019.12.10 05:00:03.425 ‘xxx20xxxx’: pending order sell limit 0.06 GBPUSD at 1.31803 sl: 1.31809 tp: 1.28473
2019.12.10 05:00:03.613 ‘xxx20xxxx’: order sell limit 0.06 GBPUSD opening at 1.31803 sl: 1.31809 tp: 1.28473 failed [Market is closed]

Thank You.

Just for info, the same EA at the same broker, on the same day and hour can run on a Demo Account, maybe the demo account does not have a Real Volume Order Thx