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

 
vladmirad:

Thanks for the advice, I am aware of these functions.

Do you know why so many people, including you, reply to those who know mql like an axe. And they ignore the advice of the knowledgeable? If you have none, check this tip:

The forum on trading, automated trading systems and strategy testing.

Any questions from beginners on MQL4 and MQL5, help and discussion on algorithms and codes

Artyom Trishkin, 2020.06.29 00:03

Hello.
Start by monitoring the state of the graph in OnChartEvent() https://www.mql5.com/ru/docs/event_handlers/onchartevent
There are a few events that you need:
CHARTEVENT_OBJECT_CREATE Create graphical object
CHARTEVENT_OBJECT_CHANGE Change the properties of graphical object through the properties dialog
CHARTEVENT_OBJECT_DELETE Delete graphical object
https://www.mql5.com/ru/docs/constants/chartconstants/enum_chartevents
Log all parameters of OnChartEvent() handler and see their values when adding/modifying/deleting graphical objects. This will give you direction where to go.

 
vladmirad:

Thanks for the tip, I know about these functions.
But how can we use them to automatically find an object on the chart and read its parameters, if we do not know its name a priori?
When drawing an object on a chart with a mouse, the system gives its name.

Of course, it is not difficult to organize the manual input of all of the necessary data of the object from its table of properties, but then why the automation?
But how to programmatically give an EA the name of an object and then all of the functions you have mentioned can be used, is still not clear to me...

As noted above, work with chart events:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool applyObject(const string _objName) {
  if(MessageBox("Сохранить параметры объекта \"" + _objName + "\" для эксперта?", "ObjChange", MB_YESNO) == IDYES) {
    objName = _objName; // Запись имени изменяемого объекта
    // Запись других параметров изменяемого объекта ...
    return true;
  }
  return false;
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam
) {
//---
  if(id == CHARTEVENT_OBJECT_CREATE || id == CHARTEVENT_OBJECT_DRAG || id == CHARTEVENT_OBJECT_CHANGE) {
    applyObject(sparam);
  }
}
Files:
ObjChange.mq5  5 kb
 
Artyom Trishkin:
Hello.
Start by tracking the state of the chart in OnChartEvent() https://www.mql5.com/ru/docs/event_handlers/onchartevent
There are a few events you need:
CHARTEVENT_OBJECT_CREATE Create a graphical object
CHARTEVENT_OBJECT_CHANGE Change the properties of a graphical object via the properties dialog
CHARTEVENT_OBJECT_DELETE Delete a graphical object
https://www.mql5.com/ru/docs/constants/chartconstants/enum_chartevents
Log all parameters from OnChartEvent() and see their values when you add/modify/delete graphical objects. This will give you direction where to go.

Thank you very much, have already taken your advice!

 
Mihail Matkovskij:

You can find and log objects of a given type with their coordinates as follows:

You can save any data to a file. And in the Expert Advisor make a loader that will add the appropriate objects, and then load data from the file into them. But you at least sketch a source code for your specific task and publish it here.

Thank you too, Michael, for your practical help!
 
Mihail Matkovskij:

As noted above, work with chart events:

Michael, your and@Artyom Trishkin's help was very helpful!

Now we need to figure out how to find the crossing point between the price chart and the found object, in this case, the trend line.

The algorithm is as follows:
1. Using the read coordinates of the trend line we calculate the coefficient of trend increase per 1 bar of the selected TF.
2. Calculates the price coordinate of the trend line on the current bar and monitors the fact of crossing by the chart of this point during the selected TF.
3. If it has, we proceed to processing of this event, for example, open an order. If not, the procedure is repeated for the next bar.

But maybe MT4(5), due to the specifics of this system, has a much simpler solution?

 
Alexey Viktorov:

Do you know why so many people, including you, respond to those who know mql like an axe. And they ignore the advice of those who know. In your case, it is this advice:


My dear Alexey, you're absolutely right about my knowledge of MQL. However, you are mistaken in saying that I don't pay attention to advice of insiders, because my first contact was with@Artyom Trishkin, who I believe is one of outstanding MQL professionals and who you know well.

His advice enabled me to immediately understand how to solve my problem and opened my eyes for further action. And@Mihail Matkovskij made my life even easier!

 
vladmirad:

Michael, your and@Artyom Trishkin's help was very helpful!

Now we need to figure out how to find the crossing point between the price chart and the found object, in this case, the trend line.

The algorithm is as follows:
1. Using the read coordinates of the trend line we calculate the coefficient of trend increase per 1 bar of the selected TF.
2. Calculates the price coordinate of the trend line on the current bar and monitors the fact of crossing by the chart of this point during the selected TF.
3. If it has, we proceed to processing of this event, for example, open an order. If not, the procedure is repeated for the next bar.

But maybe MT4(5), due to the specifics of this system, has a much simpler solution?

As I said above, sketch a source code to have something to start with. Moreover, you already have some knowledge about how to get the data of the object on the chart. No one wants to do everything for you from scratch. And in this way, what is missing for the expert's work can be supplemented...

 
vladmirad:

Michael, your and@Artyom Trishkin's help was very helpful!

Now we need to figure out how to find the crossing point between the price chart and the found object, in this case, the trend line.

The algorithm is as follows:
1. Using the read coordinates of the trend line we calculate the coefficient of trend increase per 1 bar of the selected TF.
2. Calculates the price coordinate of the trend line on the current bar and monitors the fact of crossing by the chart of this point during the selected TF.
3. If it has, we proceed to processing of this event, for example, open an order. If not, the procedure is repeated for the next bar.

Perhaps the solution in MT4(5), due to the specific features of this system, is much simpler?

It is not quite clear what you want to find. You want to find the point of crossing the trend line by the price on some bar? For that there are functions for getting the value of the line on a bar. But I would use the straight line equation:

Forum on trading, automated trading systems and trading strategy testing

FAQ from Beginners MQL5 MT5 MetaTrader 5

Artyom Trishkin, 2020.05.02 12:27

Use a straight line equation:

//+------------------------------------------------------------------+
//| Уравнение прямой                                                 |
//+------------------------------------------------------------------+
double EquationDirect(const int left_bar,const double left_price,const int right_bar,const double right_price,const int bar_to_search) 
  {
   return(right_bar==left_bar ? left_price : (right_price-left_price)/(right_bar-left_bar)*(bar_to_search-left_bar)+left_price);
  }
//+------------------------------------------------------------------+

Specify the bar number and price of the point on the left, specify the bar number and price of the point on the right (a virtual line is drawn on these points) and specify the bar you are looking for.
The function will return the price of the bar you are looking for.


Does not require the presence of a real object.
 
Artyom Trishkin:

..... There are functions for getting the line value on the bar. But I would use the straight line equation:

.....

Artyom, more details here, please.

Either I wasn't very attentive before, or the documentation was tweaked... I don't know.

But I always thought that ObjectGetDouble returned the line price on a particular bar (I mean the price exactly). And here I decided to make a little script to check it, and what did I see?

1. There is no bar number in the parameters, on which the value should be read.

2. property identifier:

OBJPROP_PRICE

Price coordinate

modifier=number of anchor point


it is only the anchor point!

Yes, basically, if I draw this line in the code, I already have these points! Why do I need to know them? In fact, what's the point of it?

How can I get the price value of this line somewhere else?


It turns out that this is

prop_modifier

[in] Modifier of specified property. For the first option, the default value of the modifier is 0. Most of the properties do not require a modifier. Denotes a level number inFibonacci tools and in Andrews' Pitchfork graphical object. Numbering of levels starts from zero.

Doesn't it make any sense at all? Is it looking for attachment points of ANY fan line? That's nonsense. Pardon.

Документация по MQL5: Константы, перечисления и структуры / Константы объектов / Свойства объектов
Документация по MQL5: Константы, перечисления и структуры / Константы объектов / Свойства объектов
  • www.mql5.com
Все объекты, используемые в техническом анализе, имеют привязку на графиках по координатам цены и времени – трендовая линия, каналы, инструменты Фибоначчи и т.д.  Но есть ряд вспомогательных объектов, предназначенных для улучшения интерфейса, которые имеют привязку к видимой всегда части графика (основное окно графика или подокна индикаторов...
 
Сергей Таболин:

Artyom, could you go into a little more detail here, please?

Either I wasn't very attentive before, or the documentation has been tweaked... I don't know.

But I always thought that ObjectGetDouble returned the line price at a particular bar (I mean the price). And here I decided to make a little script to check it, and what did I see?

1. There is no bar number in the parameters, on which the value should be read.

2. property identifier:

OBJPROP_PRICE

Price coordinate

modifier=number of anchor point


it is only the anchor point!

Yes, basically, if I draw this line in the code, I already have these points! Why do I need to know them? In fact, what's the point of it?

How can I get the price value of this line somewhere else?


It turns out that this is

prop_modifier

[in] Modifier of specified property. For the first option, the default value of the modifier is 0. Most of the properties do not require a modifier. Denotes a level number inFibonacci tools and in Andrews' Pitchfork graphical object. Numbering of levels starts from zero.

Doesn't it make any sense at all? Is it looking for attachment points of ANY fan line? That's nonsense. Pardon me.

I haven't worked with such objects much. What will this function return for the trend according to the specified bar time? I do not have time to check it. Even if it is done in a small script...

ObjectGetValueByTime()

Документация по MQL5: Графические объекты / ObjectGetValueByTime
Документация по MQL5: Графические объекты / ObjectGetValueByTime
  • www.mql5.com
Функция использует синхронный вызов – это означает, что функция дожидается выполнения всех команд, которые были помещены в очередь графика перед её вызовом, и поэтому данная функция может быть затратной по времени. Нужно иметь это обстоятельство в виду...
Reason: