Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 326

 
Integer:


So let it be, what's the big deal?

But if anything, there is the IsConnected() function;


well the worst thing that happened was that a positive trade didn't open:)

But I would like to know what really happened - whether the broker was messing around or there was a problem on my part.

 
mzk_3om6u:


1. well, the worst thing that happened was that a positive trade did not open:)

2. But I would like to know what really happened - whether the broker was messing around or there was a problem on my part.


1. it's kind of a normal, natural phenomenon.

There is no way of knowing. You often lose the connection for a few seconds.

 
Integer:


1. this is kind of a normal, natural phenomenon.

2. there is no way of knowing. Very often the connection is lost for a few seconds.


In a month of testing with this broker, it's the first time it's happened, although I've already noticed 4 problems with them - it's probably time to look for another one:)

Thank you for your answers!)

 
TarasBY:
Do you ever watch what you've written?!

Something tells me that "this is where the dog is at":


Thanks. Got it.
 
artmedia70:
You don't need a flag. The flag can be lost in abnormal situations. It is better to check - whether there is an open position and, if there is - further

Oh, I think I've got it. I figured out the logic, so here's what I've done. However, when I compile it, I get an error ')'. - assignment expect D:\Alpari\experts\Sp.mq4 (160, 92). I checked all the brackets ten times - I can't find the error. Some kind of a fucking poltergeist. artmedia70, if you don't mind telling me where the error is.

extern double  Lots             = 0.1;
extern string Сomment           = "Pattern_1";
extern int TakeProfit           = 0;     
extern int StopLoss             = 0;   
extern int Step                 = 0;   

extern int BULevel              = 200;
extern int   NotBULevel         = 20;         // Уровень безубытка в пунктах

extern int Slippage             = 2; // проскальзывание 
extern int Magic                = 111;

int ticket, otype;
double TP, price;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
      if (Digits ==3 || Digits ==5) // для пятизначного брокера
         {
            TakeProfit *= 10;
            StopLoss *= 10;
            Slippage *= 10;
            Step *= 10;
         }
      return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   if (CountTrades()==0 && Open[1]>Close[1] && Open[2]<Close[2] && High[1]>High[2] && Low[1]<Low[2])  // продажа
   {
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"Pattern_1",111,0,Red);
      if (OrderSelect(ticket, SELECT_BY_TICKET,MODE_TRADES))
      {
         TP=NormalizeDouble(Bid - TakeProfit * Point, Digits);
         OrderModify(ticket, OrderOpenPrice(),0,TP,0);
      }
   }
   else
   if (CountTrades()==0 && Open[1]<Close[1] && Open[2]>Close[2] && High[1]>High[2] && Low[1]<Low[2]) // покупка
    {
      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"Pattern_1",111,0,Blue);   
      if (OrderSelect(ticket, SELECT_BY_TICKET,MODE_TRADES))
      {
         TP=NormalizeDouble(Ask + TakeProfit * Point, Digits);
         OrderModify(ticket, OrderOpenPrice(),0,TP,0);
      }
    }
   if (CountTrades()>0)
      {
      otype = FindLastOrderType();
      if (otype == OP_BUY)
         { // ценапоследнего ордера на покупку
         price = FindLastBayPrice();
         
         if ((Bid - price) / Point >= Step)
            {
               ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid,Slippage,0,0,"Pattern_1",111,0,Red);  
            }
         }
      else if (otype == OP_SELL)
         { // цена последнего ордера на продажу
         price = FindLastSellPrice()
         
          if ((price - Ask) / Point >= Step)
            {
               ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask,Slippage,0,0,"Pattern_1",111,0,Blue);  
            }
         }
      }
   
    
   return(0);
  }
     
 //+------------------------------------------------------------------+
int CountTrades() // количество открытых ордеров
   {
      int count=0;
      for(int i=OrdersTotal()-1; i>=0; i--) 
      {
         if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
         {
            if (OrderSymbol()==Symbol() && OrderMagicNumber()==111)
            {
               if (OrderType()==OP_BUY || OrderType()==OP_SELL)
               count++;
            }
         }
      }
    return(count);  
   }
 //+------------------------------------------------------------------+
int FindLastOrderType() // вычисляем тип последнего ордера
   {
      int oticket, ticketnumber=0, OType;
      for(int i=OrdersTotal()-1; i>=0; i--)   
      {
         if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
         {
            if (OrderSymbol()==Symbol() && OrderMagicNumber()==111)
            {
              oticket=OrderTicket();
              if (oticket > ticketnumber) 
              {
               ticketnumber = oticket;
               OType = OrderType(); // самый последний тикет
              }               
            }
         }
      }
    return(OType);    
   }
       
       
  //+------------------------------------------------------------------+
double FindLastBayPrice() // находим цену последнего ордера на покупку
   {
      int oticket, ticketnumber=0;
      double oprice;
      for(int i=OrdersTotal()-1; i>=0; i--)   
      {
         if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
         {
            if (OrderSymbol()==Symbol() && OrderMagicNumber()==111 && OrderType() = OP_BUY)
            {
              oticket=OrderTicket();
              if (oticket > ticketnumber) 
              {
               ticketnumber = oticket;
               oprice = OrderType(); // самый последний тикет
              }               
            }
         }
      }
    return(oprice);    
   }      
  //+------------------------------------------------------------------+
double FindLastSellPrice() // находим цену последнего ордера на продажу
   {
      int oticket, ticketnumber=0;
      double oprice;
      for(int i=OrdersTotal()-1; i>=0; i--)   
      {
         if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
         {
            if (OrderSymbol()==Symbol() && OrderMagicNumber()==111 && OrderType() = OP_SELL)
            {
              oticket=OrderTicket();
              if (oticket > ticketnumber) 
              {
               ticketnumber = oticket;
               oprice = OrderType(); // самый последний тикет
              }               
            }
         }
      }
    return(oprice);    
   }        

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

void BU()
{
   for(int a=0; a<OrdersTotal(); a++) 
  {
       if (OrderSelect(a, SELECT_BY_POS)) 
        {      
         if(OrderMagicNumber()!=111  || OrderSymbol()!=Symbol()) continue;
         if(OrderType()==OP_BUY) 
          {
           if(OrderOpenPrice()<=(Bid-BULevel*Point-NotBULevel*Point)&& OrderOpenPrice()>OrderStopLoss())// последнеее условие БУ + 20 пипсов
            {      
             OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+NotBULevel*Point,OrderTakeProfit(),0,Green);
            }
          }       
 
         if(OrderType() == OP_SELL) 
           {
            if(OrderOpenPrice()>=(Ask+BULevel*Point+NotBULevel*Point)&& (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss() == 0 ))// последнеее условие БУ + 20 пипсов
             {
              OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-NotBULevel*Point,OrderTakeProfit(),0,Red);
             }
           } 
         }
   }
 return(0);
 }

 
 if (Digits ==3 || Digits ==3) // для пятизначного брокера
It's kind of weird.
 
ALXIMIKS:
it's kind of weird.
Corrected, ALXIMIKS, please check for errors and logic.
 
You should read the instructions before installing - the first 15 pages.
Files:
kod.txt  7 kb
 

Please tell me if this function is written correctly.

double GetLastUpperFractal()
{
double LastUpperFractalPrice = 0;
for (int i = 0; i<=Bars; i++)
{
double FractalUp = iFractals(Symbol(),PERIOD_M5,MODE_UPPER,i);
if (FractalUp != 0) LastUpperFractalPrice = FractalUp;
}
return (LastUpperFractalPrice);
}
//+------------------------------------------------------------------+
double GetLastLowerFractal()
{
double LastLowerFractalPrice = 0;
for (int i = 0; i<=Bars; i++)
{
double FractalDown = iFractals(Symbol(),PERIOD_M5,MODE_LOWER,i);
if (FractalDown != 0) LastLowerFractalPrice = FractalDown;
}
return (LastLowerFractalPrice);
}

 
ALXIMIKS:
I fixed it to compile - and use the 555 build mt4 editor - it really helps to find problems quickly. just read the instructions before installing - the first 15 pages.

I have it, thank you. Where can I read about 555 build? Can you provide the link?
Reason: