Download MetaTrader 5

[Error] OrderCloseTime return wrong

To add comments, please log in or register
kissmez
28
kissmez  

Hello everyone,

I'm thinking and tested for hours but i can't figure out this error

I have this scrips:

if (Solenh[i]==1 && OrderSelect(IDB_Tien[a[i]][0],SELECT_BY_TICKET)==true) // Right
                {                 
                    datetime Tgiandong=OrderCloseTime();
                    if (Tgiandong!=0)
                    {
                         while (1!=0)
                         {
                              OrderDelete(IDB_Tien[a[i]][1]);
                              OrderModify(IDS_Tien[a[i]][0],0,0,GiaS[a[i]][0],0);
                              int check=GetLastError();
                              if (check==4108 || check==1) break;
                         }
                         Sleep(500);
                         Solenh[i]=2;
                         OrderSelect(IDS_Tien[a[i]][0],SELECT_BY_TICKET);
                         Tgiandong=OrderCloseTime();
                         while (IDS_Tien[a[i]][Solenh[i]] <=0 && Tgiandong==0) 
                         {    
                              IDS_Tien[a[i]][Solenh[i]]= Lenhban(OP_SELLLIMIT,a[i],Solenh[i]);
                              if (IDS_Tien[a[i]][Solenh[i]]>0) break;
                         };
                         
                         if (Tgiandong != 0)
                         {                          
                              while (1!=0)
                              {
                                   OrderDelete(IDS_Tien[a[i]][Solenh[i]]);
                                   int check=GetLastError();
                                   if (check==4108) break;
                              };
                              //Reset();
                         };
                    }
                };

I'm tested that the problems at this line

datetime Tgiandong1=OrderCloseTime();

The OrderSelect before this line return true and I tested the orderticket on that is right. As you can see In begin, i have used OrderCloseTime and it works, but i don't know how i use it again then it doesn't work although the Order is closed.


I'm very happy if you can help me. Thank you so much

whroeder1
15917
whroeder1  
kissmez: The OrderSelect before this line return true and I tested the orderticket on that is right. As you can see In begin, i have used OrderCloseTime and it works, but i don't know how i use it again then it doesn't work although the Order is closed.
  1. How do you know that, you didn't bother to check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. How do you know that the order is closed? You just tried to modify it.
         OrderModify(IDS_Tien[a[i]][0],0,0,GiaS[a[i]][0],0);
         int check=GetLastError();
         if (check==4108 || check==1) break;
    }
    :
    OrderSelect(IDS_Tien[a[i]][0],SELECT_BY_TICKET);
    Tgiandong=OrderCloseTime();
    Check your return codes.
  3. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool).
  4. Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence. a[i] is meaningless
  5. Don't double post
kissmez
28
kissmez  
whroeder1:
  1. How do you know that, you didn't bother to check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  2. How do you know that the order is closed? You just tried to modify it.Check your return codes.
  3. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool).
  4. Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence. a[i] is meaningless
  5. Don't double post


Thanks for your reply;


1. I use Comment() Comand to check what its return.

2. As you can see i put the script in loop for, so that when the order is closed the OrderCloseTime will return value and i check it by compare with 0.

3. Thanks for your suggest ^^

4. I don't understand what you mean. Can you explain more?

5. Sorry for that ^^

whroeder1
15917
whroeder1  
kissmez: 4. I don't understand what you mean. Can you explain more?
What part of "use meaningful variable names ... a[i] is meaningless" is unclear?
To add comments, please log in or register