Help with order close (for smoknfx) - page 2

 
?
 
void CloseMarketOrders(int ticketsArray[][2], double lotsArray[])
   {  
//----
   int i,size=ArrayRange(ticketsArray,0);
   if (size==0) return;
   
   int ticket,type;
   double lots;
   bool res;
   
   int total=OrdersTotal(); 
   
   for (i=0;i<size;i++)
      {
      if (subNetLots()>=LotsExposure)
         {
          ticket = ticketsArray[i][0];
          type   = ticketsArray[i][1];
          lots   = lotsArray[i];
          RefreshRates(); // íà âñÿêèé ñëó÷àé îáíîâèì ñâåäåíèÿ î ðûíî÷íîì îêðóæåíèè
                
          // áëîê çàêðûòèÿ ïîêóïîê
          if (type==OP_BUY)
            {
             res = OrderClose(ticket,lots,Bid,Slippage,Orange);
             if (!res)
               {
                Print("Íå óäàëîñü çàêðûòü îðäåð â ïîêóïêó #",ticket,"!  Îøèáêà ¹",GetLastError());
                //  äàëüíåéøàÿ îáðàáîòêà îøèáêè, íàïèñàòü ñàìîñòîÿòåëüíî
               }
             }
              
          //  áëîê çàêðûòèÿ ïðîäàæ
          if (type==OP_SELL)
            {
             res = OrderClose(ticket,lots,Ask,Slippage,Orange);
             if (!res)
               {
                Print("Íå óäàëîñü çàêðûòü îðäåð â ïðîäàæó #",ticket,"!  Îøèáêà ¹",GetLastError());
                //  äàëüíåéøàÿ îáðàáîòêà îøèáêè, íàïèñàòü ñàìîñòîÿòåëüíî
               }
            }
         }
      } 
//----
   return;
   }
I added if (subNetLots()>=LotsExposure) to the close orders loop you will need a extern double LostsExposure at the begining of the code
 
or I may have mis-understood what you were after.
 
MINTA:

Hi,

I have the following problem:

I use template from here: https://www.mql5.com/en/articles/1514


You ask for help but you make life hard for those that might want to help you . . . why didn't you fix all the comments and the Printed messages ? it's not hard to do . . . I have just done it.

Files:
 
Ickyrus:
I added if (subNetLots()>=LotsExposure) to the close orders loop you will need a extern double LostsExposure at the begining of the code


I think you have modded the wrong function, it's a 2 stage process, one function selects which tickets are to be closed based on the users criteria, another function then takes that list ( stored in an array ) and closes the orders listed.

I think you should have modded PrepareTicketsToClose()

 
I thought about that but decided on the most direct route as it was easier than modifying the array code - I've printed the article out. To be honest at this point in time I'm not sure what the PrepareTicketsToClose() was doing or why.
 
MINTA:

smoknfx: I will try to explain in details:

What NET_LOTS do:

Attach iExposure indicator (from custom indicators) to chart, and open 10 orders - 5 Buy and 5 Sell. So you have 0 NET_LOTS.

Now if EA code close 1 buy order then NET_LOTS get: -0.1 NET_LOTS. Suppose that I do not want more exposure then -0.2 NET_LOTS, but EA have signal to close 4 buy orders. Before closing them NET_LOTS is -0.1, so EA makes

an array where NET_LOTS value is -0.1 NET_LOTS, and If EA does not recalculate NET_LOTS after each closed order it will close all 4 buy orders ignoring exposure rules for ABS(0.2) NET_LOTS exposure.

That is what EA now does and what must be fixed.


But I did read this!
 
Ickyrus:
I thought about that but decided on the most direct route as it was easier than modifying the array code - I've printed the article out. To be honest at this point in time I'm not sure what the PrepareTicketsToClose() was doing or why.


From what I have seen . . . there is no need to modify the array code, the code is written as a template so you can add your own code to select which orders are to be closed . . . then call CloseMarketOrders and it closes the orders you have selected.

In the PrepareTicketsToClose() function the user would add code to select Orders that he wants to keep, (continue is used to skip to the next ticket) I think the OP has added code for Orders that he wants to close . . .

The file I attached above has all (except one or two) comments and messages in English so it might help.