HELP WHO CAN !!! - page 6

 
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;

//,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
bool DS=0,DB=0,ZB=0,ZS=0;

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 x = 0; x < OrdersTotal(); x++)
        {
          if(OrderSelect(x, SELECT_BY_POS)&&OrderSymbol()==Symbol()&&OrderMagicNumber()==MAGA)
          switch(OrderType())
          {
          case 0:DB=1;break;
          case 1:DS=1;break;
          case 4:ZB=1;break;
          case 5:ZS=1;break;
          
           }
      //if(OrderType() == OP_BUYSTOP)ZB=1;
      //if(OrderType() == OP_SELLSTOP)ZS=1;
     
      //if(OrderType() == OP_SELL)DB=1;
         
      if(OrderType() == OP_SELLSTOP&&DB==1){OrderDelete(OrderTicket(),CLR_NONE);return(0);}
     
     // if(OrderType() == OP_BUY)DS=1;
      
      if(OrderType() == OP_BUYSTOP&&DS==1){OrderDelete(OrderTicket(),CLR_NONE);return(0);}
      
        
    
      //...................................................................

        //.................ТЕЙК И СТОП....................... 
       
for(int y = 0; y < OrdersTotal(); y++)
  {
    
    if(!OrderSelect(y, SELECT_BY_POS, MODE_TRADES)) continue;
    if(OrderSymbol() != Symbol()) continue;
    if(OrderMagicNumber() != MAGA) continue; 

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

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

 
THE OPTIONS ARE UNLIKELY TO WORK AND, AS I'VE ALREADY WRITTEN, THE OPTIONS ARE UNLIKELY TO WORK...
 

First of all, I said to declare variables inside the START FUNCTION, and here we have 25 again.

Secondly, why do you need a second loop? And why did you add extra checks to mine?

 
When you go through the orders and save their type, save their ticket and their stops, so you don't have to go through 10 iterations
 
Techno:
his code is messed up wildly, the same checks in the loop are repeated 10 times, there are a ton of mistakes, even the modification function has a magik instead of a delay expiration time... it's all bullshit, and it's our fault for not explaining it well...

IT'S NOT BAD EXPLANATION, IT'S THE WRONG EXPLANATION, YOU'RE LOSING IN DIFFERENT WAYS WHAT I HAD INITIALLY AND WITH THE SAME ERROR
 
Techno:

First of all, I said to declare variables inside the START FUNCTION.

Secondly, why do you need a second loop? And why did you add extra checks to mine?


I HAD IT IN THE SAME PLACE (INSIDE THE START), BUT I DON'T WANT TO REMOVE PENDING ORDERS AND EVERYTHING ELSE IS THE SAME (NOT ZEROED)
 
sllawa3:

AS YOU CAN SEE AND THERE (INSIDE THE START) THEN THE PENDING ORDERS ARE JUST NOT DELETED, BUT EVERYTHING ELSE IS THE SAME (NOT RESET)

Let's think logically, these 4 variables are reset at every tick, right?

second question, if there are no orders, then nothing is assigned to these variables and they remain zero, right?

and the last question, if they are equal to zero, how can they not be zeroed?

 
AND REMOVED THE MODIFICATION ALTOGETHER (ALONG WITH THE SECOND CYCLE )... THE SAME THING
 
Techno:

Let's think logically, these 4 variables are reset at every tick, right?

second question, if there are no orders, then nothing is assigned to these variables and they remain zero, right?

and the last question, if they are zero, how can they not be zeroed?


WELL, TRY IT AND SEE FOR YOURSELF... I WAS THINKING THE SAME THING...
 

You don't haphazardly put things away and put them in, you have to think. You know everything, you think everything, but the result is absurd.

Just write a loop where each order has its ticket and its spots, but don't write anything else. You should put the code here