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

 
Mikhail:

When I make a query like this:

I get this result:

2020.06.17 13:49:53.270 2020.01.02 06:50:00 Symbol EURUSD_i Digits 5 Point 1e-05

When I make a request like this:

I get this result:

2020.06.17 13:51:58.787 2020.01.02 06:45:00 Symbol EURUSD_i Digits 0 Point 0.0

At the same time I want to note that if I don't insert Print function, I don't get any error at all, the order doesn't even try to modify itself. It is as if CTrade does not see my order.

Checking for symbol and magic number doesn't work:

Result:

2020.06.17 14:37:38.147 2020.01.02 06:50:00 Symbol Magic 0 Ticket 2

Magic number should be 12345, the symbol is euro dollar.

Why can't I get symbol and medgic?

If you change the string:

is changed to

and remove validation by magic number, then we have problems with prices

2020.06.17 01:38:24.136 2020.01.02 07:40:00 failed modify order #2 buy stop 0.1 EURUSD_i at 1.12086 sl: 1.12023 tp: 1.12275 -> 1.00000, sl: 1.00000 tp: 1.00000 [Invalid price]

2020.06.17 01:38:24.136 2020.01.02 07:40:00 CTrade::OrderSend: modify #2 at 1.00000 (sl: 1.00000 tp: 1.00000) [invalid price]

2020.06.17 01:38:24.136 2020.01.02 07:40:00 BUY STOP modification failed! Result Retcode: 10015, description of Retcode: invalid price

I've already racked my brains, while this same code works fine in another Expert Advisor.

What am I doing wrong?

Incorrectly initialized (or not) object of class CSymbolInfo.

If you don't have this string asymbol.Name(Symbol()) then add it.

If you have one, debug in the Name(string symbol) function what happens.

Filling m_digits etc fields in Refresh() function.

s.s. Judging by what you've added, you've definitely got asymbol uninitialized.

 
Mikhail:

Until the new tick arrives, there is no movement of the buttons. That's what I can see with my eyes. As soon as the price changes, the buttons move.

Although today, even on the new tick, the buttons have stopped redrawing, although I haven't changed anything. Only the background is moving.

To clarify - as you say you change the coordinates in OnTick, and claim that in fact the buttons move on the NEXT tick. The next tick from what? The one you changed the coordinates on, or the one from christmas?

 
Aleksey Mavrin:

Your CSymbolInfo class object is initialized incorrectly (or not at all).

If you don't have such string asymbol.Name(Symbol()) then add it.

If you have one, debug in the Name(string symbol) function what happens.

Filling m_digits etc fields with Refresh().

s.s. Judging by what you've added, your asymbol is definitely uninitialized.

At the very top of my code I have the following lines
#include <Trade\Trade.mqh>
#include <Trade\OrderInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\DealInfo.mqh>
#include <Trade\SymbolInfo.mqh>

CTrade atrade;
COrderInfo aorder;
CPositionInfo apos;
CDealInfo adeal;
CSymbolInfo asymbol;

Is it an initialization? When compiling I get the following information

'Trade.mq5 panel' Trade.mq5 panel 1 1

'Trade.mqh' Trade.mqh 1 1

'Object.mqh' Object.mqh 1 1

'StdLibErr.mqh' StdLibErr.mqh 1 1

'OrderInfo.mqh' OrderInfo.mqh 1 1

'HistoryOrderInfo.mqh' HistoryOrderInfo.mqh 1 1

'PositionInfo.mqh' PositionInfo.mqh 1 1

'DealInfo.mqh' DealInfo.mqh 1 1

'SymbolInfo.mqh' SymbolInfo.mqh 1 1

code generated 1 1

0 errors, 0 warnings, 3192 msec elapsed 1 1

After I open a Buy Stop order I recalculate all orders, select an open order and check if the symbol and mqh number match:

for(int i=OrdersTotal()-1;i>=0;i--)
          if(aorder.SelectByIndex(i))  
              if(aorder.Symbol()==asymbol.Name() && aorder.Magic()==MagicNumber && Ask < aorder.PriceOpen())

Nothing happens at this stage, as I wrote above asymbol.Name() does not return the open order symbol for some reason, aorder.Magic() returns value 0 (although my magic number is 121345), asymbol.TickSize() returns value 0. In other words, the check fails and therefore further work on the order stops. Please clarify"debug in function Name(string symbol) what's going on", I don't quite understand this phrase. What should I add and where?

 
Aleksey Mavrin:

To clarify - as you say you change the coordinates in OnTick, and claim that in fact the buttons move on the NEXT tick. The next tick from what? The one you changed the coordinates on, or the one from christmas?

I think the sequence is as follows: a new tick comes in, I change the panel coordinates, the panel background starts moving to my desired location, the buttons stand still at that time, a new tick comes in and the buttons follow the panel to the desired location. Is it possible to generate ticks right from the Nativity?
 
Mikhail:

At this stage, nothing happens, because as I have already written above, function asymbol.Name() for some reason does not return the open order symbol, function aorder.Magic() returns value 0 (although my Magic is 121345), function asymbol.TickSize() returns value 0. In other words, the check fails and therefore further work on the order stops. Please clarify"debug in function Name(string symbol) what's going on", I don't quite understand this phrase. What should I add and where?

The error in the order index / ticket might be an error judging by magic 0. At the moment of access to the order structure, data of the wrong order are written there. In the selection loop, it may be that the next number is placed in the last order set but not the one you need. The data of the last order select are returned from the order structure.

 
Mikhail:
at the very top of my code are lines

Is this an initialisation? When compiling, I get the following information

'Trade panel.mq5' Trade panel.mq5 1 1

'Trade.mqh' Trade.mqh 1 1

'Object.mqh' Object.mqh 1 1

'StdLibErr.mqh' StdLibErr.mqh 1 1

'OrderInfo.mqh' OrderInfo.mqh 1 1

'HistoryOrderInfo.mqh' HistoryOrderInfo.mqh 1 1

'PositionInfo.mqh' PositionInfo.mqh 1 1

'DealInfo.mqh' DealInfo.mqh 1 1

'SymbolInfo.mqh' SymbolInfo.mqh 1 1

code generated 1 1

0 errors, 0 warnings, 3192 msec elapsed 1 1

After I open a Buy Stop order I recalculate all the orders, select an open order and check if the symbol and the Majdic number match:

Nothing happens at this stage, as I wrote above asymbol.Name() does not return the open order symbol for some reason, aorder.Magic() returns value 0 (although my magic number is 121345), asymbol.TickSize() returns value 0. In other words, the check fails and therefore further work on the order stops. Please clarify"debug in function Name(string symbol) what's going on", I don't quite understand this phrase. What should I add and where?

Geez, why do you use something you don't understand (what if it's a yadda yadda suitcase )) )

And you don't even bother to read what's written

If you don't have asymbol.Name(Symbol()) then add it.

s.w. I wanted to explain more about initialisation, but I guess that would be useless too
 
Valeriy Yastremskiy:

There may be an error in the order index / ticket according to magic 0. At the moment of access to the order structure the data of the wrong order is stored there. In the selection cycle it may be that the next number goes to the last order set and not the one you need. The data of the last order select are returned from the order structure.

I still haven't been able to figure out why this glitch is happening. Finally, I took the code that is responsible for creating the panel with buttons and rewrote it in the EA where this same code is working properly and everything worked. Anyway, thank you!
 

Good afternoon!

Help me solve a simple problem.

Gap counter. I want to count gaps that are more than 10 points.

int start()
{
int gap=0;
int r=MathAbs(Close[2]-Open[1])/Point;
if (r>=10)
{
gap=gap+1;
}
Comment("ГЭП!========: ",gap,"\n",
        "ВЕЛИЧИНА ГЭПА==: ",r,"\n");
return(0);

The variable "gap" resets to zero. I don't understand why. I've already tried everything. I've tried loops and static - it doesn't work. I suspect I wrote the loops incorrectly.

 
Alexey Belyakov:

Good afternoon!

Help me solve a simple problem.

Gap counter. I want to count gaps that are more than 10 points.

The variable "gap" resets to zero. I don't understand why. I've already tried everything. I've tried loops and static - it doesn't work. I suspect I wrote the loops incorrectly.

Variable gap is in scope of function start - and with each new tick it is re-initialized with zero

 
Alexey Belyakov:

Good afternoon!

Help me solve a simple problem.

Gap counter. I want to count gaps that are more than 10 points.

The variable "gap" resets to zero. I don't understand why. I've already tried everything. I've tried loops and static - it doesn't work. I suspect I wrote the loops incorrectly.

int gap=0;
int start()
{
int r=MathAbs(Close[2]-Open[1])/Point;
if (r>=10)
{
gap++;
}
Comment("ГЭП!========: ",gap,"\n",
        "ВЕЛИЧИНА ГЭПА==: ",r,"\n");
return(0);
int start()
{
static int gap=0;
int r=MathAbs(Close[2]-Open[1])/Point;
if (r>=10)
{
gap=gap+1;
}
Comment("ГЭП!========: ",gap,"\n",
        "ВЕЛИЧИНА ГЭПА==: ",r,"\n");
return(0);