AIDEZ QUI PEUT ! !! - page 2

 
sllawa3:
au-dessus de

Ce n'est pas plus haut, c'est à l'intérieur, au début.

int start()
{
DS=0;

// code
 

Non et ça ne fonctionne pas comme ça... car s'il n'y a pas de pose, le sélecteur ne changera pas la valeur de la variable jusqu'à ce que la suivante apparaisse

c'est comme ça que je voulais le faire :

for(int i = 0; i < OrdersTotal(); i++)
  {
    
    if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
    if(OrderSymbol() != Symbol()) continue;
    if(OrderMagicNumber() != MAGA) continue; 
    
    
      
      if(OrderType() == OP_BUYSTOP)ZB=1;
      if(OrderType() == OP_SELLSTOP)ZS=1;
     
      if(OrderType() == OP_SELL)DB=1;
         
      if(OrderType() == OP_BUYSTOP&&DB==1){OrderDelete(OrderTicket(),CLR_NONE);return(0);}
     
      if(OrderType() == OP_BUY)DS=1;
      
      if(OrderType() == OP_SELLSTOP&&DS==1){OrderDelete(OrderTicket(),CLR_NONE);return(0);}
      
          
      //...................................................................
      }
      if(ZB==0&&ZS==0&&DB==0&&DS==0        
         )          
        {
         Opn_B = true;
         Opn_S = true;
        }      
 
Ça ne marche pas non plus au début... J'ai essayé toutes sortes de choses...
 
Une fois de plus, si le drapeau de la fonction de sélection est défini sur mode_trades, les ordres sont alloués au courant et non à partir de l'historique, il n'y a donc aucun sens à demander l'heure de clôture, elle sera toujours égale à zéro.
 
Les ordres sont simplement ouverts tous les deux, un ordre en attente se déclenche, le second est supprimé, celui qui s'est déclenché est fermé au take ou au stop, et c'est là que ça s'arrête, car aucune boucle n'est lancée et la valeur de 1 pour une des variables est sauvegardée...
 
Techno:
Une fois de plus, si le drapeau de la fonction de sélection est défini sur mode_trades, les ordres sont alloués au courant et non à partir de l'historique, il n'y a donc aucun sens à demander l'heure de clôture, elle sera toujours égale à zéro.

je l'ai réparé... je le sais moi-même mais j'ai juste commencé à tout essayer
 
J'ai besoin du code complet,
 

Au fait, c'est comme ça que ça doit être ?

 if(OrderType() == OP_SELL)DB=1;
 if(OrderType() == OP_BUY)DS=1;
 

Une base comme celle-ci fonctionnerait-elle ? Cela fonctionne toujours à 100% pour moi :

si(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderSymbol()==Symbol())
{

...et ainsi de suite...

}

}

 
extern string БАЙ = "NASTROI:";
extern int StopLoss = 200; // SL для открываемого ордера
extern int TakeProfit = 40;
extern double TrailingStop = 3;
extern double TrailingStep =0;
extern string ЛОТ = "NASTROI LOT:";
extern double Lots = 0.1; // Жестко заданное колич. лотов
extern double ДОЛЯ_ДЕП_ОСН_ОРД = 0; // доля от свободных средств 
extern double MAX_LOT = 40;
extern bool NORMALIZ = false;
extern string П = "EDGE:";
extern int МАКС_КОЛИЧ_ОРДЕРОВ = 111;
extern double БАЛАНС_МАРЖИ=1;
extern int  TFCLOSE=5;
extern string FLAG = "FLAGS:";
extern int BUY =1; //блок бай
extern int SELL =1; //блок сел
extern int MINIM=1;
extern double F=1;
extern int ДИСТАНЦИЯ_ВЫСТАВЛЕНИЯ_ОТЛОЖ = 5;
extern int MAGA = 7777; //магик № бай
extern double Z=10;

//,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,


void deinit() {
   Comment("");
}

