Errors, bugs, questions - page 101

 
Urain:

Either way.

if(a==0){expression} means if a is 0 then it is true, so execute {expression}.

if(a=0){expression} is equivalent to if(a){a=0;expression} if a is true, {a=0;expression}.

The second one is wrong, it should be written like this

if(a=x) { expression } assign the value of x to the variable a, and if a is not 0 after that, then execute the expression

if(a=0) { } after optimization there will be only a=0

 
mql5:

The second one is wrong. The correct way to write it is

if(a=x) { expression } assign the value of x to the variable a, and if a is not 0 after that, execute the expression

if(a=0) { } after optimization there will be only a=0

Sorry, that's right, expressions are executed left to right.

That's why we start with assignment, and then we check for truth.

 
Renat:

This is roughly the case:

This code not only calculates the maximum volume but also fits it exactly into the limitations of the symbol settings.

It calculates it but forgets why it calculates it when it inserts it:

   double minvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);
   if(lot<minvol) lot=minvol;

The value of the lot by this point is calculated so as to consume all available margin with a minimum margin.

If this value is increased by at least a volume step, there will not be enough money to open a position.

But the second line of the cited code MAKES up the value of lot in case the condition under if is fulfilled, and can increase it by much more than the value of volume step, because in reality there are volume min = 0.1 and volume step = 0.01.

And in this code below, a division by zero may occur, against which there is no protection:

   double stepvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP);
   lot=stepvol*NormalizeDouble(lot/stepvol,0);

If SymbolInfoDouble() returns 0, that's it. MQL5 programs terminate on division by 0, right? It cannot return 0? People here complain that informational functions quite often return 0. You cannot fall back on "it won't return 0" because, firstly, it may, and secondly, division by 0 is fatal.

There are some lesser remarks about "accuracy of entry", but they are really not too significant, i.e. they do not have such serious consequences, you can ignore them.

Anticipating possible arguments that the code is "approximate", I note: how many users of the product are able to find and competently fix such "bad places"?

For them, this is "code from the developers". An example to look up to.

 

Why is the "Next" button not active when all the mandatory fields are filled in?

 
EvgeTrofi:

Why is the "Next" button not active when all the mandatory fields are filled in?

You need to give your permission to receive the newsletter by post.
 
simpleton:

It does calculate, but then it forgets what it was calculating for:

Anticipating possible arguments that the code is "approximate", I want to point out: how many users of the product can correctly fix such "bad places"?

The code was approximate (copied from two pieces), but your comments are correct.

Here is the corrected version:

double CalculateMaxVolume(string symbol)
  {
   double price=0.0;
   double margin=0.0;
//--- select lot size
   if(!SymbolInfoDouble(symbol,SYMBOL_ASK,price))                return(0.0);
   if(!OrderCalcMargin(ORDER_TYPE_BUY,symbol,1.0,price,margin)) return(0.0);
   if(margin<=0.0)                                            return(0.0);

   double lot=NormalizeDouble(AccountInfoDouble(ACCOUNT_FREEMARGIN)/margin,2);
//--- normalize and check limits
   double stepvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP);
   if(stepvol>0.0)
     {
      double newlot=stepvol*NormalizeDouble(lot/stepvol,0);
      if(newlot>lot) lot=NormalizeDouble(newlot-stepvol,2);
      else           lot=newlot;
     }

   double minvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);
   if(lot<minvol) lot=0.0;   // 

   double maxvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);
   if(lot>maxvol) lot=maxvol;
//--- return trading volume
   return(lot);
  }
 
gumgum:

And why session_index++; when session_index=1 is already false:

We can't know in advance what the number of sessions per tool is. So we query each session by number. If it is true

session_exist=SymbolInfoSessionQuote(symbol,day,session_index,start,finish);

we are interested in the time of its beginning and end. If we get false - that's it, there is no session with this number.

 
Rosh:

We cannot know in advance what the number of sessions for an instrument is. Therefore we request each session by number. If it is true

we analyze the time of its beginning and end. If we get false - that's it, there is no session with this number.

A...... Why then on Friday everything ends at 24:00, but in reality at 23:00?
 
gumgum:
A...... then why does everything end on Friday at 24:00 and in reality at 23:00?
Because that's what the server says. We'll check it out, thanks.
 
I understand that you can now change your email on your profile? In the E-mail field you can now make changes, but they are not saved!
Reason: