Download MetaTrader 5
To add comments, please log in or register
Join MQL5 Cloud Network. Millions of traders are waiting for this!
topas
8
topas 2014.11.18 14:09 

Good day. My EA opens 2 order. First order close at the same time when she open. Second order open together with first order but close after 5 minutes.

  I would like disposed of first order, but I don´t know how to do it.

 This is my ea:

//+------------------------------------------------------------------+

//| Externí vstupní parametry strategie                              |

//+------------------------------------------------------------------+

extern double Stoploss_v_pipech = 1000; // definice stop lossu

extern double Profit_target_v_pipech = 2000; // definice profit targetu

extern double Velikost_pozice = 0.01; // definice velikosti pozice pro obchodování

extern double ADXP = 14;

extern double LMAP = 21;

extern double SMAP = 5;



//+------------------------------------------------------------------+

//| Expert initialization function                                      |

//+------------------------------------------------------------------+

int init()

  {return(0);}

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

int deinit()

  {return(0);}

//+------------------------------------------------------------------+

//| Expert start function                                            |

//+------------------------------------------------------------------+

int start()

  {

//+------------------------------------------------------------------+

//| Definice proměnných                                              |

//+------------------------------------------------------------------+

   int D = DayOfWeek();                       // zjistí den v týdnu (neděle=0 … pátek=5)

   int m = TimeMinute(TimeCurrent());         // zjistí aktuální minutu

   int h = TimeHour(TimeCurrent());           // zjistí aktuální hodinu

   int ticket, q, p, close;                   // proměnná pro zadání příkazu, počítadlo

   int maxDuration = 5 * 60;

   int duration = TimeCurrent() - OrderOpenTime();

   double aLMA = iMA(Symbol(),PERIOD_M1,LMAP,0,MODE_LWMA,PRICE_CLOSE,2);

   double bLMA = iMA(Symbol(),PERIOD_M1,LMAP,0,MODE_LWMA,PRICE_CLOSE,1);

   double aSMA = iMA(Symbol(),PERIOD_M1,SMAP,0,MODE_LWMA,PRICE_CLOSE,2);

   double bSMA = iMA(Symbol(),PERIOD_M1,SMAP,0,MODE_LWMA,PRICE_CLOSE,1);

   double ADX = iADX(Symbol(),PERIOD_M1,ADXP,PRICE_CLOSE,0,1);

   double SL = Stoploss_v_pipech*Point;       // převod pipového stoplossu na cenové vyjádření

   double PT = Profit_target_v_pipech*Point;  // převod pipového profitu na cenové vyjádření

   int Magic_number = 1001;                   // identifikační číslo strategie

   string Text = "5 minutes EA";      // komentář  



//+------------------------------------------------------------------+

//| Výstup kontraktů                                                 |

//+------------------------------------------------------------------+

for(p = 0;p < OrdersTotal();p++)

{if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES)==true && OrderMagicNumber()==Magic_number && duration > maxDuration)  

   {if(OrderType()==OP_BUY) {close=OrderClose(OrderTicket(),Velikost_pozice,Bid,2,Yellow);}

    if(OrderType()==OP_SELL) {close=OrderClose(OrderTicket(),Velikost_pozice,Ask,2,Yellow);}}}



//+------------------------------------------------------------------+

//| Omezovač počtu vstupů                                            |

//+------------------------------------------------------------------+

for(q = 0; q < OrdersTotal(); q++)

    {if(OrderSelect(q, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber()==Magic_number)

    {return(0);}}

//+------------------------------------------------------------------+

//| Podmínka pro prodej (SELL/SHORT)                                 |

//+------------------------------------------------------------------+

if (D >= 1 && D < 5 && aLMA < aSMA && bLMA > bSMA && ADX > 25)

   {ticket = OrderSend(Symbol(),OP_SELL,Velikost_pozice,Bid,0,Bid+SL,Bid-PT,Text, Magic_number,0,Red);}

   



//+------------------------------------------------------------------+

//| Podmínka pro nákup (BUY/LONG)                                    |

//+------------------------------------------------------------------+

if (D >= 1 && D < 5 && aLMA > aSMA && bLMA < bSMA && ADX > 25)

   {ticket = OrderSend(Symbol(),OP_BUY,Velikost_pozice,Ask,0,Ask-SL,Ask+PT,Text, Magic_number,0,Blue);}



  return(0);} 
Andrey Barinov
39296
Andrey Barinov 2014.11.18 15:38  
topas:

