Closing more positions simultaneously

 
Hi there!

I'd like to close 3 open positions with the following code, but it closes just the first position. How can I close all of them?
My wrong code:
if ********something**********
    {
     if (OrderSelect(MyOrderTicket0, SELECT_BY_TICKET)==true)
     {
         if (OrderType() == OP_BUY) OrderClose(MyOrderTicket0,OrderLots(),Bid,1,CLR_NONE);
        if (OrderType() == OP_SELL) OrderClose(MyOrderTicket0,OrderLots(),Ask,1,CLR_NONE);
     }
     
    if (OrderSelect(MyOrderTicket1, SELECT_BY_TICKET)==true)
     {
        if (OrderType() == OP_BUY) OrderClose(MyOrderTicket1,OrderLots(),Bid,1,CLR_NONE);
         if (OrderType() == OP_SELL) OrderClose(MyOrderTicket1,OrderLots(),Ask,1,CLR_NONE);
     }
 
    if (OrderSelect(MyOrderTicket2, SELECT_BY_TICKET)==true)
     {
        if (OrderType() == OP_BUY) OrderClose(MyOrderTicket2,OrderLots(),Bid,1,CLR_NONE);
         if (OrderType() == OP_SELL) OrderClose(MyOrderTicket2,OrderLots(),Ask,1,CLR_NONE);
     }
     
    return(0);
    }
Thanks for helping!
 

parameter error?

OrderSelect(MyOrderTicket0, SELECT_BY_TICKET, MODE_TRADES)

 
phy:

parameter error?

OrderSelect(MyOrderTicket0, SELECT_BY_TICKET, MODE_TRADES)

Great day to phy, I sense your beautiful spirit in helping confused people like me in solving some challenges. I am Ayo, a new trader trying to build the simplest code that would exit all open trades and pending orders when a percentage of the starting balance is gained.
Some thing like :Close all pending orders, and open trades if Equity >= 1.001Initial Balance. Please can i find some help with this from any expert programmer? More profits to your accounts.please you can send the code straight to my email: ayoakorede@yahoo. com
Thanks.
 

Here is a little framework

double balance;
double equity;

int init(){
     balance = AccountBalance(); 
}

int start(){
   ...
   ...
   equity  = AccountEquity();
   if(equity >= balance*1.002){
      ... code for close all trades...
      ... verify all trades closed. if not closed handle the error
      balance = AccountBalance(); // new starting point for future trades
   }
   return(0);
}
 
phy:

Here is a little framework

double balance;
double equity;

int init(){
     balance = AccountBalance(); 
}
 





int start(){
   ...
   ...
   equity  = AccountEquity();
   if(equity >= balance*1.002){
      ... code for close all trades...
      ... verify all trades closed. if not closed handle the error
      balance = AccountBalance(); // new starting point for future trades
   }
   return(0);
}
Phy, you know I haven't tried it out, but I think you are a great man for your swift response.
Best Regards Ayo
 
61177:
phy:

Here is a little framework

double balance;
double equity;

int init(){
     balance = AccountBalance(); 
}
 





int start(){
   ...
   ...
   equity  = AccountEquity();
   if(equity >= balance*1.002){
      ... code for close all trades...
      ... verify all trades closed. if not closed handle the error
      balance = AccountBalance(); // new starting point for future trades
   }
   return(0);
}
Phy, I tried compiling it, but it didn't work! Is there a way I should go about it? Pls tell me in full because i am not a programmer
 

The above is "pseudocode", meaning, enough to give you an idea, but not meant to run "as is"

https://en.wikipedia.org/wiki/Pseudocode

If you are not a programmer, consider becoming one.

 
61177:
61177:
phy:

Here is a little framework

double balance;
double equity;

int init(){
     balance = AccountBalance(); 
}
 





int start(){
   ...
   ...
   equity  = AccountEquity();
   if(equity >= balance*1.002){
      ... code for close all trades...
      ... verify all trades closed. if not closed handle the error
      balance = AccountBalance(); // new starting point for future trades
   }
   return(0);
}
Thanks Phy, but i would appreciate if you could just write the complete code for me. if i start learning programming now, it is would take a life time b4 i understand the syntax..., talkless of writing a correct code.cheers

 

There are examples of "close all trades" in previous posts.

 
phy:

There are examples of "close all trades" in previous posts.

Phy, please could you just do me a favor of completing the good work you started by assisting me to write the complete code. I went through all i ones i saw but they were too complex for me to use and besides, they are meant to met different needs . The pseudocode you gave is absolutely similar to what i need.
Reason: