Il mio EA fa una doppia entrata - pagina 11

 

Ho pensato che ci fossero aggiornamenti su questo thread che si presenta come il 1° thread

quindi credo che non ci sia ancora nessun aggiornamento dal service desk giusto?

 

Ciao, ho un problema con la doppia entrata (inaspettatamente :) ). Per favore, potete aiutarmi con il mio problema? In questo argomento vedo spesso la funzione sleep(), ma non so dove usarla.

Questo è il mio programma:

//+------------------------------------------------------------------+
//| 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 = "Moje první strategie";      // komentář  

//+------------------------------------------------------------------+
//| Výstup kontraktů                                                 |
//+------------------------------------------------------------------+
for(p = 0;p < OrdersTotal();p++)
{if(OrderSelect(p, SELECT_BY_POS, MODE_TRADES)==true && OrderMagicNumber()==Magic_number && duration > maxDuration)  //&& 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);}
 
topas:

Ciao, ho un problema con la doppia entrata (inaspettatamente :) ). Per favore, potete aiutarmi con il mio problema? In questo argomento vedo spesso la funzione sleep(), ma non so dove usarla.

Questo è il mio programma:

Questo argomento riguarda mql5, non è rilevante per mql4.
 
topas:

Ciao, ho un problema con la doppia entrata (inaspettatamente :) ). Per favore, potete aiutarmi con il mio problema? In questo argomento vedo spesso la funzione sleep(), ma non so dove usarla.

Questo è il mio programma:

Forum sul trading, sistemi di trading automatico e strategie di trading di prova

Aprire 2 ordini

Wahoo, 2014.11.18 15:38

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

//| 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);
     }