Errors, bugs, questions - page 147

 
Vladix:

Is there a possibility in mql5 to track the status of an open position, for example, that it is being closed now?

...

But then the next tick comes, all the above steps are repeated, position selection is done, volume is taken and ONE more position is placed in the direction of closing.

What can be done to avoid this?

Nothing needs to be done. Until the current tick is processed by OnTick() function, all incoming ticks are skipped.

What happens to the position in real time, can be tracked using the OnTrade () function.

Обработка торговых событий в эксперте при помощи функции OnTrade()
Обработка торговых событий в эксперте при помощи функции OnTrade()
  • 2010.06.01
  • KlimMalgin
  • www.mql5.com
В 5-ой версии языка MQL появилась масса нововведений, в том числе работа с событиями различных типов (события таймера, торговые события, пользовательские и т.д.). Возможность обработки событий позволяет создавать совершенно новый тип программ для автоматического и полуавтоматического трейдинга. В этой статье мы рассмотрим торговые события и напишем для функции OnTrade() код, который будет обрабатывать событие Trade.
 
Valmars:

There is no need to do anything. As long as the current tick is not processed by OnTick() function, all newly arrived ticks are skipped.

What happens to the position in real time can be tracked using the OnTrade () function.

If it were not for the asynchronous execution of the request, everything would be OK. But when a tick comes, the position is closed, while it is still in the list when the next tick comes, so how can we understand whether the position is opened, opened or closed? How to process trade events? Imho, a basic operation should not be so complicated.

Ideally, when trying to close a position, it gets the status "Closed" or "Processing" or something else, by which it can be determined that it is currently in the process of some action, then it can be left alone with a clear conscience.

And now, you have to look through a lot of history and understand how everything happened, and there is no guarantee that everything will be correct.

 
Vladix:

If it weren't for the asynchronous nature of the request, all would be well. But when a tick comes, the position is closed, and when the next tick comes, they are still in the list, so how can we understand whether they are opened or closed? How to process trade events? Imho, a basic operation should not be so complicated.

Ideally, when an attempt is made to close a position, it will get a "Closed" or "Processing" status or whatever, which would indicate that it is currently in the process of some kind of action, and then it can be left alone with a clear conscience.

And now, you have to look through a lot of history and understand how everything happened, and there is no guarantee that everything will be correct.

Do not open-close positions on every tick, make a delay after each trade operation.
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Типы торговых операций
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Типы торговых операций
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Типы торговых операций - Документация по MQL5
 
EQU:

Why... Who's to say NewBar isn't an event? )))))))))

OnNews - the news comes in, the bot has to read it... Officially. Not by poking through WinAPI in a left-handed way.

1.NewBar - An event that you can implement yourself. This is likely to be what they advise. I once asked about Connect and the answer was simple: you have to implement it yourself.

It is not a problem - I implemented it and now I try to track almost everything I need with help of timer (I already have about 30 events). When I'm done, the user can not change any of the parameters I am interested in, so that the expert did not know about it.

2. OnNews - The idea in general is understandable, you could join. Although, the developers are likely to point to the presence of News.wav.

Although, I've long sought from the developers to expand the functionality of the language through the possibility of working with the calendar of economic news and other FA. Do you think they will do everything right? I don't think so.

I've already sent in my application on this occasion, hope is still alive. It would be nice if an expert would do some work on his own...

Документация по MQL5: Основы языка / Функции
Документация по MQL5: Основы языка / Функции
  • www.mql5.com
Основы языка / Функции - Документация по MQL5
 
Vladix:

If not for the asynchronous request, everything would be fine. But when a tick comes, the position is closed and on the next tick they are still in the list, and how can we understand whether they are opened, opened or closed? How to process trade events? Imho, a basic operation should not be so complicated.

Ideally, when you try to close a position, it gets the status "Closed" or "Processing" or whatever, by which you can determine that it is currently in the process of some kind of action, then it can be left alone with a clear conscience.

And now, you have to look through a lot of history and understand how everything happened, and there is no guarantee that everything will be correct.

Even now it can be done with ease, if you know how to do it. Developers have promised to rewrite OnTrade(), add the necessary parameters there. if done, it will be even easier to handle.

No one prevents to handle such situations on site, in OnTick() or OnTime() - at place of trade operation; or in OnTrade(), if you want to catch user actions or trade operations not controlled directly from code.

Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Типы торговых операций
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Типы торговых операций
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Типы торговых операций - Документация по MQL5
 
Interesting:

1.NewBar - An event that you can implement yourself. This is likely to be what they advise. I once asked about Connect and the answer was simple - you should implement it yourself.

...

I'm a little fuzzy on how I see OnNewBar...))

OnNewBar(ulong Param), where Param - bitwise filled in 1 in positions of timeframes with new bar... - Not all charts are updated simultaneously by the number of bars...

For example ...

...00001 - only updated a minute

...00111 - only one minute, 2 and 3 are updated... and so on...

It's just an idea, but I think it would be useful. Although...?;)

 
EQU:

I'm a little fuzzy on how I see OnNewBar...)

OnNewBar(ulong Param), where Param - fill in 1 in timeframe positions with a new bar... - Not all charts update simultaneously by the number of bars...

For example ...

...00001 - only the minute was updated.

...00111 - only one minute, 2 and 3 are updated... etc...

It's just an idea, but I think it would be useful. Although...?;)

At the expense of the parameter it is necessary to think. Is it worth doing it (may be, it's easier to put TF there as ENUM_TIMEFRAMES)?

At least, I wanted to do something like that, but then I gave up...

PS

I forgot to tell, I wanted to make up OnNewBar in Chart class, which I'm working on now (at the moment I'm still packing there standard stuff + my own pleasant trifles).

Just do not ask me why I do not like the standard CChart... :)

 

If you need to track a new bar, have a look at my code. it might come in handy. i have tried different variants - this method is the most reliable

https://www.mql5.com/ru/code/107

isNewBar
isNewBar
  • votes: 7
  • 2010.05.07
  • Prival
  • www.mql5.com
Функция анализа появления нового бара на заданном таймфрейме.
 
Prival:

If you need to track a new bar, have a look at my code. it might come in handy. i have tried different variants - this method is the most reliable

https://www.mql5.com/ru/code/107

What's wrong with the last bar open time compared to the symbol-period SERIES_LASTBAR_DATE? Much easier than your version and you don't need an indicator.


In addition, for a multi-currency EA a new bar should be defined for each symbol, it means that the indicator should be initialized for all symbols.

 
Prival:

If you need to track a new bar, have a look at my code. it might come in handy. i have tried different variants - this method is the most reliable

https://www.mql5.com/ru/code/107

Again - code... code... Code is good... but so are tactics, loops... ;)

Doesn't the chart get a message about creating a new bar? I don't believe it...)))

Is it a problem to make an event out of it? Is a variable predefined at least?

And in general - it is easier to process events than to fill a mountain of code. And besides - with errors (ERROR-FREE PROGRAMS DO NOT EVER!!! )))))

Reason: