Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1694

 
Aleksei Stepanenko #:

I don't know why it's done that way, it's essentially a boolean function.

It goes something like this:

In enum, the elements start with zero, so Ok=0 , AllocError=1

i.e. GetRepeat returns either 0 or 1

respectively ! GetRepeat is a negation of the return value

0 is false, 1 is true.


It is easy to break your head

Exactly!)) Thanks, Alexey!

 
You're welcome :)
 

Good day!!!

Here is a function to calculate the average price of a grid of orders and display it on a chart. After the grid is closed, horizontal lines showing the average line are not deleted.

Please help us to write a function that these lines will be deleted after the grid of orders is closed. Thank you!!!

//+----------------------------------------------------------------------------+
//| Расчет среденй цены (0)-buy (1)-sell ()-all                                |
//+----------------------------------------------------------------------------+
double GetAveragePrice(int ot=-1)
  {
   double order_lots = 0, order_price = 0, avg_price = 0;
     {
      for(int i = OrdersTotal()-1; i>=0; i--)
        {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
           {
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
              {
               if(OrderType()==ot||ot<0)
                 {
                  order_lots += OrderLots();
                  order_price += OrderOpenPrice() * OrderLots();
                 }
              }
           }
        }
     }
   avg_price = NormalizeDouble(order_price / order_lots, Digits);

   if(ObjectFind(0,"AveragePriceLine"+IntegerToString(ot))!=0)
      ObjectCreate(0,"AveragePriceLine"+IntegerToString(ot),OBJ_HLINE, 0, 0, avg_price);
   else
      ObjectSetDouble(0,"AveragePriceLine"+IntegerToString(ot),OBJPROP_PRICE,avg_price);
   if(ot==0)
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrLime);
   if(ot==1)
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrMagenta);
   return(avg_price);
  }

 
EVGENII SHELIPOV #:

Good day!!!

Here is a function to calculate the average price of a grid of orders and display it on a chart. After the grid is closed, horizontal lines showing the average line are not deleted.

Please help us to write a function that these lines will be deleted after the grid of orders is closed. Thank you!!!

This is not the place to do it.

void OnTick()
  {
//---
   if(ObjectFind(0,"AveragePriceLine"+0)==0&&CountTrade(0)<1)//для бай
     {ObjectDelete(0,"AveragePriceLine"+0);}
   if(ObjectFind(0,"AveragePriceLine"+1)==0&&CountTrade(1)<1)//для селл
     {ObjectDelete(0,"AveragePriceLine"+1);}

   .....

  }
 
MakarFX #:

This is not the place to do it.

Makar, how do you bind this in void OnTick()

 
MakarFX #:

This is not the place to do it.

Thank you, Makar, a little file work and it's fine.

 

Please advise.

The Expert Advisor sets the start and end time of opening orders. I would like to have this time displayed on the chart. I have not been able to do it yet. Here is the code. I would like to ask you for help!

//-------------------------------------------------------------------+  Команда на открытие первых ордеров в сетке
   if((UseHour==1&&Hour()>=StartTime&&Hour()<=StopTime)||UseHour==0)
   ObjectCreate(0, "Начало торговли", OBJ_VLINE,0,0, StartTime);
   ObjectSetInteger(0, "Начало торговли",OBJPROP_COLOR, clrBlue);
   ObjectCreate(0,"Окончание торговли", OBJ_VLINE, 0, 0, StopTime);
   ObjectSetInteger(0, "Окончание торговли", OBJPROP_COLOR, clrBlue);
     {
      if(CountTrade(0)==0 && CountTrade(1)==0 && TradeSignal()==0)
         SendFirsOrder(0);
      if(CountTrade(1)==0 && CountTrade(0)==0 && TradeSignal()==1)
         SendFirsOrder(1);
     }
 
EVGENII SHELIPOV #:

Please advise.

The Expert Advisor sets the start and end time of opening orders. I would like to have this time displayed on the chart. I have not been able to do it yet. Here is the code. I would like to ask you for help!

Show StartTime and StopTime variables
 
MakarFX #:
Show the StartTime and StopTime variables
extern string               TIME                           = "Настройки времени";
extern int                  UseHour                        = 1;         // Торговля в установленное время "0"-ВЫКЛ, "1"-ВКЛ
extern int                  StartTime                      = 1;         // Начало торговли
extern int                  StopTime                       = 19;        // Окончание торговли
 
EVGENII SHELIPOV #:
   if((UseHour==1&&Hour()>=StartTime&&Hour()<=StopTime)||UseHour==0)
     {
      if(ObjectFind(0,"Начало торговли"+TimeToString(Time[0],TIME_DATE))!=0)
        {
         ObjectCreate(0,"Начало торговли"+TimeToString(Time[0],TIME_DATE),OBJ_VLINE,0,Time[0]+(StartTime*3600),0);
         ObjectSetInteger(0,"Начало торговли"+TimeToString(Time[0],TIME_DATE),OBJPROP_COLOR, clrBlue);
         ObjectCreate(0,"Окончание торговли"+TimeToString(Time[0],TIME_DATE),OBJ_VLINE,0,Time[0]+(StopTime*3600),0);
         ObjectSetInteger(0,"Окончание торговли"+TimeToString(Time[0],TIME_DATE),OBJPROP_COLOR, clrBlue);
        }
      if(CountTrade(0)==0 && CountTrade(1)==0 && TradeSignal()==0)
         SendFirsOrder(0);
      if(CountTrade(1)==0 && CountTrade(0)==0 && TradeSignal()==1)
         SendFirsOrder(1);
     }
Reason: