HELP WHO CAN !!! - page 2

 
sllawa3:
above

It's not higher, it's inside, at the beginning.

int start()
{
DS=0;

// code
 

No and it doesn't work that way... because if there are no poses, the selector won't change the value of the variable until the next one appears

that's how I wanted to do it:

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;
        }      
 
It doesn't work in the beginning either... I've tried all sorts of things
 
Once again, if the flag of the select function is set to mode_trades orders are allocated to current and not from the history, so it makes no sense to request the closing time, it will always be equal to zero
 
Orders are simply both opened, one pending order triggers, the second one is deleted, the triggered one is closed at take or stop, and that's where it stops, because no loop is started and the value of 1 for one of the variables is saved...
 
Techno:
Once again, if the flag of the select function is set to mode_trades orders are allocated to current and not from the history, so it makes no sense to request the closing time, it will always be equal to zero

i fixed it... i know it myself but i just started trying everything
 
need the full code,
 

By the way, is this how it's supposed to be?

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

Would a base like this work? It always works 100% for me:

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

...and so on...

}

}

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

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