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

 
EVGENII SHELIPOV #:

Good afternoon!!! Happy New Year everyone!!!

Water code removing horizontal line

Thanks for the help.

This is more than enough.

//-------------------------------------------------------------------+  Команда на удаление линий отображающую среднюю цену
   if(CountTrade() == 0)
     {
      ObjectsDeleteAll(0,"AveragePriceLine");
     }
EVGENII SHELIPOV #:

The question is very simple you need to know the coordinates of the inscription with reference to the horizontal line as I do not know how to calculate it.

Here you can help

ChartTimePriceToXY

ChartXYToTimePrice

 
Tretyakov Rostyslav #:

That's more than enough.

Here's where you can get help.

ChartTimePriceToXY

ChartXYToTimePrice

Thanks for the tip Rostislav, but I'm doing something wrong.

I need to change only the 0Y axis, but the inscription does not want to marry with the horizontal line.

I am attaching code and screenshot please advise where is the error?

//+----------------------------------------------------------------------------+
//| Расчет среденй цены (0)-buy (1)-sell ()-all                                |
//+----------------------------------------------------------------------------+
double GetAveragePrice(int ot=-1)
  {
   double order_lots = 0, order_price = 0, avg_price = 0;
   int x = 0, y = 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);
   ObjectCreate("signal4",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("signal4",OBJPROP_XDISTANCE,500);
   ChartTimePriceToXY(0, 0, 0,avg_price, x, y);
   ObjectSet("signal4",OBJPROP_YDISTANCE, y + 10);
   ObjectSetText("signal4","- Средняя цена сетки ордеров на покупку",14,"Times New Roman", clrLime);
   if(ot==1)
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrRed);
   ObjectCreate("signal3",OBJ_LABEL,0, 0, 0, 0, 0);
   ObjectSet("signal3",OBJPROP_XDISTANCE, 500);
   ChartTimePriceToXY(0, 0, 0, avg_price, x, y);
   ObjectSet("signal3",OBJPROP_YDISTANCE, y + 10);
   ObjectSetText("signal3","- Средняя цена сетки ордеров на продажу", 14, "Times New Roman", clrRed);
   return(avg_price);
  }


 
EVGENII SHELIPOV #:

Thanks for the tip, Rostislav, but I'm doing something wrong.

I need to change only the 0Y axis, but the inscription does not want to marry with the horizontal line.

I am attaching the code and a screenshot, can you tell me where the error is?

Don't forget the brackets.

//+----------------------------------------------------------------------------+
//| Расчет среденй цены (0)-buy (1)-sell ()-all                                |
//+----------------------------------------------------------------------------+
double GetAveragePrice(int ot=-1)
  {
   double order_lots = 0, order_price = 0, avg_price = 0;
   int x = 0, y = 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);
      ObjectCreate("signal4",OBJ_LABEL,0,0,0,0,0);
      ObjectSet("signal4",OBJPROP_XDISTANCE,500);
      ChartTimePriceToXY(0, 0, 0,avg_price, x, y);
      ObjectSet("signal4",OBJPROP_YDISTANCE, y + 10);
      ObjectSetText("signal4","- Средняя цена сетки ордеров на покупку",14,"Times New Roman", clrLime);
     }
   if(ot==1)
     {
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrRed);
      ObjectCreate("signal3",OBJ_LABEL,0, 0, 0, 0, 0);
      ObjectSet("signal3",OBJPROP_XDISTANCE, 500);
      ChartTimePriceToXY(0, 0, 0, avg_price, x, y);
      ObjectSet("signal3",OBJPROP_YDISTANCE, y + 10);
      ObjectSetText("signal3","- Средняя цена сетки ордеров на продажу", 14, "Times New Roman", clrRed);
     }
   return(avg_price);
  }
 
Tretyakov Rostyslav #:

Don't forget the brackets.

No, there's something else missing.

 
EVGENII SHELIPOV #:

No, something else is missing

There must be errors in the logbook
 

Copying to an array

MqlRates CopySymb[];  
if(CopyRates(mSymbol,PERIOD_CURRENT,0,6,CopySymb)<0) return;
Print( ArrayMaximum(???) );

How do I get the maximum high in an array?

 
Vitaly Muzichenko #:

Copying to an array

How to get the maximal high in an array?

Additionally copy CopyHigh and get the maximal from this array. I understand that through ...it... but the only other way is to try over in the loop.

 
Alexey Viktorov #:

Additionally copy CopyHigh and get maximal from this array. I understand that through ...it... but the other option is only looping.

I did so, but it is additional copying. Using a loop is also not an option.

I'll leave it withCopyHigh.

 
Vitaly Muzichenko #:

I did, but it's an extra copy. Through the loop is not an option either.

I'll leave it throughCopyHigh then.

I've been thinking about it for a long time. And I've come to the conclusion, that if we need to look for minimum/maximum from MqlRates array, it's better to copy required data to different double arrays.

 
Vitaly Muzichenko #:

Copying to an array

How do I get the maximum high in an array?

CopySymb[i].high
Reason: