How to take only one action on lots per condition???

 

hi

i would like to divide the Order Lots (Praticl close)when the Profit  reaches certain level but the problem that it continues to divide , need help to know how to break the loop and don't repeat itself

 //-------------------------------------------------

 void PartialClose()

{  

    

    for(int i = OrdersTotal()-1; i >= 0; i--){

   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==false)continue;

   if( Magic == OrderMagicNumber() )

 {

int Tk=100;

     

         if(OrderType() == OP_BUY){

            if(Bid > OrderOpenPrice()+(Tk*Point)){

               OrderClose(OrderTicket(), OrderLots()/2, Bid, 3, Red);

            }

         }

         if(OrderType() == OP_SELL){

            if(Ask< OrderOpenPrice()-(Tk*Point)){

               OrderClose(OrderTicket(),OrderLots()/2, Ask, 3, Red);

            }

         }

      }

   }


 

 

i will appreciate your help 

 
micoul81: i would like to divide the Order Lots (Praticl close)when the Profit  reaches certain level but the problem that it continues to divide , need help to know how to break the loop and don't repeat itself
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. You can't use OrderLots()/2 because that is not a multiple of LotStep, and you can't close or have remaining less than MinLot. See my code
  3. You are only checking if price may trigger a partial close. You aren't checking if you have already done it.
    • Set a flag in persistent storage (files, global variables w/ flush)
    • I move SL to BE+1 before the partial close. That way I know that I already did it.
    • Open two orders.
 

Sorry for number 1

2 and 3 still complicated for me

What's the meaning of BE+1 

 

can't handle it 

 

Q: What's the meaning of BE+1 ?

A: Breakeven + 1

 

thanks deysmacro

 
it continue to divide lots
 
  void PartialClose()
{  
   double Lotstep = MarketInfo(Symbol(), MODE_LOTSTEP);
   int x = 0; if(Lotstep == 0.01) x = 2; else x = 1;
    
    for(int i = OrdersTotal()-1; i >= 0; i--){
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==false)continue;
   if( Magic == OrderMagicNumber() )
 {
int Tk=100;
double LOTS = OrderLots();
double Dividelot = NormalizeDouble(LOTS * 0.5, x);
     
         if(OrderType() == OP_BUY){
            if(Bid > OrderOpenPrice()+(Tk*Point)){
               OrderClose(OrderTicket(), Dividelot*2, Bid, 3, Red);
            }
         }
         if(OrderType() == OP_SELL){
            if(Ask< OrderOpenPrice()-(Tk*Point)){
               OrderClose(OrderTicket(),Dividelot*2, Ask, 3, Red);
            }
         }
      }
   }

}
 
 

any help please to solve this problem , still can't handle it

 

You need to do something like this as suggested by WHRoeder

         if(OrderType() == OP_BUY && OrderStopLoss()<OrderOpenPrice()){
            if(Bid > OrderOpenPrice()+(Tk*Point)){
               {
               OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+Point,OrderTakeProfit(),0,clrNONE );
               OrderClose(OrderTicket(), Dividelot*2, Bid, 3, Red);
               }
            }
         }

 Not tested and checking success of OrderModify and OrderClose required

 
GumRai:

You need to do something like this as suggested by WHRoeder

 Not tested and checking siccess of OrderModify and OrderClose required

  void PartialClose()
{  
   double Lotstep = MarketInfo(Symbol(), MODE_LOTSTEP);
   int x = 0; if(Lotstep == 0.01) x = 2; else x = 1;
    
    for(int i = OrdersTotal()-1; i >= 0; i--){
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))continue;
   if( Magic == OrderMagicNumber() )
 {
int Tk=100;
double LOTS = OrderLots();
double Dividelot = NormalizeDouble(LOTS * 0.5, x);
     
         if(OrderType() == OP_BUY&& OrderStopLoss()<OrderOpenPrice()){
            if(Bid > OrderOpenPrice()+(Tk*Point)){
            OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+50*Point,0,0,clrNONE );
               OrderClose(OrderTicket(), Dividelot*2, Bid, 3, Red);
            }
         }
         if(OrderType() == OP_SELL&& OrderStopLoss()>OrderOpenPrice()){
          
            if(Ask< OrderOpenPrice()-(Tk*Point)){
               OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()-50*Point,0,0,clrNONE );
               OrderClose(OrderTicket(),Dividelot*2, Ask, 3, Red);
            }
         }
      }
   }

}
 
 I follow your instruction but it still doesn't work
 
micoul81:
 I follow your instruction but it still doesn't work

What do you mean "it still doesn't work"?

What doesn't work?