int start()
{
  bool DS=0,DB=0,ZB=0,ZS=0;
  int R=1,CB=0;
  double Lts,
  FB=F,FS=F,MG,ZL=0,  
  Min_Lot,
  Lts1,
  TPD1;
  bool Cls_B = false,
  Cls_S = false,
  Opn_B = false,
  Opn_S = false;



  
  //00000000000000000000000000000000000000000000000000000
        //+------------РАСЧЁТ СТОИМОСТИ------------------------------------------------------+        
          // Стоимость ордеров
       
        if(БАЛАНС_МАРЖИ>0&&NORMALIZ==false)
        {
        RefreshRates();
        if(AccountFreeMargin()>AccountMargin())MG=AccountFreeMargin();
        //if(AccountFreeMargin()<AccountMargin())MG=0;
        if(БАЛАНС_МАРЖИ*AccountFreeMargin()<AccountMargin())R=0;
        Min_Lot = MarketInfo(Symbol(), MODE_MINLOT);
        
        if(Lots > 0 && ДОЛЯ_ДЕП_ОСН_ОРД == 0)
          Lts = Lots;
        if(ДОЛЯ_ДЕП_ОСН_ОРД > 0)
          Lts=MG/MarketInfo (Symbol(), MODE_MARGINREQUIRED)*ДОЛЯ_ДЕП_ОСН_ОРД;
        if(Lts > MAX_LOT)
          Lts = MAX_LOT;
        if(MG==0)Lts =0;
        if(MG>0&&Lts < Min_Lot&&MINIM==0)
        {
        R=0;
        Lts = 0;// Min_Lot;
        }
        if(MG>0&&Lts < Min_Lot&&MINIM==1)
        {
        Lts = Min_Lot;
        }
        Lts1=Lts;
        }
        //................................
        int m;
        if(NORMALIZ==true&&БАЛАНС_МАРЖИ>0)
        {
        if(AccountFreeMargin()>AccountMargin())MG=AccountFreeMargin();
        if(AccountFreeMargin()<AccountMargin())MG=0;
        Min_Lot = MarketInfo(Symbol(), MODE_MINLOT);
        //........................................................
        if(Lots > 0 && ДОЛЯ_ДЕП_ОСН_ОРД == 0)
          Lts = Lots;
        if(ДОЛЯ_ДЕП_ОСН_ОРД>0)
          m=БАЛАНС_МАРЖИ*MG/MarketInfo (Symbol(), MODE_MARGINREQUIRED)*ДОЛЯ_ДЕП_ОСН_ОРД/Min_Lot;
          Lts = m*Min_Lot;
        
        if(Lts > MAX_LOT)
          Lts = MAX_LOT;
        if(MG==0)Lts =0;
        if(MG>0&&Lts < Min_Lot)
        {
         Lts =Min_Lot;
        // R=O;
        }
         Lts= Lts;
        }
         
        //................................
        
        if(БАЛАНС_МАРЖИ==0)
        {
         RefreshRates();
        Min_Lot = MarketInfo(Symbol(), MODE_MINLOT);       
        if(Lots > 0 && ДОЛЯ_ДЕП_ОСН_ОРД == 0)
          Lts = Lots;
        if(ДОЛЯ_ДЕП_ОСН_ОРД > 0)
          Lts=AccountFreeMargin()/MarketInfo (Symbol(), MODE_MARGINREQUIRED)*ДОЛЯ_ДЕП_ОСН_ОРД;
        if(Lts > MAX_LOT)
          Lts = MAX_LOT;        
        if(Lts < Min_Lot&&MINIM==0)
        {
        R=0;
        Lts = 0;//Min_Lot;
        }
        if(Lts < Min_Lot&&MINIM==1)
        {
        Lts = Min_Lot;
        }
        Lts1=Lts;
        }
        
  
 
 
 for(int i = 0; i < OrdersTotal(); i++)
  {
    
    if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
    if(OrderSymbol() != Symbol()) continue;
    if(OrderMagicNumber() != MAGA) continue; 
    
    
      
      if(OrderType() == OP_BUYSTOP)ZB=1;
      if(OrderType() == OP_SELLSTOP)ZS=1;
     
      if(OrderType() == OP_SELL)DB=1;
         
      if(OrderType() == OP_BUYSTOP&&DB==1){OrderDelete(OrderTicket(),CLR_NONE);return(0);}
     
      if(OrderType() == OP_BUY)DS=1;
      
      if(OrderType() == OP_SELLSTOP&&DS==1){OrderDelete(OrderTicket(),CLR_NONE);return(0);}
      
      
    
      //...................................................................

        //.................ТЕЙК И СТОП....................... 
    if(OrderType() == OP_BUY&&OrderStopLoss()==0||OrderTakeProfit()==0&&StopLoss>0)
    {
      OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice()-StopLoss*Point ,
       OrderOpenPrice()+TakeProfit*Point ,MAGA, CLR_NONE);
       return(0);
    }

    if(OrderType() == OP_SELL&&OrderStopLoss()==0||OrderTakeProfit()==0&&StopLoss>0)
    {
      OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice()+StopLoss*Point ,
       OrderOpenPrice()-TakeProfit*Point ,MAGA, CLR_NONE);
       return(0);
    }


 //....................................................................   
    if(OrdersTotal() > 0&&TrailingStop>1)//&&OrderMagicNumber()== MAGICD1||OrderMagicNumber()== MAGIC1||OrderMagicNumber()== MAGICD||OrderMagicNumber()== MAGIC)
    {
      if(OrderType() == OP_SELL&&OrderMagicNumber()== MAGA)
      {
        if(TrailingStop> 0)
        {
          if(OrderOpenPrice() - Ask >= Z * TrailingStop * Point)
          {            
            if(OrderStopLoss() > (Ask + Z*Point* TrailingStop+Z*Point*TrailingStep))
            {           
              OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Z*Point * TrailingStop,
               OrderTakeProfit(),MAGA, CLR_NONE);
               return(0);
            }
          }
        }
      }
      else
        if(OrderType() == OP_BUY&&OrderMagicNumber()== MAGA)//||OrderMagicNumber()== MAGIC1)
        {
          if(TrailingStop > 0)         
          {
            if(Bid - OrderOpenPrice() >= Z*TrailingStop * Point)
            {
              if(OrderStopLoss() < (Bid - Z*Point * TrailingStop-Z*Point*TrailingStep))
              {
                OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Z*Point * TrailingStop,
                  OrderTakeProfit() ,MAGA, CLR_NONE);
                  return(0);
              }
            }
          }
        }
      }   
     }
   //OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
 
       if(ZB==0&&ZS==0&&DB==0&&DS==0        
         )          
        {
         Opn_B = true;
         Opn_S = true;
        }     
        
//OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

     // Открытие ордеров
        while(true)
        {     
  //OOOOOOOOOOOOOOOOOOOOOOOO ОСНОВНЫЕ OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

      
     
           if(Opn_B == true && BUY ==1)
          {
           // CS=1; 
           Alert("Попытка BUY");
            if(Opn_B == true && BUY ==1)
            OrderSend(Symbol(), OP_BUYSTOP,FB*Lts,Ask+Z*ДИСТАНЦИЯ_ВЫСТАВЛЕНИЯ_ОТЛОЖ*Point,2,0,0,"",MAGA,0,Aqua); 
                  if(Fun_Error(GetLastError()) == 1)  
              continue;
           // return(0);
          }
          //--------------------------------------------------
           
         
           if(Opn_S == true&&SELL==1)
          {
           // CB=1;
            Alert("Попытка SELL");
            if(Opn_S == true&&SELL==1)
            OrderSend(Symbol(), OP_SELLSTOP, FS*Lts,Bid-Z*ДИСТАНЦИЯ_ВЫСТАВЛЕНИЯ_ОТЛОЖ*Point,2,0,0,"",MAGA,0,Orange);//TimeCurrent()+TIMELIVE*60
                  if(Fun_Error(GetLastError()) == 1)
              continue;
            return(0);
          }                      
          break;
        }
        return(0);
     }
  
//+------------------------------------------------------------------+

int Fun_Error(int Error)
{
  switch(Error)
  {
    case 4:
      Alert("Торговый сервер занят. Пробуем ещё раз..");
    Sleep(3000);
    return(1);
    case 135:
      Alert("Цена изменилась. Пробуем ещё раз..");
    RefreshRates();
    return(1);
    case 136:
      Alert("Нет цен. Ждём новый тик..");
    while(RefreshRates() == false)
      Sleep(1);
    return(1);
    case 137:
      Alert("Брокер занят. Пробуем ещё раз..");
    Sleep(3000);
    return(1);
    case 146:
      Alert("Подсистема торговли занята. Пробуем ещё..");
    Sleep(500);
    return(1);
    case 2:
      Alert("Общая ошибка.");
    return(0);
  }
  
  //+------------------------------------------------------------------+
}

//.............................................................

Raison: