help to fix ea bug

 

hi,  firstly wish all of you happy holiday!


i found this ea online forum, and it has potential. this ea will place pending orders. but most of times those pending orders can not deleted by its logics.

 this ea will pop up message  deleted pending orders  fail.  so it always result those  pending orders  trigger.   

does any experience coders to  check what problem of this ea, and point me to correct this bug.



 thanks.

Files:
TrendStat.mq4  66 kb
 
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. void DeletePendingTrades(){
       :   
       for (int cc = 0; cc <= OrdersTotal(); cc++)
    
    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
    2. 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.)
    3. 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
    4. 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.

  3. If there are n orders they are numbered zero to n-1.

  4. int start(){
    :
       if (OrdersTotal() == 0){ TicketNo = -1; }
    Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum

  5. Start using the new Event Handling Functions.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference

  6.    if (OldBars != Bars){
          OldBars = Bars;
    
    For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.
    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
              New candle - MQL4 and MetaTrader 4 - MQL4 programming forum

  7. Do you really expect us to debug your thousands of lines of code? Use the debugger or print out your variables, including _LastError and find out why.
 
thanks for point me,  i am sorry i post the thread in wrong section.. .    i will try to understand all these  information which  you prodvide for me.