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

 
Andrey Sokolov #:

In mql you can also fill an array from the keyboard, but you don't need to)))

Andrei! Programming. Creativity. The flight of thoughts and fantasies. Can't hold them in the cells of gray matter. I want it off the keyboard. It's not a pretense. It's just that my desire is a figment of my imagination. I'd like it like this, from the keyboard.
 
vladeimirami #:
Andrei! Programming. Creativity. Flying thoughts and fantasies. Not keeping them in the cells of gray matter. I want it off the keyboard. It's not a pretense. It's just that my desire is a figment of my imagination. I'd like it like this, from the keyboard.

I'll make it simple. Questions are appropriate in specialist topics/forums.

 
Andrey Sokolov #:

I'll make it simple. Questions are appropriate in specialist threads/forums.

Andrey, maybe this question was raised in the forum like mine? If there is something on the forum please give me a link. Or should we open this discussion on the forum?

In any case thanks a lot!

 
vladeimirami #:
Andrei! Programming. Creativity. The flight of thoughts and fantasies. Can not hold them in the cells of gray matter. I want it off the keyboard. It's not a pretense. It's just that my desire is a figment of my imagination. I'd like it like this, from the keyboard.

read the array from the file. And edit the file in any text editor :-)

 
Andrey Sokolov #:

"Do this - I won't tell you how."

Why didn't you figure it out yourself? And tell the uservladeimirami how to do it. It's all in the documentation:

https://www.mql5.com/ru/docs/event_handlers/onchartevent

//Пример слушателя событий графика

//+------------------------------------------------------------------+
//|                                          OnChartEvent_Sample.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property description "Пример слушателя событий графика и генератора пользовательских событий"
//--- идентификаторы служебных клавиш
#define  KEY_NUMPAD_5       12
#define  KEY_LEFT           37
#define  KEY_UP             38
#define  KEY_RIGHT          39
#define  KEY_DOWN           40
#define  KEY_NUMLOCK_DOWN   98
#define  KEY_NUMLOCK_LEFT  100
#define  KEY_NUMLOCK_5     101
#define  KEY_NUMLOCK_RIGHT 102
#define  KEY_NUMLOCK_UP    104
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- выведем значение константы CHARTEVENT_CUSTOM
   Print("CHARTEVENT_CUSTOM=",CHARTEVENT_CUSTOM);
//---
   Print("Запущен эксперт с именем ",MQLInfoString(MQL5_PROGRAM_NAME));
//--- установка флага получения событий создания объектов графика
   ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_CREATE,true);
//--- установка флага получения событий удаления объектов графика
   ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_DELETE,true);
//--- включение сообщений о прокрутке колесика мышки
   ChartSetInteger(0,CHART_EVENT_MOUSE_WHEEL,1);
//--- принудительное обновление свойств графика гарантирует готовность к обработке событий
   ChartRedraw();
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- счетчик тиков для генерации пользовательского события 
   static int tick_counter=0;
//--- будем делить накопленные тики на это число
   int simple_number=113;
//--- 
   tick_counter++;
//--- отправляем пользовательское событие, если счетчик тиков кратен simple_number
   if(tick_counter%simple_number==0)
     {
      //--- сформируем идентификатор пользовательского события в диапазоне от 0 до 65535
      ushort custom_event_id=ushort(tick_counter%65535);
      //---  отправим пользовательское событие с заполнением параметров
      EventChartCustom(ChartID(),custom_event_id,tick_counter,SymbolInfoDouble(Symbol(),SYMBOL_BID),__FUNCTION__);
      //--- сделаем вывод в лог для изучения и анализа результатов примера
      Print(__FUNCTION__,": Отправлено пользовательcкое событие ID=",custom_event_id);
     }
//---     
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//--- нажатие кнопки на клавиатуре
   if(id==CHARTEVENT_KEYDOWN)
     {
      switch((int)lparam)
        {
         case KEY_NUMLOCK_LEFT:  Print("Нажата KEY_NUMLOCK_LEFT");   break;
         case KEY_LEFT:          Print("Нажата KEY_LEFT");           break;
         case KEY_NUMLOCK_UP:    Print("Нажата KEY_NUMLOCK_UP");     break;
         case KEY_UP:            Print("Нажата KEY_UP");             break;
         case KEY_NUMLOCK_RIGHT: Print("Нажата KEY_NUMLOCK_RIGHT");  break;
         case KEY_RIGHT:         Print("Нажата KEY_RIGHT");          break;
         case KEY_NUMLOCK_DOWN:  Print("Нажата KEY_NUMLOCK_DOWN");   break;
         case KEY_DOWN:          Print("Нажата KEY_DOWN");           break;
         case KEY_NUMPAD_5:      Print("Нажата KEY_NUMPAD_5");       break;
         case KEY_NUMLOCK_5:     Print("Нажата KEY_NUMLOCK_5");      break;
         default:                Print("Нажата какая-то неперечисленная клавиша");
        }
     }
//--- нажатие левой кнопкой мышки на графике
   if(id==CHARTEVENT_CLICK)
      Print("Координаты щелчка мышки на графике: x = ",lparam,"  y = ",dparam);
//--- нажатие мышкой на графическом объекте
   if(id==CHARTEVENT_OBJECT_CLICK)
      Print("Нажатие кнопки мышки на объекте с именем '"+sparam+"'");
//--- удален объект
   if(id==CHARTEVENT_OBJECT_DELETE)
      Print("Удален объект с именем ",sparam);
//--- создан объект
   if(id==CHARTEVENT_OBJECT_CREATE)
      Print("Создан объект с именем ",sparam);
//--- изменен объект
   if(id==CHARTEVENT_OBJECT_CHANGE)
      Print("Изменен объект с именем ",sparam);
//--- перемещен объект или изменены координаты точек привязки
   if(id==CHARTEVENT_OBJECT_DRAG)
      Print("Изменение точек привязки объекта с именем ",sparam);
//--- изменен текст в поле ввода графического объекта Edit
   if(id==CHARTEVENT_OBJECT_ENDEDIT)
      Print("Изменен текст в объекте Edit ",sparam,"  id=",id);
//--- события перемещения мышки
   if(id==CHARTEVENT_MOUSE_MOVE)
      Comment("POINT: ",(int)lparam,",",(int)dparam,"\n",MouseState((uint)sparam));
   if(id==CHARTEVENT_MOUSE_WHEEL)
     {
      //--- разберем состояние кнопок и колесика мышки для этого события 
      int flg_keys = (int)(lparam>>32);          // флаг состояний клавиш Ctrl, Shift и кнопок мышки
      int x_cursor = (int)(short)lparam;         // X-координата, в которой произошло событие колесика мышки
      int y_cursor = (int)(short)(lparam>>16);   // Y-координата, в которой произошло событие колесика мышки
      int delta    = (int)dparam;                // суммарное значение прокрутки колесика, срабатывает при достижении +120 или -120
      //--- обработаем флаг 
      string str_keys="";
      if((flg_keys&0x0001)!=0)
         str_keys+="LMOUSE ";
      if((flg_keys&0x0002)!=0)
         str_keys+="RMOUSE ";
      if((flg_keys&0x0004)!=0)
         str_keys+="SHIFT ";
      if((flg_keys&0x0008)!=0)
         str_keys+="CTRL ";
      if((flg_keys&0x0010)!=0)
         str_keys+="MMOUSE ";
      if((flg_keys&0x0020)!=0)
         str_keys+="X1MOUSE ";
      if((flg_keys&0x0040)!=0)
         str_keys+="X2MOUSE ";
 
      if(str_keys!="")
         str_keys=", keys='"+StringSubstr(str_keys,0,StringLen(str_keys)-1)+"'";
      PrintFormat("%s: X=%d, Y=%d, delta=%d%s",EnumToString(CHARTEVENT_MOUSE_WHEEL),x_cursor,y_cursor,delta,str_keys);
     }
//--- изменение размеров графика или изменение свойств графика через диалог свойств
   if(id==CHARTEVENT_CHART_CHANGE)
      Print("Изменение размеров или свойств графика");
//--- пользовательское событие
   if(id>CHARTEVENT_CUSTOM)
      PrintFormat("Пользовательское событие ID=%d, lparam=%d, dparam=%G, sparam=%s",id,lparam,dparam,sparam);
  }
//+------------------------------------------------------------------+
//| MouseState                                                       |
//+------------------------------------------------------------------+
string MouseState(uint state)
  {
   string res;
   res+="\nML: "   +(((state& 1)== 1)?"DN":"UP");   // mouse left
   res+="\nMR: "   +(((state& 2)== 2)?"DN":"UP");   // mouse right 
   res+="\nMM: "   +(((state&16)==16)?"DN":"UP");   // mouse middle
   res+="\nMX: "   +(((state&32)==32)?"DN":"UP");   // mouse first X key
   res+="\nMY: "   +(((state&64)==64)?"DN":"UP");   // mouse second X key
   res+="\nSHIFT: "+(((state& 4)== 4)?"DN":"UP");   // shift key
   res+="\nCTRL: " +(((state& 8)== 8)?"DN":"UP");   // control key
   return(res);
  }

Extend the list of constants to the required ones:

#define  KEY_NUMPAD_5       12
#define  KEY_LEFT           37
#define  KEY_UP             38
#define  KEY_RIGHT          39
#define  KEY_DOWN           40
#define  KEY_NUMLOCK_DOWN   98
#define  KEY_NUMLOCK_LEFT  100
#define  KEY_NUMLOCK_5     101
#define  KEY_NUMLOCK_RIGHT 102
#define  KEY_NUMLOCK_UP    104

Where to get values for the constants:. Google "C++ key codes" (as I said before). And process it:

//--- нажатие кнопки на клавиатуре
   if(id==CHARTEVENT_KEYDOWN)
     {
      switch((int)lparam)
        {
         case KEY_NUMLOCK_LEFT:  Print("Нажата KEY_NUMLOCK_LEFT");   break;
         case KEY_LEFT:          Print("Нажата KEY_LEFT");           break;
         case KEY_NUMLOCK_UP:    Print("Нажата KEY_NUMLOCK_UP");     break;
         case KEY_UP:            Print("Нажата KEY_UP");             break;
         case KEY_NUMLOCK_RIGHT: Print("Нажата KEY_NUMLOCK_RIGHT");  break;
         case KEY_RIGHT:         Print("Нажата KEY_RIGHT");          break;
         case KEY_NUMLOCK_DOWN:  Print("Нажата KEY_NUMLOCK_DOWN");   break;
         case KEY_DOWN:          Print("Нажата KEY_DOWN");           break;
         case KEY_NUMPAD_5:      Print("Нажата KEY_NUMPAD_5");       break;
         case KEY_NUMLOCK_5:     Print("Нажата KEY_NUMLOCK_5");      break;
         default:                Print("Нажата какая-то неперечисленная клавиша");
        }
     }

Instead of string with Print, insert function which adds value to array depending on key pressed. What is so hard?

Документация по MQL5: Обработка событий / OnChartEvent
Документация по MQL5: Обработка событий / OnChartEvent
  • www.mql5.com
OnChartEvent - Обработка событий - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Mihail Matkovskij #:

Why didn't you figure it out yourself? And tell the uservladeimirami how to do it. After all, everything is in the documentation:

https://www.mql5.com/ru/docs/event_handlers/onchartevent

Extend the list of constants to the required ones:

Where to get values for the constants:. Google "C++ key codes" (as I said before). And process it:

Instead of string with Print, insert function which adds value to array depending on key pressed. What is so complicated?

At least read what you're answering and who was answering what to whom before rushing to hit the keys

 
Mihail Matkovskij #:

Why didn't you figure it out yourself? And tell the uservladeimirami how to do it. After all, everything is in the documentation:

https://www.mql5.com/ru/docs/event_handlers/onchartevent

Extend the list of constants to the required constants:

Where to get the values for the constants:. Google "C++ key codes" (as I said before). And process it:

Instead of a string with Print, we insert a function which adds a value to the array depending on the key pressed. What is so complicated?

It will be tricky if you need to write a number in the array instead of the code of the pressed key. For example 123. Here, there will be three array cells filled in - each with the values 1, 2 and 3, not one with the value 123.

This means that you have to read the keys separately and end them separately. In other words, let the program know that a number entry has started and let it know that it is finished and you can write the entered number to the array.

 
Andrey Sokolov #:

At least read what you're answering.

Oh... okay. I'm confused. I have to write a lot. That's why I could be wrong.

But I get the impression that you're the one who doesn't know what to do or how to do it... You could have helpedvladeimirami.

 
Artyom Trishkin #:

There will be a complication if you need to write a number into the array rather than the code of the key pressed. For example 123. This will fill three cells in the array - each will have values 1, 2 and 3, not one with the value 123.

This means that you have to read the keys separately and end them separately. In other words, let the program know that number entry has started and let it know that it's finished and you can write the entered number to the array.

If the array is uchar then you can useStringToCharArray. Or create your own function that adds a number to each cell in a string. Just the length of the string can be easily obtained and you can loop through it.

 
Mihail Matkovskij #:

Ah... all right. I'm confused. I have to write a lot. So I could be wrong.

But I get the impression that you're the one who doesn't know what to do or how to do it... You could have helpedvladeimirami.

Your pointless trolling is clearly unnecessary here. And those answers that aren't trolling are either wrong or a lie altogether.

All of your responses over the last few pages are either misinforming or bullshit, lying and trolling, I don't understand why you write them, unless you're tweaking the post count, they are of no use, only detrimental.