Questions from Beginners MQL5 MT5 MetaTrader 5 - page 630

 
Alexey Volchanskiy:

1. now look at the screen resolution and scale. I don't know how to do this on 8.1, I'm on 10 myself at the moment. You clearly have all the controls displaced. It's typical when you write a program for a standard scale, and the user usually sets it to a larger scale. You don't have a notebook with a small screen there, do you? They usually zoom in because it's hard to see small elements.

This is how it's set up on 10.

2. You have to set it to standard - 100%

1. I have a laptop with a "big" screen... :-)

2. So I did.

Thanks for the help...

 
Roman Shiredchenko:

1. I have a Notebook with a "big" screen... :-)

2. So I did.

Thanks for the help...

Thought about the resolution as well, while reading the question - got beaten to the answer.

You understand yourself - it's unrealistic to write a platform for all screens of any device)

 
new-rena:

I was thinking about the resolution too, when I read the question, you got ahead of me.

You know, it's impossible to write a platform for all screens of any device)

Sens... :-) Haven't been here in a while... Business... :-)

Same old faces. What's good!

Although you can't see many of them...

 
I can't remember and can't find in the documentation how to split the comment line of the EA parameters, in the window called by F7.
 
new-rena:

I was thinking about the resolution too, but when I read the question, the answer got ahead of me.

You understand yourself - it's unrealistic to write a platform for all screens of any device)

Yes, I remember when we wrote for the Windows and started delivering widescreens to customers, we had a lot of trouble with GUI redesign
 
Vladimir Tkach:
I can't remember and can't find in the documentation how to split the comment line of the EA parameters, in the window called by F7.

sinput string separator = "";   //в комментарий записать пустой символ "Alt+(Num)255"
 
Hello!
// Существует алгоритм сортировки "ПУЗЫРЬКОМ" по убыванию

void bubble_sort(int &a[], int length)
   {
    for(int i=0; i<length-1; i++)
        {
         bool swapped = false;
         for(int j=0; j<length-i-1; j++)
             {
              if(a[j] < a[j+1])
                  {
                   int b = a[j];
                   a[j] = a[j+1];
                   a[j+1] = b;
                   swapped = true;
                  }
             }
         if(!swapped)
              break;
        }
   }

// Есть массив D[][2]. Подскажите пожалуйста, как правильно организовать сортировку массива D[][2] 
// сначала по параметру с индексом "0", а потом по параметру с индексом "1"
// Такой вариант не проходит (сортирует не правильно):

double D[][2];                                   // Исходный динамический массив
double S[2];                                     // Временный статический массив

//        Исходный     Сортировка по индексу "0"    Сортировка по индексу "1"
//          7  4                  9  5                         9  8
//          3  9                  9  8                         9  5
//          9  5                  7  4                         7  6                              
//          9  8                  7  6                         7  4
//          7  6                  3  9                         3  9
//         ......

int    R=ArrayRange(D, 0);
       Fun();

void Fun()
   {
    int n=0;                                     // Техническая переменная
    int cur_0=0;                                 // Значение массива D[j]  [0] в строке с индексом "j"
    int fol_0=0;                                 // Значение массива D[j+1][0] в строке с индексом "j+1" 
    int cur_1=0;                                 // Значение массива D[j]  [1] в строке с индексом "j"
    int fol_1=0;                                 // Значение массива D[j+1][1] в строке с индексом "j+1" 

    for(int i=0; i<R-1; i++)                     // Сортировка по индексу "0"
        {
         bool swapped = false;
         for(int j=0; j<R-i-1; j++)
             {
              cur_0=a[j]  [0];
              fol_0=a[j+1][0];
              if(cur_0 < fol_0)
                  {
                   for(n=0; n<2; n++)
                        S[n]=D[j][n];            // Значения из строки [j] во временный массив 
                   for(n=0; n<2; n++)
                        D[j][n]=D[j+1][n];       // Значения из строки [j+1] в строку [j]
                   for(n=0; n<2; n++)
                        D[j+1][n]=S[n];          // Значения из временного массива в строку [j+1]
                   swapped = true;
                  }
             }
         if(!swapped)
              break;
        }

    for(i=0; i<R-1; i++)                         // Сортировка по индексу "1"
        {
         swapped = false;
         for(j=0; j<R-i-1; j++)
             {
              cur_0=a[j]  [0];
              fol_0=a[j+1][0];
              cur_1=a[j]  [1];
              fol_1=a[j+1][1];
              if( (cur_0 == fol_0) &&            // При равенстве значений по индексу "0"
                  (cur_1 <  fol_1) )
                  {
                   for(n=0; n<2; n++)
                        S[n]=D[j][n];            // Значения из строки [j] во временный массив 
                   for(n=0; n<2; n++)
                        D[j][n]=D[j+1][n];       // Значения из строки [j+1] в строку [j]
                   for(n=0; n<2; n++)
                        D[j+1][n]=S[n];          // Значения из временного массива в строку [j+1]
                   swapped = true;
                  }
             }
         if(!swapped)
              break;
        }
   }
How to make it like in Excel ))

Everything works great!!!! It was not the algorithm. The issue is resolved.
 

Decided here by quadruplet:

There is indicator code. It counts and draws asc and bid lines + counts average speed X of fresh Num_Aver_of_Ticks ticks received in Sec_at_Num_Aver_of_Ticks seconds. X = Num_Aver_of_Ticks / (time_s - ExtMapBuffer3[Num_Aver_of_Ticks]);

How do I read the value of this variable X (see end of start function) in the EA?

//+------------------------------------------------------------------
//
//
//
//
//+------------------------------------------------------------------
#property copyright "ROMANBEST"
#property link      "rshiredchenko@mail.ru"

#property indicator_separate_window
#property indicator_buffers 2
#property  indicator_color1 clrLimeGreen
#property  indicator_color2 clrBlue           // Цвет второй линии
//#property indicator_color3 clrGray         // Цвет третьей линии - гистограммы
//---- buffers
extern int MaxDrawTicks=100;
extern int Num_Aver_of_Ticks=15;
//--- Создаём динамические массивы
double ExtMapBuffer1[];                      // Индикаторный массив значений цен Bid
double ExtMapBuffer2[];                      // Индикаторный массив значений цен Ask 
              // Кол-во тиков для среднего Num_Aver_of_Ticks / кол-во секунд, за которое эти тики поступили 
 // При обращении к любому члену массива по индексу (допустим i) нужно убедиться что i>=0 и i<ArraySize(High) 
double ExtMapBuffer3[];                      // Массив значений времени в сек. с момента запуска индикатора 
int size;                                    // Вспомогательная переменная для массива
 // При обращении к любому члену массива по индексу (допустим i) нужно убедиться что i>=0 и i<ArraySize(High) 

                                  
int myBars;
int i;
int delimeterCounter;
int _start,tickCounter;
double Sec_at_Num_Aver_of_Ticks; // кол-во секунд, за которое  поступило среднее количество тиков для расчёта 
                                 // (Num_Aver_of_Ticks)
  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexBuffer(0, ExtMapBuffer1);           // Назначение массива буферу
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);  // Стиль линии    
   SetIndexEmptyValue(0,0.0);
   
   SetIndexBuffer(1, ExtMapBuffer2);           // Назначение массива буферу
   SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,2);  // Стиль линии    
   SetIndexEmptyValue(1,0.0); 
 
   
    
//--- устанавливаем размер динамического массива
   if(ArrayResize(ExtMapBuffer3,MaxDrawTicks)<0) {Print(" Ошибка в изменении размера массива времени поступления тиков "); return(false);}
//--- установим индексацию для буфера как в таймсерии для динамического массива
    // ArraySetAsSeries(ExtMapBuffer3,true);
    
//---   Возвращает количество элементов указанного массива. 
   size=ArraySize(ExtMapBuffer3);
   if (size>0) Print("Размер массива: ",size);
   else Print("Ошибка. Массив пустой ",size);     
                                                          // for(int i=0;i<=100;i++) Print(" ExtMapBuffer3[i] = ", ExtMapBuffer3[i]);   
   //--- заполняем начальные 50 элементов значением 4
 //  ArrayFill(ExtMapBuffer3,0,50,4);
//--- заполняем 50 элементов (начиная с 50-го) значением 8
 //   ArrayFill(ExtMapBuffer3,50,50,8);
//--- выводим значения всех элементов
 //  for(int i=0;i<ArraySize(ExtMapBuffer3);i++) Print(" i =  ", i, " ExtMapBuffer3 =  ", ExtMapBuffer3[i]);                      

//   ------------
   
   Print("Обнуляем тики и время их поступления");
   for (i=Bars-1;i>=0;i--) { ExtMapBuffer1[i]=0.0; ExtMapBuffer2[i]=0.0; ExtMapBuffer3[i]=0.0;} 
  
   //--- запомним начальное значение для подсчёта секунд c момента старта системы
   _start = GetTickCount();   
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| сдвинем массив                                                   |
//+------------------------------------------------------------------+
void SetDelimeter()
  {
//----
   string delimeterDate=TimeToStr(Time[0]);
   if (myBars!=0)
      {
      Print("Ставим разделитель");      
      int handle=WindowFind("Ticks");
      if(!ObjectCreate(delimeterDate,OBJ_VLINE,handle,Time[0],0))
         {
         Print("Неудачная попытка создания разделителя в окне ",
         handle," по времени ",TimeToStr(CurTime()));
         Print("Ошибка №",GetLastError(),", имя разделителя ",delimeterDate);
         }
      else 
         {
         ObjectSet(delimeterDate,OBJPROP_COLOR,DarkGreen);
         ObjectSet(delimeterDate,OBJPROP_STYLE,STYLE_DASHDOT);
         ObjectsRedraw();
         }
      }
//----   
  }
//+------------------------------------------------------------------+
//| сдвинем массив                                                   |
//+------------------------------------------------------------------+
void ShiftArray()
  {
//----
   int V_lines;
   string delimeterName;
   datetime firstTime;
   int BarFirstTime;
   
   if (tickCounter>2*MaxDrawTicks)
      {
      for (i=tickCounter;i>=MaxDrawTicks;i--) { ExtMapBuffer1[i]=0.0; ExtMapBuffer2[i]=0.0; ExtMapBuffer3[i]=0.0; }
      tickCounter=MaxDrawTicks;
      }
   for(int cnt=tickCounter;cnt>0;cnt--)
      {
      ExtMapBuffer1[cnt]=ExtMapBuffer1[cnt-1];
      ExtMapBuffer2[cnt]=ExtMapBuffer2[cnt-1];
      ExtMapBuffer3[cnt]=ExtMapBuffer3[cnt-1];
      }
   V_lines=ObjectsTotal();
   for (int z=0;z<V_lines;z++)
      {
      delimeterName=ObjectName(z); 
      if (ObjectFind(delimeterName)!=-1)
         {
         if (ObjectType(delimeterName)==OBJ_VLINE) 
            {
            firstTime=ObjectGet(delimeterName,OBJPROP_TIME1);
            BarFirstTime=iBarShift(NULL,0,firstTime);
            firstTime=Time[BarFirstTime+1];
            ObjectSet(delimeterName,OBJPROP_TIME1,firstTime); 
            }
         }       
      }
//----   
  }
//+------------------------------------------------------------------+
//| признак нового бара                                              |
//+------------------------------------------------------------------+
bool isNewBar()
  {
//----
   bool res=false;
   if (myBars!=Bars)
      {
      res=true;
      myBars=Bars;
      }   
//----
   return(res);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {   
  //--- выводим значения всех элементов
   // for(int i=0;i<ArraySize(ExtMapBuffer3);i++) Print(" i =  ", i, " ExtMapBuffer3 =  ", ExtMapBuffer3[i]);      
   //--- получим время в миллисекундах, прошедших с момента старта системы 
   uint time_ms=GetTickCount() - _start;
   //--- получим время в секундах, прошедших с момента старта системы 
   double time_s=time_ms/1000;
   double X;                      // вспомогательная переменная 
   
   int    counted_bars=IndicatorCounted();
//----
   if (isNewBar())
     {
      // установить разделитель
      //tickCounter++;
      SetDelimeter();
      ExtMapBuffer1[0]=Bid;  
      ExtMapBuffer2[0]=Ask; 
             //ExtMapBuffer3[0]= time_s;  
      //--- заполняем c tickCounter элементов значением time_s
     // ArrayFill(ExtMapBuffer3,tickCounter,1,time_s);  
     if (tickCounter >= 0 && tickCounter < ArraySize(ExtMapBuffer3) && tickCounter <= Num_Aver_of_Ticks)    
     {
      //--- заполняем начальный и последующие элементы значениями time_s
      if (tickCounter == 0) ArrayFill(ExtMapBuffer3,0,1,time_s);
      else                  ArrayFill(ExtMapBuffer3,tickCounter,1,time_s);
      //--- выводим значение элемента
       for( i=0;i<1;i++) Print(" tickCounter =  ", tickCounter, " ExtMapBuffer3 =  ", ExtMapBuffer3[tickCounter]);     
     }        
     }
   else
      
     {
      tickCounter++;
      ShiftArray();
      ExtMapBuffer1[0]=Bid; 
      ExtMapBuffer2[0]=Ask;  
      ExtMapBuffer3[0]= time_s;  
      // массив    // индекс начального элемента // количество элементов // значение, которым заполняется массив      
      //--- заполняем начальные (с нуля) tickCounter  элементов значением time_s
      //ArrayFill(ExtMapBuffer3,tickCounter,1,time_s);    
                                              // X = tickCounter/time_s;  
       if (tickCounter >= 0 && tickCounter < ArraySize(ExtMapBuffer3) && tickCounter <= Num_Aver_of_Ticks)    
          {
      //--- заполняем начальный и последующие элементы значениями time_s
            if (tickCounter == 0) ArrayFill(ExtMapBuffer3,0,1,time_s);
            else                  ArrayFill(ExtMapBuffer3,tickCounter,1,time_s);
      //--- выводим значение элемента
           for( i=0;i<1;i++) Print(" tickCounter =  ", tickCounter, " ExtMapBuffer3 =  ", ExtMapBuffer3[tickCounter]);     
          }                                                                         
     }
 /*    
    if (tickCounter > Num_Aver_of_Ticks) то ищем индекс массива с минимумом http://docs.mql4.com/ru/array/arrayminimum и заполняем его значением секунд 
    следующего тика...   Потом считаем разность между этим значением и следующим минимумом...
    Псле заполнения массива до ExtMapBuffer3[Num_Aver_of_Ticks]. Читать минимум, максимум. Переписываем минимум. Разница значений 
    ExtMapBuffer3[максимум] и ExtMapBuffer3[минимум] будет время в секундах поступления Num_Aver_of_Ticks.
    
*/    
      Sec_at_Num_Aver_of_Ticks =  time_s - ExtMapBuffer3[Num_Aver_of_Ticks];
      
      if (tickCounter >= Num_Aver_of_Ticks  && (time_s - ExtMapBuffer3[Num_Aver_of_Ticks])!=0) 
          X = Num_Aver_of_Ticks / (time_s - ExtMapBuffer3[Num_Aver_of_Ticks]);        
       
      
     if (time_s!=0) 
       Comment(
              "tickCounter = ", tickCounter, "\n",
              "secondCounter = ",    NormalizeDouble(time_s,Digits) , "\n",
              "ExtMapBuffer1[0] = ", NormalizeDouble(ExtMapBuffer1[0],Digits) , "\n",
              "ExtMapBuffer2[0] = ", NormalizeDouble(ExtMapBuffer2[0],Digits) , "\n",
              "ExtMapBuffer3[0] = ", NormalizeDouble(ExtMapBuffer3[0],Digits) , "\n",
              "Average speed for average quantity of tics = ", NormalizeDouble(X,2), " Num_Aver_of_Ticks/Sec_at_Num_Aver_of_Ticks ", "\n",
              "Num_Aver_of_Ticks =  ", Num_Aver_of_Ticks," Время в секундах поступления  Num_Aver_of_Ticks = ",Sec_at_Num_Aver_of_Ticks  , "\n",
              "Average speed since running = ", NormalizeDouble(tickCounter/time_s,Digits) , " All Tick/All Second ", "\n",
              
              
           "") ;    
                    
            
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
Roman Shiredchenko:

Decided here by quadruplet:

there is indicator code. It counts and draws the asc and bid lines + counts the average rate X of fresh Num_Aver_of_Ticks ticks received per Sec_at_Num_Aver_of_Ticks seconds. X = Num_Aver_of_Ticks / (time_s - ExtMapBuffer3[Num_Aver_of_Ticks]);

How do I read the value of this variable X (see end of start function) in the EA?

It's hard to look at the code on the tablet, but the answer is to write the value of X into the buffer.
 
Artyom Trishkin:
It is difficult to look at code on the tablet, but the answer is inevitable - write value Х in the buffer.

Thank you. Artyom. The same goes for me... :-)


I wrote this indict long ago, and used Rosha's code from kodobase as a base.

Reason: