Discussion of article "Limitations and Verifications in Expert Advisors" - page 2

 

Thank you.

 
double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_LIMIT);

'SYMBOL_VOLUME_LIMIT' - undeclared identifier.............

'SymbolInfoDouble' - none of the overloads can be applied to the function call.............

Is it just me?

Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте
Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте
  • www.mql5.com
Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте - Документация по MQL5
 
gumgum:

'SYMBOL_VOLUME_LIMIT' - undeclared identifier.............

'SymbolInfoDouble' - none of the overloads can be applied to the function call.............

Is it just me?

As soon as a new build is released, everything will become normal. We are waiting for the build.
 
Rosh:

Can you do that?

lot_max=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
 

One more question about the SeriesInfoInteger() function.

When creating the topic"AccountInfo... Information relevance", I learnt that there are functions that use data "cached in the software environment" and there are functions that always have "direct access to actual data".

Which category of functions does the SeriesInfoInteger() function belong to ?

 

The following code is used in the CheckVolumeValue function:

int ratio=(int)MathRound(volume/volume_step);

if(MathAbs(ratio*volume_step-volume)>0.0000001)

{

description=StringFormat("Объем не является кратным минимальной градации SYMBOL_VOLUME_STEP=%.2f, ближайший корректный объем %.2f",

volume_step,ratio*volume_step);

return(false);

}

But it is more correct:

int ratio = (int)MathRound((volume-min_volume)/volume_step);

if (MathAbs(ratio*volume_step+min_volume-volume)>0.0000001)

{

description=StringFormat("Объем не является кратным минимальной градации SYMBOL_VOLUME_STEP=%.2f, ближайший корректный объем %.2f",

  volume_step,ratio*volume_step+min_volume);

return(false);

}

Because the minimum step of volume change must be counted from the minimum value.

 

And perhaps the code snippet

//--- вычислим значение маржи

bool check=OrderCalcMargin(type,Symbol(),lots,last_tick.ask,margin);

should be replaced with:

//--- вычислим значение маржи

double price = (type == ORDER_TYPE_BUY || type == ORDER_TYPE_BUY_LIMIT || type == ORDER_TYPE_BUY_STOP || type == ORDER_TYPE_BUY_STOP_LIMIT) ? last_tick.ask : last_tick.bid;

bool check=OrderCalcMargin(type,Symbol(),lots,price,margin);

 
Attached source code files and source code insets in HTML code are now completely translated into Portuguese for your convenience.
MQL5.community - User Memo
MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 
Rashid Umarov:

Due to changes in MQL5, now the maximal overall volume allowed for one symbol can be obtained as following:

Do not use the old variant! It was like this:

The article has been corrected and the new Check_Order_And_Volume_Limits.mq5 expert code has been attached to it.

Dear Admin

I try to use this function but it will return 0 in all cases.

My MT5 build is 2280

 
double orders_volume_on_symbol=PendingsVolume(symbol);


gives error, no such function

And after I modify function to not include pending orders, it  gives 0


double NewOrderAllowedVolume(string symbol)
  {
   double allowed_volume=0;
//--- get the limitation on the maximum volume of an order
   double symbol_max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
//--- get the limitation of volume by a symbol
   double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_LIMIT);

//--- get the volume of open position by a symbol
   double opened_volume=PositionVolume(symbol);
   if(opened_volume>=0)
     {
      //--- if we already used available volume
      if(max_volume-opened_volume<=0)
         return(0);

      //--- volume of the open position doen't exceed max_volume
      //double orders_volume_on_symbol=PendingsVolume(symbol);
      //allowed_volume=max_volume-opened_volume-orders_volume_on_symbol;
      allowed_volume=max_volume-opened_volume;
      if(allowed_volume>symbol_max_volume) allowed_volume=symbol_max_volume;
     }
   return(allowed_volume);
  }

It is because max_volume is 0 and opened_volume is 0;

Why max volume is 0 if there is no opened positions?

Build 2715

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
Predefined Macro Substitutions - Named Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5