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

 
Good afternoon everyone. I'm not a very good programmer, so I don't understand some simple things. I have this problem: I have to choose among closed orders in my EA the last one closed by SL.
 
Igor Makanu:

you can't complicate simple tasks! ... said Me, who idly wrapped the new bar definition function into a class ))))

to the point:


the idea is clear, but it's more correct >= in all likelihood

if((timer1++)>=Timer1) { timer1 = 0; Print("Timer №1"); }
if((timer2++)>=Timer2) { timer2 = 0; Print("Timer №2"); }
 
leonerd:

the idea is clear, only more correct >= in all likelihood

did not check, unprint the variables immediately see if by 1 error, then either your version, or do not zero, and assign values =1 to counters timer1 and timer2

as an option, you can try it that way too:


if((++timer1)>=Timer1) { timer1 = 0; Print("Timer №1"); }
if((++timer2)>=Timer2) { timer2 = 0; Print("Timer №2"); }
 
Igor Makanu:

did not check, unpin the variables immediately see if by 1 error, then either your version or do not zero, and assign values =1 to counters timer1 and timer2

However, the method certainly doesn't guarantee a given periodicity. Execution of code in one timer may exceed the time of the other timer.

 
leonerd:

However, the method certainly does not guarantee a given periodicity. Code execution in one timer may exceed the time of another timer.

Where do you get a real-time timer guaranteed on Windows systems? - If the system is overloaded, there will be delays.

in MQL - if you overloaded OnTick() with complex calculations, then until it is executed the OnTimer() event will not happen.

i.e., even MT4 is enough for complex calculations, if not then MT5 - it really works at the level of C++, but the lack of performance is usually related to a bad calculation algorithm - use the profiler, don't do calculations every tick where there is nothing to calculate until a new bar appears, don't calculate the whole history, if you use signals on the last 1 to 3 bars - calculate only 100 bars ... there are many variants

HH: working with graphical objects slows down everything, working with strings also reduces performance - in theory, but lately I haven't noticed that, like working with time conversion functions - it's unambiguously seen in the profiler, where a lot of time is spent - we try to use this code fragment less often

Профилирование кода - Разработка программ - MetaTrader 5
Профилирование кода - Разработка программ - MetaTrader 5
  • www.metatrader5.com
Профилирование — это сбор характеристик программы во время ее выполнения. При профилировании замеряется время выполнения и количество вызовов отдельных функций и строк в коде программы. При помощи этого инструмента программист может найти наиболее медленные участки кода и провести их оптимизацию. Профилирование можно проводить на обычном...
 
Igor Makanu:

and where can you be guaranteed to get a real-time timer on Windows systems? - if the system is overloaded, there will be delays

the same in MQL - if you have loaded complex calculations with OnTick() , then until it is executed the OnTimer() event will not happen.

i.e., even MT4 is enough for complex calculations, if not then MT5 - it really works at the level of C++, but the lack of performance is usually related to a bad calculation algorithm - use the profiler, don't do calculations every tick where there is nothing to calculate until a new bar appears, don't calculate the whole history, if you use signals on the last 1 to 3 bars - calculate only 100 bars ... there are many variants

HH: working with graphical objects slows down everything, working with strings also reduces performance - in theory, but lately I haven't noticed that, like working with time conversion functions is also a pain - clearly everything in the profiler is visible, where much time is spent - we try to use this part of the code less often

Agreed, standard timer also does not guarantee anything. Well thanks, we'll give it a try.

 

Good afternoon, dear friends!

Can you please tell me if it is possible in MKL4 to setthe opening of a position for one symbol at the time of opening a position for another symbol? Maybe such a question already discussed, then give me a link.

Thank you.

 
novichok2018:

Good afternoon, dear friends!

Can you please tell me if it is possible in MKL4 to setthe opening of a position for one symbol at the time of opening a position for another symbol? Maybe such a question already discussed, then give me a link.

Thank you.

The question is not fully formulated.
But in general - you can. But not simultaneously, but sequentially in either of the two cases.
 
Artyom Trishkin:
The question is not formulated completely.
But in general, you can. But not at the same time, but consecutively in either case.

That's great. How do I describe it in the code? For example, if conditions are correct and I open a Buy position in GBP at 9:00, I open a Buy position in EUR as well (at 9:00).

 
novichok2018:

Great. How do I describe it in the code? For example, if conditions have developed at 9:00 and a BUY on the pound is opened, then a BUY on the euro is also opened (at 9:00).

Opened how? What is the reason for opening?
Reason: