Download MetaTrader 5

Can´t find the reason why OrderModify Error 4051 is happening - page 2

To add comments, please log in or register
Hundreds of articles will help you to create a trading robot. Come and read them!
Sam
6
Sam 2014.12.09 15:01  

Thank you guys for the quick replies..

 I have change the FOR loop to:

  v_cnt = OrdersTotal();

for(int pos=v_cnt-1;pos>=0;pos--) { 

And results changed with no errors.. and got the selected order correctly :)

2014.12.09 16:31:23.640 2014.03.28 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 4
2014.12.09 16:31:23.640 2014.03.28 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 1 Total Trades : 4
2014.12.09 16:31:23.640 2014.03.28 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 2 Total Trades : 4
2014.12.09 16:31:23.640 2014.03.28 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 3 Total Trades : 4
2014.12.09 16:31:23.640 2014.03.28 00:00  TESTIN~1 EURGBP-,Daily: open #9 buy 0.10 EURGBP- at 0.82709 tp: 0.83184 ok
2014.12.09 16:31:23.640 2014.03.28 00:00  TESTIN~1 EURGBP-,Daily: Alert:              ###   --  New BAR  (DOWN) --   ### : 5
2014.12.09 16:31:23.375 2014.03.27 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 3
2014.12.09 16:31:23.375 2014.03.27 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 1 Total Trades : 3
2014.12.09 16:31:23.375 2014.03.27 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 2 Total Trades : 3
2014.12.09 16:31:23.375 2014.03.27 00:00  TESTIN~1 EURGBP-,Daily: open #8 buy 0.10 EURGBP- at 0.83115 tp: 0.83627 ok
2014.12.09 16:31:23.375 2014.03.27 00:00  TESTIN~1 EURGBP-,Daily: Alert:              ###   --  New BAR  (DOWN) --   ### : 4
2014.12.09 16:31:23.125 2014.03.26 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 2
2014.12.09 16:31:23.125 2014.03.26 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 1 Total Trades : 2
2014.12.09 16:31:23.125 2014.03.26 00:00  TESTIN~1 EURGBP-,Daily: open #7 buy 0.10 EURGBP- at 0.83639 tp: 0.83903 ok
2014.12.09 16:31:23.125 2014.03.26 00:00  TESTIN~1 EURGBP-,Daily: Alert:              ###   --  New BAR  (DOWN) --   ### : 3
2014.12.09 16:31:22.984 2014.03.25 16:12  Tester: take profit #5 at 0.83421 (0.83415 / 0.83421)
2014.12.09 16:31:22.984 2014.03.25 16:11  Tester: take profit #6 at 0.83429 (0.83423 / 0.83429)
2014.12.09 16:31:22.796 2014.03.25 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 3
2014.12.09 16:31:22.796 2014.03.25 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 1 Total Trades : 3
2014.12.09 16:31:22.796 2014.03.25 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 2 Total Trades : 3
2014.12.09 16:31:22.796 2014.03.25 00:00  TESTIN~1 EURGBP-,Daily: open #6 sell 0.10 EURGBP- at 0.83859 tp: 0.83429 ok
2014.12.09 16:31:22.796 2014.03.25 00:00  TESTIN~1 EURGBP-,Daily: Alert:           ###   --  New BAR (UP) --   ### : 4
2014.12.09 16:31:22.515 2014.03.24 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 2
2014.12.09 16:31:22.515 2014.03.24 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 1 Total Trades : 2
2014.12.09 16:31:22.515 2014.03.24 00:00  TESTIN~1 EURGBP-,Daily: open #5 sell 0.10 EURGBP- at 0.83601 tp: 0.83421 ok
2014.12.09 16:31:22.515 2014.03.24 00:00  TESTIN~1 EURGBP-,Daily: Alert:           ###   --  New BAR (UP) --   ### : 3
2014.12.09 16:31:22.328 2014.03.21 10:38  Tester: take profit #4 at 0.83649 (0.83649 / 0.83655)
2014.12.09 16:31:22.265 2014.03.21 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 0 Total Trades : 2
2014.12.09 16:31:22.265 2014.03.21 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 1 Total Trades : 2
2014.12.09 16:31:22.265 2014.03.21 00:00  TESTIN~1 EURGBP-,Daily: open #4 buy 0.10 EURGBP- at 0.83474 tp: 0.83649 ok
2014.12.09 16:31:22.265 2014.03.21 00:00  TESTIN~1 EURGBP-,Daily: Alert:              ###   --  New BAR  (DOWN) --   ### : 2
2014.12.09 16:31:22.078 2014.03.20 13:47  Tester: take profit #1 at 0.83415 (0.83409 / 0.83415)
2014.12.09 16:31:21.921 2014.03.20 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 0 Total Trades : 2
2014.12.09 16:31:21.921 2014.03.20 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 0 - Position : 1 Total Trades : 2
2014.12.09 16:31:21.921 2014.03.20 00:00  TESTIN~1 EURGBP-,Daily: open #3 buy 0.10 EURGBP- at 0.83624 tp: 0.83968 ok
2014.12.09 16:31:21.921 2014.03.20 00:00  TESTIN~1 EURGBP-,Daily: Alert:              ###   --  New BAR  (DOWN) --   ### : 1
2014.12.09 16:31:21.875 2014.03.19 22:26  Tester: take profit #2 at 0.83607 (0.83601 / 0.83607)
2014.12.09 16:31:21.546 2014.03.19 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 0 Total Trades : 2
2014.12.09 16:31:21.546 2014.03.19 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 1 Total Trades : 2
2014.12.09 16:31:21.546 2014.03.19 00:00  TESTIN~1 EURGBP-,Daily: open #2 sell 0.10 EURGBP- at 0.83967 tp: 0.83607 ok
2014.12.09 16:31:21.546 2014.03.19 00:00  TESTIN~1 EURGBP-,Daily: Alert:           ###   --  New BAR (UP) --   ### : 2
2014.12.09 16:28:48.109 2014.03.18 00:00  TESTIN~1 EURGBP-,Daily: On Success: - Type : 1 - Position : 0 Total Trades : 1
2014.12.09 16:28:48.109 2014.03.18 00:00  TESTIN~1 EURGBP-,Daily: open #1 sell 0.10 EURGBP- at 0.83672 tp: 0.83415 ok
2014.12.09 16:28:48.109 2014.03.18 00:00  TESTIN~1 EURGBP-,Daily: Alert:           ###   --  New BAR (UP) --   ### : 1
2014.12.09 16:28:48.093 TESTIN~1 inputs: BuyLots=0.1; SellLots=0.1; Barsize_min=20; Barsize_max=60; Spread=10; Take_profit_level=100; high_low=1; 

 

I am wondering if I can use the same for loop for an inner FOR loops inside the Main FOR loop, one FOR loop for buy orders and one FOR loop for sell orders (All inside the main loop)..

So that I can modify the takeprofit level depending on market conditions that I set.

The main issue that I am going to be having, how to identify the closed orders while still going through the main loop?

Let say I have 5 orders open, and by the time the code is going through the second order the 4th order got closed because simply it reached takeprofit level, now the total order has changed to 4 order instead of 5. So the order count is not in sync anymore with the orderselect!

Simply I just want to modify the orders that are still open. 

 

Kind regards,

12
To add comments, please log in or register