Questions from Beginners MQL4 MT4 MetaTrader 4 - page 5

 
Guys, please advise what's wrong with the tester. instead of candlesticks it only shows opening prices in "All ticks, most accurate method" mode and in other modes too.
MT4 Batter volum is also inadequate in the tester
 

Can you tell me why it opens on every tick?

void OnTick()
  {
   Alert(Sborinfo(Magic));
   if(Sborinfo(Magic)<=0)
     {
      MassivPrice(step); 
      tiket=OrderSend(Symbol(),OP_BUY,0.01,Ask,0,0,0,NULL,0,0,Blue);
      if(tiket>=0
         LastPrice=Ask
      else LastPrice=-1
     }
   MassivPrice(step);
   tiket=OrderSend(Symbol(),OP_SELL,0.01,Bid,0,0,0,NULL,0,0,Red);
   if(tiket>=0)
      LastPrice=Bid;
   else LastPrice=-1;
  }
//+------------------------------------------------------------------+
int Sborinfo(int magic)
  {
   for(int i=0; i<OrdersTotal(); i++)
     {
      Print("колличество ордеров ",kol);
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==magic)
         kol++;
     }
   Print("новые ордера ",kol);
   return(kol);
  }
 
Ibragim Dzhanaev:

Can you tell me why it opens on every tick?

Because I always test in this mode

void OnTick()
  {
   Alert(Sborinfo(Magic));
   if(Sborinfo(Magic)<=0)
     {
      MassivPrice(step); 
      tiket=OrderSend(Symbol(),OP_BUY,0.01,Ask,0,0,0,NULL,0,0,Blue);
      if(tiket>=0
         LastPrice=Ask
      else LastPrice=-1
     }
   MassivPrice(step);
   tiket=OrderSend(Symbol(),OP_SELL,0.01,Bid,0,0,0,NULL,0,0,Red);
   if(tiket>=0)
      LastPrice=Bid;
   else LastPrice=-1;
  }
//+------------------------------------------------------------------+
int Sborinfo(int magic)
  {
   for(int i=0; i<OrdersTotal(); i++)
     {
      Print("колличество ордеров ",kol);
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderMagicNumber()==magic)
         kol++;
     }
   Print("новые ордера ",kol);
   return(kol);
  }
 
Ibragim Dzhanaev:

Can you tell me why it opens on every tick?

Because that is how the code is written.

In simple terms, your algorithm looks like this: if there are no orders, open Buy, and at every tick, open Sell.

 
Vitalie Postolache:

Because that's how the code is written.

In simple terms, your algorithm looks like this: if there are no orders, open a Buy, and at every tick, open a Sell.

How can you change the code to make it work without additional conditions ?
Alert(Sborinfo(Magic));
  // Closse(Magic);
   if(Sborinfo(Magic)==0)
     {
     Print("количество ордеров ",Sborinfo(Magic));
      MassivPrice(step);
      if(OrdersTotal()<2)// без таких условий
         tiket=OrderSend(Symbol(),OP_BUY,0.01,Ask,slippage,0,0,NULL,0,0,Green);
      if(tiket>=0)
         LastPrice=Ask;  
     }

   MassivPrice(step);
   if(OrdersTotal()<2)// без таких условий
      tiket=OrderSend(Symbol(),OP_SELL,0.01,Bid,slippage,0,0,NULL,0,0,Red);
   if(tiket>=0)
      LastPrice=Bid;
  
  }
//+------------------------------------------------------------------+
int Sborinfo(int magic)
  {
  kol=0;
   for(int i=0; i<OrdersTotal(); i++)
     {
     Print(" чему ровно кол " , kol );
      if(OrderSelect(i,SELECT_BY_POS) && OrderMagicNumber()==magic)
      {
      Print(" ордера после " , kol );
      
        // kol++;
         }
     }
   return(kol);
  }
 
Ibragim Dzhanaev:
How do you change the code to work without additional conditions ?

But you can't, if you need both buy and sell and limit their number. Only I would not look atOrdersTotal(), and would count how much buy and how much sell.

And again, why do you need this "if(Sborinfo(Magic)==0)" if you then useOrdersTotal()?

 
Vitalie Postolache:

But you can't, if you need both buy and sell and limit their number. Only I would not look atOrdersTotal(), and would count how much buy and how much sell.

And again, why do you need this "if(Sborinfo(Magic)==0)", if you then useOrdersTotal()?

You mean like this ? Are there other options - simpler ?
{
  CloseFirst(Magic);
   int b=0;
   int s=0;
   for(int i=0; i<=OrdersTotal(); i++)
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true && OrderMagicNumber()==Magic && OrderSymbol()==_Symbol )
        {
         if(OrderType()==OP_BUY)
            b++;
         if(OrderType()==OP_SELL)
            s++;
        }
   if(b==0)
      tiket=OrderSend(Symbol(),OP_BUY,0.01,Ask,slippage,0,0,NULL,Magic,0,Green);
  if(s==0)
      tiket=OrderSend(Symbol(),OP_SELL,0.01,Bid,slippage,0,0,NULL,Magic,0,Red);
      }
 

Comrades! I have a question.
The Expert Advisor opens pending orders at 00:00 from the beginning of the day based on the previous day's extremums.

On weekdays, everything works fine, but with Monday's opening,the pending orders are not placed at Friday's extremes, but at Thursday's levels for some reason. How come?

OpenTime="00:00";
currtime=TimeToStr(TimeCurrent(),TIME_MINUTES);
Format=Digits();
DH=NormalizeDouble(iHigh(NULL,PERIOD_D1,1),Format) ;
DL=NormalizeDouble(iLow(NULL,PERIOD_D1,1),Format);
if (currtime==OpenTime)
{
отложки
}
 
Ibragim Dzhanaev:
You mean like this? Are there any other options - simpler?

Yeah, that's about right. How much simpler?

 
Vitalie Postolache:

Yeah, that's about right. How much easier could it be?

Do you happen to know any lessons on arrays? If you do, please send me the link.
Reason: