Help: Why The EA does not close a trade - page 6

 
RaptorUK:

You don't need the Function at all . . . . . . get rid of it.



Hello Raptor,

I need this function since the EA is quit complex one, and I use this function with many versions od closing conditions.

I hope you understand me.

Y.

 
onewithzachy:

Let's do it again part 2 :(


Thank you onewithzachy, but as I responsed befor, I need this function for close with many versions of conditions, So it is too complex to put the closing code commands within each condition, especially that it is not a one code command.

Thanks,

Y.

 
RaptorUK:

Do this . . . ( repeated from here: https://www.mql5.com/en/forum/139543 )

. . . and you don't need the Function at all.


Raptor, I need this function to overcome REQUATE situations, as you can see.

Y.

 
onewithzachy:

@ RaptorUK, I'm considering wearing crash helmet so at least I can think well ahead than I'm currently now. Isn't that, those drivers do, think well ahead ? :D


@ skaboy, I'm asking politely here, if you don't mind, would you please use SRC button to post your code. We've been asking that too many times in this thread alone.

@ crossy, It's almost a week since your first post. Surely I understand that you may not have a clear head now dealing with 4000 lines, right now I myself have mine here too. If you still don't understand it, - ehm - you can ask us to write that Close code for you. However you still have to write the code even just a little - and show us. :D, RaptorUK's code just above there is more direct than mine, think about it and then you can move on with your EA.

With the way you write code here - too many unnecessary repeated code - you should have a little worry with your 4000 lines of code that it may slow down your EA and makes your EA miss a tick. It's okay to miss a couple point, however what happen if you miss like 10 pips away ? and probably your 4000 lines may still can be reduced to just 400 lines. Who knows ?, your EA, become more lighter and faster. :D


Thank you onewithzachy,

My EA has this small mistake, which is:

1) It closes the relevante ticket and it looks for it too.

2) This mistake does not appear every close order, and sometimes it work good.

aboy the other 3,950 code lines - they work very good.

I attach the relevand code lines, again.

Y.

...
   for(int cnt = OrdersTotal()-1; cnt >= 0 ; cnt--) 
   {
      CodeY = false;
      if ( OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) )
      {
         CodeY    = true;
         OrderS   = OrderSymbol();
         OrderT   = OrderTicket();
         OrderM   = OrderMagicNumber();
         OrderTyp = OrderType();
         OrderL   = OrderLots();
      }   
      if ( CodeY && OrderS == Pair1 && OrderTyp == OP_BUY && OrderM == MAG &&.... )
    
         CLOSE_Single_P(Pair1,"LONG",OrderT,OrderL);

//-----------------------------------------------+
void CLOSE_Single_P(string SYMB, string TREN, int TICKET, double LOTT)
{
   double PRC;
   bool Check = false;

   for ( int cntt=0; cntt<20000; cntt++ )
   {
      if ( Check )
      {
         Check_Ini();
         return;
      }
      Check = false;
      if ( TREN == "LONG" )
         PRC = MarketInfo(SYMB,MODE_BID);
      else
      if ( TREN == "SHORT" )
         PRC = MarketInfo(SYMB,MODE_ASK);
         
      Check = OrderClose(TICKET,LOTT,PRC,Slippage,Yellow);
   }
   return;
}
//-----------------------------------------------+
 
crossy:



Hello Raptor,

I need this function since the EA is quit complex one, and I use this function with many versions od closing conditions.

I hope you understand me.

Y.

I don't think you understand the code you have copy and pasted from somewhere else . . . and no it's not for requotes . . . you don't even check if an error you get is a requote.
 
RaptorUK:
I don't think you understand the copy you have copy and pasted from somewhere else . . . and no it's not for requotes . . . you don't even check if an error you get is a requote.


No Raptor, The error I got was: The ticket number was not found. And I can tell you that the reson is The ticket was already closed one second before.

I do not understand how it closes the ticket and continuing searching it...

 
crossy:


I do not understand how it closes the ticket and continuing searching it...

It's because of the loop that I said you don't need . . . in the function that you don't need.

"Why do you have a loop in the Close_Single_P Function ? " from 3rd post on page 1

"why the loop ?" from page 4, 2nd post

 

Am I wrong or this function never closes SHORT orders?

...
   for(int cnt = OrdersTotal()-1; cnt >= 0 ; cnt--) 
   {
      CodeY = false;
      if ( OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) )
      {
         CodeY    = true;
         OrderS   = OrderSymbol();
         OrderT   = OrderTicket();
         OrderM   = OrderMagicNumber();
         OrderTyp = OrderType();
         OrderL   = OrderLots();
      }   
      if ( CodeY && OrderS == Pair1 && OrderTyp == OP_BUY && OrderM == MAG &&.... )
    
         CLOSE_Single_P(Pair1,"LONG",OrderT,OrderL);
                               ^^^^ - You always pass LONG to variable TREN, so variable PRC (below) is always equal taken from LONG, but NEVER from SHORT.

//-----------------------------------------------+
void CLOSE_Single_P(string SYMB, string TREN, int TICKET, double LOTT)
{
   double PRC;
   bool Check = false;

   for ( int cntt=0; cntt<20000; cntt++ )
   {
      if ( Check )
      {
         Check_Ini();
         return;
      }
      Check = false;
      if ( TREN == "LONG" )
         PRC = MarketInfo(SYMB,MODE_BID);
      else
      if ( TREN == "SHORT" )
         PRC = MarketInfo(SYMB,MODE_ASK);
         ^^^   Never executed
         
      Check = OrderClose(TICKET,LOTT,PRC,Slippage,Yellow);
   }
   return;
}
//-----------------------------------------------+
 
Waidas:

Am I wrong or this function never closes SHORT orders?


Waidas, You rigth. But this is just a small piece from the EA, which closes LONG and SHORT.

Thanks.

 
RaptorUK:

It's because of the loop that I said you don't need . . . in the function that you don't need.

"Why do you have a loop in the Close_Single_P Function ? " from 3rd post on page 1

"why the loop ?" from page 4, 2nd post


Raptor, You were rigth, and I cacled the loops, so the function is now without any loop.

I attach it again here.

Y.

...
   for(int cnt = OrdersTotal()-1; cnt >= 0 ; cnt--) 
   {
      CodeY = false;
      if ( OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) )
      {
         CodeY    = true;
         OrderS   = OrderSymbol();
         OrderT   = OrderTicket();
         OrderM   = OrderMagicNumber();
         OrderTyp = OrderType();
         OrderL   = OrderLots();
      }   
      if ( CodeY && OrderS == Pair1 && OrderTyp == OP_BUY && OrderM == MAG &&.... )
    
         CLOSE_Single_P(Pair1,"LONG",OrderT,OrderL);

//-----------------------------------------------+
void CLOSE_Single_P(string SYMB, string TREN, int TICKET, double LOTT)
{
   double PRC;
   bool Check = false;

   for ( int cntt=0; cntt<20000; cntt++ )
   {
      if ( Check )
      {
         Check_Ini();
         return;
      }
      if ( TREN == "LONG" )
         PRC = MarketInfo(SYMB,MODE_BID);
      else
      if ( TREN == "SHORT" )
         PRC = MarketInfo(SYMB,MODE_ASK);
         
      Check = OrderClose(TICKET,LOTT,PRC,Slippage,Yellow);
   }
   return;
}
//-----------------------------------------------+