EA not Closing Opposite Order Once active and not modifying Stop of active order

To add comments, please log in or register
cgeach
9
cgeach  

Hi


Looking for assistance with EA.  I am new to MQL4 code and have done what i can but can't work out what i have missed or done wrong.


Orders are opening as they should and closing at expiration time.  


Orders are not deleting on activation of opposite order and order modify for stop is not working.


Can i please get some assistence.  (could be something simple and dumb)

 few order should be checked and possible data loss errors im trying to work out as well.

Files:
MyEA2.mq4 5 kb
whroeder1
17944
whroeder1  
  1.    int totalorders = OrdersTotal();
        for(int j=0;j<totalorders;j++){
    In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading,) while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing:
    1. For non-FIFO (US brokers,) (or the EA only opens one order per symbol,) you can simply count down in a position loop, and you won't miss orders. Get in the habit of always counting down.
                Loops and Closing or Deleting Orders - MQL4 and MetaTrader 4 - MQL4 programming forum
      For FIFO (US brokers,) and you (potentially) process multiple orders per symbol, you must count up and on a successful operation, reprocess all positions (set index to -1 before continuing.)
    2. and check OrderSelect in case earlier positions were deleted.
                What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
                Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    3. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use the Predefined Variables (Bid/Ask) or OrderClosePrice() instead, on the next order/server call.

  2.      if ((Hour()==10) && (Minute()==0) && (Seconds()==01))
    What if there is no tick that exact second? Code fails. What if there is multiple ticks? Multiple orders, code fails

  3. ticket1 = OrderSend( Symbol(),OP_BUYSTOP,Lots,t1, 3,sl1,tp1,"BUY PLACED",Magic,0,Blue);
    
    OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TS*Point,OrderTakeProfit(),0,Green);
    Check your return codes for errors, report them and you would know why. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

cgeach
9
cgeach  

Thanks for the info..


Will look into it and hopefully work it out :)

To add comments, please log in or register