Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1536

 
maxvoronin74 #:

So position opening-closing is displayed in any case. It should. It always has been. Until now.

Errors are not displayed/processed - that's why I wrote about the need to set the error returned by the server, and then think further. If it does not return errors, then it is a question of the EA logic - it may not work.

maxvoronin74 #:

So opening-closing a position is displayed in any case. It should be displayed. And it has always been so. Until now.

It's sad. So much time and effort has already been put into this.... It's a shame. Perhaps there are ways to participate in trading without the broker layer. But I couldn't find anything on this topic.

I wish I had given up 10 years ago.

Try looking at the Moscow Exchange.

 
maxvoronin74 #:

The code can be seen as text in google drive: https://drive.google.com/file/d/1bSmNjmO71GYO6fYVFioJWOsFctmmeJTy/view?usp=drive_link

Some evil coder has done a very bad job on the code of your Expert Advisor.

I am afraid that this EA will never be able to trade.

But seriously, the EA has no conditions for opening positions.

Agree that such a condition will never be fulfilled ask > ask and bid > bid as well.

And in your code, the EA is waiting for this very condition to be fulfilled.

Sorry, there is one condition that can open a sell position - ask0 > bid0, but the problem is that you can sell only at bid price, but your EA tries to sell at ask price, and naturally it gets requotes.


As you can see in the logs, everything is there.

 
Aleksandr Slavskii #:

Some evil coder really messed with your advisor's code.

I'm afraid that this EA will never be able to trade.

But seriously, the EA has no conditions for opening positions.

Agree that such a condition will never be fulfilled ask > ask and bid > bid too

And in your code, the EA is waiting for this very condition to be fulfilled.

Sorry, there is one condition that can open a sell position - ask0 > bid0, but the problem is that you can sell only at bid price, but your EA tries to sell at ask price, and naturally it gets requ otes.


As you can see in the logs, everything is there.

There are more evil coders than me...

How did you make the logs appear and what does this requote mean?

The thing is that there were no problems with opening orders. I attach a scan of the history for 03.05.2024. There are three positions opened by the robot, one of which is a buy.... I had to close them manually and remove the Expert Advisor from the page so that it would not open them again. For some reason, it was the closing condition that did not work.

I could post the whole code here, but there are two hundred lines of code. I'm not sure it would be right that way. That's why I left the link.

PS. I'm trying to add an mq5 file. You can see the code there too. My MetaEditor opens it.

Tried how the Expert Advisor, which is attached below, works. I opened a buy. Again did not close by the condition. And again there is no log file or entries in the Expert Advisor tab.



 
Aleksey Vyazmikin #:

Errors are not displayed/processed - that's why I wrote about the need to set the error returned by the server, and then think further. If it does not return errors, then it is a question of the EA logic - it may not work.

You are right. I made prints and the log file appeared. But for some reason, it does not indicate the opening and closing of positions. Maybe I was worried for nothing? I'm sorry I wasted your time.

 
Aleksey Vyazmikin #:

Perhaps this case.

Prints confirmed that the closing condition is there, but the closing is not happening.
Files:
 
maxvoronin74 #:

I'm the angriest coder you'll ever find...

All right, everybody's got to start somewhere.

There are a lot of mistakes in the EA.

double Price            = PositionGetDouble(POSITION_PRICE_OPEN);

You should call PositionGetDouble after PositionSelect, otherwise your Price will most likely contain rubbish or zero, then you will compare this zero with ascii bits, and somewhere the condition will be triggered.

 for(int i = 0; i < ArraySize(mqlTick); i++)
  {
     double bid1 = NormalizeDouble(mqlTick[0].bid, _Digits); // первая цена bid за последний период
     double ask1 = NormalizeDouble(mqlTick[0].ask, _Digits); // первая цена ask за последний период

What does this code do?

It does the same thing a hell of a lot of times.

I think that the index of the mqlTick array should be i, not zero.

And I wrote about incorrect asci bits in position openings in the previous post.

You'd better not specify the price to open a position at all, let the CTrade class do it

m_trade.Buy(LotSize)

This way you will have less chances to make a mistake.


When the condition bid0 > ask0 occurs, you want to open a position.

In my opinion, when this condition occurs, you should close all open positions, close the terminal and switch off the computer)))))

 
Aleksandr Slavskii #:

You should call PositionGetDouble after PositionSelect otherwise your Price will most likely contain rubbish or zero, then you will compare this zero with ascii bits, somewhere somewhere the condition will be triggered.

What does this code do?

It does the same thing a fuckload of times.

I think that the index of the mqlTick array should be i, not zero.

I wrote about incorrect asci bits in position openings in the previous message.

You'd better not specify the price for opening a position at all, let the CTrade class do it

This way you will have less chances to make a mistake.


When the condition bid0 > ask0 occurs, you want to open a position.

In my opinion, when this condition occurs, you should close all open positions, close the terminal and switch off the computer)))))

PositionSelect - I will have to spend a bit of time to understand why positions are not opened when I use it. So temporarily I use !PositionSelect(Symbol()) so that only one position on an instrument works at any time. That's why I think it's

double Price            = PositionGetDouble(POSITION_PRICE_OPEN);

works correctly. Checked. Or is that not always the case?

 for(int i = 0; i < ArraySize(mqlTick); i++)
  {
     double bid1 = NormalizeDouble(mqlTick[0].bid, _Digits); // первая цена bid за последний период
     double ask1 = NormalizeDouble(mqlTick[0].ask, _Digits); // первая цена ask за последний период

This code is timed, every 300 milliseconds, to find the first price for the period. That's why the index is 0. How else am I supposed to find the first price of the period?

The open buy price should be ask, as I understand it. And sell is bid. I guess I didn't write the position opening correctly. It's the other way round. Does it make no sense to write the instrument name when opening because of the class? Only the lottery and that's all?

Regarding the opening condition, I read that the spread can be negative. So I tried to provide for it, but I wrote the logic incorrectly. In fact, the spread can't be negative?

Anyway, thank you very much. I wouldn't have paid attention if you hadn't shown me.

Files:
 
Hello guys, can I ask you about what language I should learn in programming for MetaTrader 5? 
 
152488748 #:
Hello guys, can you please tell me what language I should learn in programming for MetaTrader 5?

Look at the top of this site, click on the link and start learning:

Программирование на MQL5 для трейдеров - Учебник на MQL5.com
Программирование на MQL5 для трейдеров - Учебник на MQL5.com
  • www.mql5.com
Современный трейдинг немыслим без компьютера. Автоматизация рабочего процесса трейдера уже давно вышла за пределы бирж и офисов брокеров, став...
 
What formula is used to calculate SYMBOL_PRICE_VOLATILITY?
Reason: