English

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

 Moderator3423 GumRai 2014.11.23 22:46 #   micoul81: now it doesn't divide the lotWhy do you divide the lot and then multiply it by 2?`OrderClose(OrderTicket(), Dividelot*2, Bid, 3, Red);`
 12 micoul81 2014.11.27 00:56 #   ```  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=10; double LOTS = OrderLots(); double Dividelot = NormalizeDouble(LOTS * 0.5, x);               if(OrderType() == OP_BUY){             if(Bid > OrderOpenPrice()+(Tk*Point)){                OrderClose(OrderTicket(), Dividelot, Bid, 3, Red);             }          }          if(OrderType() == OP_SELL){             if(Ask< OrderOpenPrice()-(Tk*Point)){                OrderClose(OrderTicket(),Dividelot, Ask, 3, Red);             }          }       }    } } ``` Sorry it's an error when i paste the code , still have the same problem
 13008 WHRoeder 2014.11.27 15:22 #   micoul81: it continue to divide lotsmicoul81:  Sorry it's an error when i paste the code , still have the same problem```int x = 0; if(Lotstep == 0.01) x = 2; else x = 1; double Dividelot = NormalizeDouble(LOTS * 0.5, x);```You still have the same problem (multiple closings) because you didn't do anything about it. Asked and previously answered.This assumes lotstep must be a (negative) power of 10 (0.1 or 0.01) and fails for any other value. Don't assume, do it right, see my NormalizeLots.
 2 fabio_geraci 2015.06.28 22:04 #   JD4: You could also try following the suggestions here, go through your code and try to see in yours something similar is happening, and try to correct it as WHRoeder and GumRai are telling micould81 to do.  I know your code is not likely to be exactly the same, but it is a starting point.  Then, if you are able to fix your code, you could also post a before and after here, so people can see what was wrong, and what you did to fix it.JD4, I have tried several approach mostly based on the work of Mr. Hopwood. the problem is that the PartClose function doesn t get call so I have tried micould81 approach, keeping the start() as it is now, and same issue, that is the reason of my question, where should i put the call for the partClose function. As it stands atm.```int start() { //----    static bool TradeExists;    if (OrdersTotal() == 0)    {       TicketNo = -1;    }//if (OrdersTotal() == 0)    ReadIndicatorValues();    //Find open trades    if (OrdersTotal() > 0)    {       CountOpenTrades();       TradeExists = DoesTradeExist();       if (TradeExists)       //{       //   if (OrderProfit() > 0)          TradeManagementModule();          LookForTradeClosure();       //}//if (TradeExists)    }//if (OrdersTotal() > 0)    if (TicketNo == -1)    {       //if(timeprev==Time[0]) return(0);       //timeprev=Time[0];       LookForTradingOpportunities();    } //----    return(0); }```