Good day. My EA opens 2 order. First order close at the same time when she open. Second order open together with first order but close after 5 minutes.

  I would like disposed of first order, but I don´t know how to do it.

 This is my ea:

//+------------------------------------------------------------------+

//| Externí vstupní parametry strategie                              |

//+------------------------------------------------------------------+

   extern double Stoploss_v_pipech=1000; // definice stop lossu

   extern double Profit_target_v_pipech=2000; // definice profit targetu

   extern double Velikost_pozice=0.01; // definice velikosti pozice pro obchodování

   extern double ADXP=14;

   extern double LMAP=21;

   extern double SMAP=5;

//+------------------------------------------------------------------+

//| Expert initialization function                                      |

//+------------------------------------------------------------------+

   int init()

     {return(0);}

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

   int deinit()

     {return(0);}
//+------------------------------------------------------------------+

//| Expert start function                                            |

//+------------------------------------------------------------------+

   int start()

     {

      //+------------------------------------------------------------------+

      //| Definice proměnných                                              |

      //+------------------------------------------------------------------+

      int D=DayOfWeek();                       // zjistí den v týdnu (neděle=0 … pátek=5)

      int m=TimeMinute(TimeCurrent());         // zjistí aktuální minutu

      int h=TimeHour(TimeCurrent());           // zjistí aktuální hodinu

      int ticket,q,p,close;                   // proměnná pro zadání příkazu, počítadlo

      int maxDuration=5*60;

      double aLMA=iMA(Symbol(),PERIOD_M1,LMAP,0,MODE_LWMA,PRICE_CLOSE,2);

      double bLMA=iMA(Symbol(),PERIOD_M1,LMAP,0,MODE_LWMA,PRICE_CLOSE,1);

      double aSMA=iMA(Symbol(),PERIOD_M1,SMAP,0,MODE_LWMA,PRICE_CLOSE,2);

      double bSMA=iMA(Symbol(),PERIOD_M1,SMAP,0,MODE_LWMA,PRICE_CLOSE,1);

      double ADX=iADX(Symbol(),PERIOD_M1,ADXP,PRICE_CLOSE,0,1);

      double SL=Stoploss_v_pipech*Point;       // převod pipového stoplossu na cenové vyjádření

      double PT=Profit_target_v_pipech*Point;  // převod pipového profitu na cenové vyjádření

      int Magic_number=1001;                   // identifikační číslo strategie

      string Text="5 minutes EA";      // komentář  

      //+------------------------------------------------------------------+

      //| Výstup kontraktů                                                 |

      //+------------------------------------------------------------------+

      for(p=0;p<OrdersTotal();p++)

        {
         if(OrderSelect(p,SELECT_BY_POS,MODE_TRADES)==true && OrderMagicNumber()==Magic_number)
           {
            int duration=TimeCurrent()-OrderOpenTime();
            if(duration>maxDuration)
              {
                 {
                  if(OrderType()==OP_BUY) {close=OrderClose(OrderTicket(),Velikost_pozice,Bid,2,Yellow);}

                  if(OrderType()==OP_SELL) {close=OrderClose(OrderTicket(),Velikost_pozice,Ask,2,Yellow);}
                 }
              }
           }
        }

      //+------------------------------------------------------------------+

      //| Omezovač počtu vstupů                                            |

      //+------------------------------------------------------------------+

      for(q=0; q<OrdersTotal(); q++)

        {
         if(OrderSelect(q,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==Magic_number)

           {return(0);}
        }

      //+------------------------------------------------------------------+

      //| Podmínka pro prodej (SELL/SHORT)                                 |

      //+------------------------------------------------------------------+

      if(D>=1 && D<5 && aLMA<aSMA && bLMA>bSMA && ADX>25)

        {ticket=OrderSend(Symbol(),OP_SELL,Velikost_pozice,Bid,0,Bid+SL,Bid-PT,Text,Magic_number,0,Red);}


      //+------------------------------------------------------------------+

      //| Podmínka pro nákup (BUY/LONG)                                    |

      //+------------------------------------------------------------------+

      if(D>=1 && D<5 && aLMA>aSMA && bLMA<bSMA && ADX>25)

        {ticket=OrderSend(Symbol(),OP_BUY,Velikost_pozice,Ask,0,Ask-SL,Ask+PT,Text,Magic_number,0,Blue);}

      return(0);
     }
/
To add comments, please log in or register