Problème ordre de l'EA passé 2 fois

 

Bonjour,

J'ai un EA qui avec le testeur de stratégie (chaque tick basé sur les ticks réels) ne me donne aucune erreurs dans le journal et le comportement que j'attend.

Par contre quand je le glisse en mode demo il me passe une seconde fois un ordre alors qu'il ne devrait pas pouvoir, veut modifier un SL alors que les conditions ne sont pas au rendez-vous et me fait des invalids SL...

Voici une partie de mon code : 

...
//--- global variables
//--- initialize global variables
...
bool Position1_Prise = false;
...
void OnTick()
  {
...
if (Position1_Prise && PositionsTotal()==0)
      {
        ExpertRemove();
      }
...
// Buy conditions --------------------------------------------------
...
   if (!Position1_Prise)
     {
     Buy_Condition1=true; //Pour le test
        }              
          
   if (Buy_Condition1 && !Position1_Prise && !PositionExists1 && !forte_volatilite)    // Open long position
       {  
         Buy_Condition1=false;
                  
         Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);    // Ask price
         Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);    // Bid price
        
        SL1=Ask-(Delta_SL1*coeff_digits);
        TP1=Ask+(Delta_TP1*coeff_digits);
        
        LongPositionOpen1();                           
       }

      
   return;
  }
    
  
//+------------------------------------------------------------------+
//| Open Long position  1                                            |
//+------------------------------------------------------------------+
void LongPositionOpen1()
  {
   MqlTradeRequest mrequest1;                             // Will be used for trade requests
   MqlTradeResult mresult1;                               // Will be used for results of trade requests
  
   ZeroMemory(mrequest1);
   ZeroMemory(mresult1);
  
     if(!PositionExists1)
     {
      mrequest1.action = TRADE_ACTION_DEAL;               // Immediate order execution
      mrequest1.price = Ask;     // Lastest Ask price
      bool SL1_check=false;
      //--- check the StopLoss
      while(!SL1_check)
         {
            Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);    // Bid price
            int stops_level=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
            SL1_check=(Bid-SL1>stops_level*_Point);
            SL1= SL1-0.00001*coeff_digits;
         }
      mrequest1.sl = SL1;            // Stop Loss of the position
      mrequest1.tp = TP1;            // Take Profit of the position
      mrequest1.symbol = _Symbol;                         // Symbol
      mrequest1.volume = Lot1;                             // Number of lots to trade
      mrequest1.magic = Magic1;                                // Magic Number
      mrequest1.type = ORDER_TYPE_BUY;                    // Buy Order
      mrequest1.type_filling = ORDER_FILLING_FOK;         // Order execution type
      mrequest1.deviation=2;                              // Deviation from current price
      //--- send the request
         if(!OrderSend(mrequest1,mresult1))
         PrintFormat("OrderSend error %d",GetLastError());  // if unable to send the request, output the error code
         //--- information about the operation   
         PrintFormat("retcode=%u  deal=%I64u  order=%I64u",mresult1.retcode,mresult1.deal,mresult1.order);
     }
          
     Ask1=mresult1.price;
     
     for(int i = PositionsTotal() - 1; i >= 0; i--)
      {
         if (PositionGetTicket(i) > 0 && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
         {
          PositionExists1 = true;
          Position1_Prise = true;
          Position_ticket1 = PositionGetTicket(i);// ticket of the position
          }
       }
  }
...
Dossiers :
journal.jpg  620 kb
Raison: