English

## Only one command with one MN

 9 Uncl3B0B 2016.04.11 12:10   How does it do to the command entered, it is not yet entry and that did not enter when it is entered? So that each command entered only once. ```if (((C1 -60*Point) > O1) && ((H1 -100*Point) > L1))         {ticket=OrderSend (Symbol(),OP_BUYSTOP,Lots,H1+25*Point+Spread,0,H1+25*Point+Spread-SL, H1+25*Point+Spread+PT_1,51, MN1, ex,Blue);        ticket=OrderSend (Symbol(),OP_BUYSTOP,Lots,H1+25*Point+Spread,0,H1+25*Point+Spread-SL, H1+25*Point+Spread+PT_2,52, MN2, ex,Blue);        ticket=OrderSend (Symbol(),OP_BUYSTOP,Lots,H1+25*Point+Spread,0,H1+25*Point+Spread-SL2,H1+25*Point+Spread+PT_3,53, MN3, ex,Blue);} ```  When add restrictions, so one command unnecessarily blocking all others:``` for(p = 0; p < OrdersTotal(); p++) {if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES) && (OrderMagicNumber()==MN1)) {return(0);}} for(p = 0; p < OrdersTotal(); p++) {if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES) && (OrderMagicNumber()==MN2)) {return(0);}} for(p = 0; p < OrdersTotal(); p++) {if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES) && (OrderMagicNumber()==MN3)) {return(0);}}```  What specify the condition to command with a specific Magic Number was the always only one?THX
 9 Uncl3B0B 2016.04.11 13:23 #   Yes, my english is too bad - sorry. I try to send it again.  I send order / I enter the command ```if (((C1 -60*Point) > O1) && ((H1 -100*Point) > L1))         {ticket=OrderSend (Symbol(),OP_BUYSTOP,Lots,H1+25*Point+Spread,0,H1+25*Point+Spread-SL, H1+25*Point+Spread+PT_1,51, MN1, ex,Blue);}```  The command will be entered again and again. Prevent so that before command I give restrictions:`for(p = 0; p < OrdersTotal(); p++) {if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES) && (OrderMagicNumber()==MN1)) {return(0);}}`This works. But until moments before want more independent commands. When I want to send more commands to be independent of each other, so the restrictions blocking allHow to make restrictions that the individual orders were independent of each other?
 1234 FMIC 2016.04.12 01:19 #   This should give you an idea of a possible solution to you problem. Some variables and functions are just place-holders for you own code and logic, namely "MyMagicNumber", "BuySignal", "SellSignal", "PlaceBuyOrder" and "PlaceSellOrder".```// Check Open Orders and Count Them int OpenBuyOrderCount = 0, OpenSellOrderCount = 0; for( int i = OrdersTotal() - 1; i >= 0; i-- ) {    if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) )    {       if( ( OrderMagicNumber() == MyMagicNumber ) && ( OrderSymbol() == _Symbol ) )       {          switch( OrderType() )          {             case OP_BUY:                OpenBuyOrderCount++;                break;                            case OP_SELL:                OpenSellOrderCount++;                break;          }       }          } } // Check Signal and Place Order if None exist in the same direction if( BuySignal  && ( OpenBuyOrderCount  < 1 ) ) PlaceBuyOrder(); if( SellSignal && ( OpenSellOrderCount < 1 ) ) PlaceSellOrder();```
 9 Uncl3B0B 2016.04.12 11:34 #   This is my homemade creation. Everything works - only restriction blocks all commands, not just one.One running order, not allow other order activated - I need activated order while other order runnig ...```extern double Lots = 0.1;                 extern double Stoploss_1 = 35; extern double Stoploss_2 = 45;         extern double Profit_target_1 = 120;     extern double Profit_target_2 = 200; extern double Profit_target_3 = 350; extern double ShiftBE1 = 35;   extern double ShiftBE2 = 55; int start()  {   //+------------------------------------------------------------------+ //| Definition of variables                                          | //+------------------------------------------------------------------+    int D = DayOfWeek();                            int m = TimeMinute(TimeCurrent());              int h = TimeHour(TimeCurrent());                int s = TimeSeconds(TimeCurrent());    int    MN1 = 991;    int    MN2 = 992;      int    MN3 = 993;    int    buy  = 0,sell = 0, ticket, p, modify,result;                        double SL   = Stoploss_1*Point;    double SL2  = Stoploss_2*Point;      double PT_1 = Profit_target_1*Point;    double PT_2 = Profit_target_2*Point;    double PT_3 = Profit_target_3*Point;       double BE1 = ShiftBE1*Point;    double BE2 = ShiftBE2*Point;                           double H1 = iHigh (NULL,PERIOD_M5,1);            double L1 = iLow  (NULL,PERIOD_M5,1);               double O1 = iOpen (NULL,PERIOD_M5,1);            double C1 = iClose(NULL,PERIOD_M5,1);           double Spread = 10*Point;                        double ex = iTime(Symbol(),PERIOD_M1,0)+ 1489; //+------------------------------------------------------------------+ //| Shift to BE                                                      | //+------------------------------------------------------------------+ for(p = 0; p < OrdersTotal(); p++) {if (OrderSelect(p,SELECT_BY_POS,MODE_TRADES) && OrderType()==OP_BUY && Ask >= OrderOpenPrice()+ BE1      && (OrderMagicNumber()==MN1 || OrderMagicNumber()==MN2 || OrderMagicNumber()==MN3 ) && OrderStopLoss()OrderOpenPrice())    { modify=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0, Orange );}} for(p = 0; p < OrdersTotal(); p++) {if (OrderSelect(p,SELECT_BY_POS,MODE_TRADES) && OrderType()==OP_BUY && Ask >= OrderOpenPrice()+ BE2      && (OrderMagicNumber()==MN1 || OrderMagicNumber()==MN2 || OrderMagicNumber()==MN3)  && OrderStopLoss()OrderOpenPrice()-10*Point)    { modify=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-10*Point, OrderTakeProfit(), 0, Orange );}} //+------------------------------------------------------------------+   //| Trailing Stop                                                    |   //+------------------------------------------------------------------+   for(p = 0; p < OrdersTotal(); p++) {if (OrderSelect(p,SELECT_BY_POS,MODE_TRADES)==true && OrderType()==OP_BUY &&         (OrderMagicNumber()==MN1 ) && Ask-OrderOpenPrice()> 70*Point && (Ask-70*Point) > OrderStopLoss())      { modify=OrderModify(OrderTicket(), OrderOpenPrice(), Ask-70*Point, OrderTakeProfit(), 0, Green);}} for(p = 0; p < OrdersTotal(); p++) {if (OrderSelect(p,SELECT_BY_POS,MODE_TRADES)==true && OrderType()==OP_SELL &&       (OrderMagicNumber()==MN1  ) && OrderOpenPrice()- Bid > 70*Point && (Bid+70*Point) < OrderStopLoss())        { modify=OrderModify(OrderTicket(), OrderOpenPrice(),Bid+70*Point, OrderTakeProfit(), 0, Green);}}        for(p = 0; p < OrdersTotal(); p++) {if (OrderSelect(p,SELECT_BY_POS,MODE_TRADES)==true && OrderType()==OP_BUY &&         ( OrderMagicNumber()==MN2 || OrderMagicNumber()==MN3) && Ask-OrderOpenPrice()> 160*Point && (Ask-160*Point) > OrderStopLoss())      { modify=OrderModify(OrderTicket(), OrderOpenPrice(), Ask-160*Point, OrderTakeProfit(), 0, Green);}} for(p = 0; p < OrdersTotal(); p++) {if (OrderSelect(p,SELECT_BY_POS,MODE_TRADES)==true && OrderType()==OP_SELL &&       (OrderMagicNumber()==MN2 || OrderMagicNumber()==MN3 ) && OrderOpenPrice()- Bid > 160*Point && (Bid+160*Point) < OrderStopLoss())        { modify=OrderModify(OrderTicket(), OrderOpenPrice(),Bid+160*Point, OrderTakeProfit(), 0, Green);}} //+------------------------------------------------------------------+ //| Close awaiting instructions on activation opposite positions     | //+------------------------------------------------------------------+ for (p = 0; p < OrdersTotal(); p++) {if (OrderSelect(p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==MN1) {if (OrderSymbol() == Symbol()) {if (OrderType() == OP_BUY ) buy++; if (OrderType() == OP_SELL) sell++;    } } }    if (buy > 0) {for (p = 0; p < OrdersTotal(); p++){if (OrderSelect (p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==MN1)  {if (OrderSymbol() == Symbol()) {if  (OrderType() == OP_SELLSTOP) result =  OrderDelete(OrderTicket(),Yellow); } } } }    if (sell > 0) {for (p = 0; p < OrdersTotal(); p++) {if (OrderSelect (p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==MN1)  {if (OrderSymbol() == Symbol()) {if (OrderType() == OP_BUYSTOP) result =  OrderDelete(OrderTicket(),Yellow); } } } }   for (p = 0; p < OrdersTotal(); p++) {if (OrderSelect(p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==MN2) {if (OrderSymbol() == Symbol()) {if (OrderType() == OP_BUY ) buy++; if (OrderType() == OP_SELL) sell++;    } } }    if (buy > 0) {for (p = 0; p < OrdersTotal(); p++){if (OrderSelect (p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==MN2)  {if (OrderSymbol() == Symbol()) {if  (OrderType() == OP_SELLSTOP) result =  OrderDelete(OrderTicket(),Yellow); } } } }    if (sell > 0) {for (p = 0; p < OrdersTotal(); p++) {if (OrderSelect (p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==MN2)  {if (OrderSymbol() == Symbol()) {if (OrderType() == OP_BUYSTOP) result =  OrderDelete(OrderTicket(),Yellow); } } } }   for (p = 0; p < OrdersTotal(); p++) {if (OrderSelect(p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==MN3) {if (OrderSymbol() == Symbol()) {if (OrderType() == OP_BUY ) buy++; if (OrderType() == OP_SELL) sell++;    } } }    if (buy > 0) {for (p = 0; p < OrdersTotal(); p++){if (OrderSelect (p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==MN3)  {if (OrderSymbol() == Symbol()) {if  (OrderType() == OP_SELLSTOP) result =  OrderDelete(OrderTicket(),Yellow); } } } }    if (sell > 0) {for (p = 0; p < OrdersTotal(); p++) {if (OrderSelect (p, SELECT_BY_POS, MODE_TRADES )&& OrderMagicNumber()==MN3)  {if (OrderSymbol() == Symbol()) {if (OrderType() == OP_BUYSTOP) result =  OrderDelete(OrderTicket(),Yellow); } } } }   //+------------------------------------------------------------------+ //| Expiration/Deleted                                               | //+------------------------------------------------------------------+     if (TimeCurrent() - OrderOpenTime()>=4.5*60)for(p = 0; p < OrdersTotal(); p++) {if (OrderSelect (p, SELECT_BY_POS, MODE_TRADES )&& (OrderMagicNumber()==MN1 || OrderMagicNumber()==MN2 ))      {if (OrderType() == OP_BUYSTOP || OP_SELLSTOP) result =  OrderDelete(OrderTicket(),Yellow);} } if (TimeCurrent() - OrderOpenTime()>=5*60) for(p = 0; p < OrdersTotal(); p++) {if (OrderSelect (p, SELECT_BY_POS, MODE_TRADES )&& (OrderMagicNumber()==MN3 ))      {if (OrderType() == OP_BUYSTOP || OP_SELLSTOP) result =  OrderDelete(OrderTicket(),Yellow);} }     //+------------------------------------------------------------------+ //| Restrictions                                          | //+------------------------------------------------------------------+   for(p = 0; p < OrdersTotal(); p++) {if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES) && (OrderMagicNumber()==MN1)) {return(0);}} // restriction blocks all commands, not just one. for(p = 0; p < OrdersTotal(); p++) {if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES) && (OrderMagicNumber()==MN2)) {return(0);}} // restriction blocks all commands, not just one. for(p = 0; p < OrdersTotal(); p++) {if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES) && (OrderMagicNumber()==MN3)) {return(0);}} // restriction blocks all commands, not just one. //+------------------------------------------------------------------+ //| Buy                                                              |     //+------------------------------------------------------------------+       if (((C1 -60*Point) > O1 && (H1 -100*Point) > L1)  && s > 0 && s < 10 && D >= 1 && h >= 9 &&  ((m==0)||(m==5)||(m==10)||(m==15)||(m==20)||(m==25)||(m==30)||(m==35)||(m==40)||(m==45)||(m==50)||(m==55)))         {ticket=OrderSend (Symbol(),OP_BUYSTOP,Lots,H1+25*Point+Spread,0,H1+25*Point+Spread-SL, H1+25*Point+Spread+PT_1,51, MN1, ex,Blue);        ticket=OrderSend (Symbol(),OP_BUYSTOP,Lots,H1+25*Point+Spread,0,H1+25*Point+Spread-SL, H1+25*Point+Spread+PT_2,52, MN2, ex,Blue);        ticket=OrderSend (Symbol(),OP_BUYSTOP,Lots,H1+25*Point+Spread,0,H1+25*Point+Spread-SL2,H1+25*Point+Spread+PT_3,53, MN3, ex,Blue); }    //+------------------------------------------------------------------+ //|  Sell                                                            |     //+------------------------------------------------------------------+   if (((C1 +60*Point) < O1 && (L1 +100*Point) < H1)  && s > 0 && s < 10 && D >= 1 && h >= 9 &&  ((m==0)||(m==5)||(m==10)||(m==15)||(m==20)||(m==25)||(m==30)||(m==35)||(m==40)||(m==45)||(m==50)||(m==55)))       {ticket=OrderSend (Symbol(),OP_SELLSTOP, Lots,L1-25*Point, 0,L1-25*Point+SL, L1-25*Point-PT_1,51, MN1, ex,Red);        ticket=OrderSend (Symbol(),OP_SELLSTOP, Lots,L1-25*Point, 0,L1-25*Point+SL, L1-25*Point-PT_2,52, MN2, ex,Red);        ticket=OrderSend (Symbol(),OP_SELLSTOP, Lots,L1-25*Point, 0,L1-25*Point+SL2,L1-25*Point-PT_3,53, MN3, ex,Red); }       return(0);} //+------------------------------------------------------------------+   ```