Errors, bugs, questions - page 37

 
kirill190982:
I'll probably ignore it for now, but in MQL4 the compiler didn't produce such remarks
That's a whole other issue, there were a lot of things that weren't there... :)
 
Interesting:

The variables are probably OK. Please see my post above...

I don't know, if you convert double to int, there will definitely be a loss, and if vice versa, there will most likely be an error during normalization, since the second function value is of int type
Документация по MQL5: Основы языка / Типы данных / Целые типы / Типы char, short, int и long
Документация по MQL5: Основы языка / Типы данных / Целые типы / Типы char, short, int и long
  • www.mql5.com
Основы языка / Типы данных / Целые типы / Типы char, short, int и long - Документация по MQL5
 
Interesting:

Question to the developers regarding "user" events and several experts working on the same terminal.

I want to know if I want to make it right or not?


The idea is this

In the course of the play we need to inform the "neighbouring" experts about some of the processes taking place.

...

If it is a good idea, it may be finished and formatted as an article. Or add it to the Help section dedicated to user events?

There is an example for function EventChartCustom:

//+------------------------------------------------------------------+
//|                                            ButtonClickExpert.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
 
string buttonID="Button";
string labelID="Info";
int broadcastEventID=5000;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- создадим кнопку, для передачи пользовательских событий
   ObjectCreate(0,buttonID,OBJ_BUTTON,0,100,100);
   ObjectSetInteger(0,buttonID,OBJPROP_COLOR,White);
   ObjectSetInteger(0,buttonID,OBJPROP_BGCOLOR,Gray);
   ObjectSetInteger(0,buttonID,OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0,buttonID,OBJPROP_YDISTANCE,100);
   ObjectSetInteger(0,buttonID,OBJPROP_XSIZE,200);
   ObjectSetInteger(0,buttonID,OBJPROP_YSIZE,50);
   ObjectSetString(0,buttonID,OBJPROP_FONT,"Arial");
   ObjectSetString(0,buttonID,OBJPROP_TEXT,"Кнопка");
   ObjectSetInteger(0,buttonID,OBJPROP_FONTSIZE,10);
   ObjectSetInteger(0,buttonID,OBJPROP_SELECTABLE,0);
 
//--- создадим метку для вывода информации
   ObjectCreate(0,labelID,OBJ_LABEL,0,100,100);
   ObjectSetInteger(0,labelID,OBJPROP_COLOR,Red);
   ObjectSetInteger(0,labelID,OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0,labelID,OBJPROP_YDISTANCE,50);
   ObjectSetString(0,labelID,OBJPROP_FONT,"Trebuchet MS");
   ObjectSetString(0,labelID,OBJPROP_TEXT,"Нет информации");
   ObjectSetInteger(0,labelID,OBJPROP_FONTSIZE,20);
   ObjectSetInteger(0,labelID,OBJPROP_SELECTABLE,0);
 
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   ObjectDelete(0,buttonID);
   ObjectDelete(0,labelID);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
 
  }
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//--- проверим событие на нажатие кнопки мышки
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      string clickedChartObject=sparam;
      //--- если нажатие на объекте с именем buttonID
      if(clickedChartObject==buttonID)
        {
         //--- состояние кнопки - нажата кнопка или нет
         bool selected=ObjectGetInteger(0,buttonID,OBJPROP_STATE);
         //--- выведем в лог отладочное сообщение
         Print("Кнопка нажата =",selected);
         int customEventID; // номер пользовательского события для отправки
         string message;    // сообщение для отправки в событии
         //--- если кнопка нажата
         if(selected)
           {
            message="Кнопка нажата";
            customEventID=CHARTEVENT_CUSTOM+1;
           }
         else // кнопка не нажата
           {
            message="Кнопка отжата";
            customEventID=CHARTEVENT_CUSTOM+999;
           }
         //--- отправим пользовательское событие "своему"графику
         EventChartCustom(0,customEventID-CHARTEVENT_CUSTOM,0,0,message);
         //--- отправим сообщение всем открытым графикам
         BroadcastEvent(ChartID(),0,"Broadcast Message");
         //--- отладочное сообщение
         Print("Отправлено событие с ID =",customEventID);
        }
      ChartRedraw();// принудительно перерисуем все объекты на графике
     }
 
//--- проверим событие на принадлежность к пользовательским событиям
   if(id>CHARTEVENT_CUSTOM)
     {
      if(id==broadcastEventID)
        {
         Print("Получили широковещательное сообщение от графика с id="+lparam);
        }
      else
        {
         //--- прочитаем текстовое сообщение в событии
         string info=sparam;
         Print("Обрабатывается ПОЛЬЗОВАТЕЛЬСКОЕ событие с ID =",id);
         //--- выведем сообщение в метке
         ObjectSetString(0,labelID,OBJPROP_TEXT,sparam);
         ChartRedraw();// принудительно перерисуем все объекты на графике
        }
     }
  }
//+------------------------------------------------------------------+
//| послать широковещательное сообщение всем открытм графикам        |
//+------------------------------------------------------------------+
void BroadcastEvent(long lparam,double dparam,string sparam)
  {
   int eventID=broadcastEventID-CHARTEVENT_CUSTOM;
   long currChart=ChartFirst();
   int i=0;
   while(i<CHARTS_MAX)          // у нас наверняка не больше CHARTS_MAX открытых графиков
     {
      EventChartCustom(currChart,eventID,lparam,dparam,sparam);
      currChart=ChartNext(currChart); // на основании предыдущего получим новый график
      if(currChart==0) break;  // достигли конца списка графиков
      i++;                     // не забудем увеличить счетчик
     }
  }
//+------------------------------------------------------------------+

Try it out.

 
kirill190982:
I don't know, if we convert double to int there will definitely be a loss, but if vice versa, there will most likely be an error during normalization, because the second value of the int type function

If you write int to double, everything is handled normally, the compiler just discards the fractional part (according to the rule).

In the reverse situation, however, the compiler starts doubting, and gives a warning about possible problems (as it seems to it).

And since we all know about the fact that when you HAVE to CREATE in a similar situation, we "advise him" to do it. :)

PS

Perhaps developers will turn off REAL warnings in the future, and then, like in MQL4, the compiler will stop shouting about all sorts of trivialities...

 
Interesting:

Question to the developers regarding "user" events and several experts working on the same terminal.

So I want to ask if I want to make it right or not?


Here is an idea.

In the course of the play we need to inform the "neighbouring" Expert Advisors about some processes that take place.

For example, the following processes should be monitored first:

1. Expert locking;

2. Unloading of the Expert Advisor;

3. Termination of trading operations;

4. Resume trading operations.


Implement

I. Create 4 identifiers of events:

1 - CHARTEVENT_CUSTOM+1//Starting the Expert Advisor

2 - CHARTEVENT_CUSTOM+2//Unloading of the Expert Advisor

3 - CHARTEVENT_CUSTOM+3 //Stop trading operations

4 - CHARTEVENT_CUSTOM+4//Restarting of trading operations


II. Tracking events

When a certain situation happens, the Expert Advisor generates a WIDE message using EventChartCustom.

At the same time,the Expert Advisor writes in sparam a comment (its name and type of the event, or other information) , andlparam its own chart identifier.

The Expert Advisors on other charts (if they can correctly identify the nature of an event) will reply to this specific EA.


PS

If the idea is good, may be it elaborated and arranged as an article. Or add it to help section dedicated to custom events?

And I don't see the point in using several EAs at once, especially if you play several tools - you can easily do with one EA, modification, opening and closing can also be done by one EA, indicator analysis too
 
Rosh:

There is an example to the EventChartCustom function:

Try it out.

Yes, I've seen this example before (I don't even know how long ago). I wanted to ask if my idea is correct and interesting in terms of implementation.

PS

If it does not fit in the help, then maybe someone will agree to refine it and write an article on this application of events.

It would also be interesting to use custom events in the form of orders from one EA to another (or others). if you sum it all up, it would turn out in my opinion a very interesting article.

Unfortunately, I don't have time to deal with it...

 
kirill190982:
And I don't see the point in using several EAs at once, especially if you play several symbols - you can easily do with one EA, modification, opening and closing can also be done by one EA, the analysis of indicators, too

There is always a sense, especially since not all EAs are multicurrency a priori (based on the experience in MQL4).

So, it's not easy for beginners and many of those who used to be engaged in mechanical trading to organise multicurrency ones properly...


God only knows what will happen if someone wants to execute, say, 2-3 copies of MACD Sample on one account.


Besides situations are different, other Expert Advisors may play a secondary role receiving orders from the first one.

Also, this variant will be acceptable when other EAs ("neighbours") do not trade, but only process data or do certain work.

Also similar things can be implemented in the communication between indices and EAs (with a certain approach).

PS

That's why I suggested to work on this question and if any experienced progamer would be willing to write an article. I would be especially glad if the developers themselves devote some of their time to this issue.

I think there's enough material for more than one article...

 
Interesting:
............

Unfortunately I don't have the time to do it...

We understand. Too much time spent commenting on everyone and everything....
 
AM2:

I'm looking at vMA and Close[]. In wotch, it's counting fine. I also tried it like this:

Again I get another error. Maybe there is another way to calculate simple moving average. Or take the handle iMA and CopyBuffer where it should be?

1. In the wotcha, you should specify either the name of Close array (you will see only general information) or a specific value of Close[1], Close[2],..., Close[i].

2. You cannot see how your code fills the mrate array

3. Look at the standard library MovingAverages.mqh - there will be an example of MA calculation

 
joo:
We understand. Too much time is spent commenting on everyone and everything....


There is enough time for commenting too, and for implementing certain ideas.

It's just that I probably won't tackle the issue seriously enough to cover the whole field (and I'm already dealing with some of the applications of the idea, purely for myself).

But in any case I probably won't be writing articles on this subject (for various reasons)...