Errors, bugs, questions - page 7

 
FEDOR_MQL:

And at this stage of development: parameters, function call and function itself should show compile-time errors or not. If so, why? I have errors.

Yes, it does indeed show errors for some reason, even though there should not be any. I ask developers to pay attention to this. I changed it this way, there are no errors, but when I use switch switch it still shows error.

 //+------------------------------------------------------------------+
#property copyright "2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//--- input parameters

input double   Lots=0.1;
input bool     MM = true;
input double   Risk = 10.0;

double lots;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
  return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(MM) lots = LotSon();      //вызов функции LotSon 
   else lots = Lots;
  }
//+------------------------------------------------------------------+
double LotSon()
{
  double LotMin     = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
  double LotMax     = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
  double LotStep    = SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
  double Lot        = AccountInfoDouble(ACCOUNT_FREEMARGIN)/100000.0 * Risk;
  Lot               = MathMin(LotMax,MathMax(LotMin,Lot));
  
  if (Lot < LotMin) Lot = LotMin;
  if (Lot > LotMax) Lot = LotMax;
  // Вариант первый
  /*
  switch(LotStep)
  {
   case 0.01: Lot=NormalizeDouble(Lot,2);break;
   case 0.1 : Lot=NormalizeDouble(Lot,1);break;
   case 1.0 : Lot=NormalizeDouble(Lot,0);break;
  }
  */
  // Вариант второй
  if (LotStep == 0.01)Lot=NormalizeDouble(Lot,2);
  if (LotStep == 0.1) Lot=NormalizeDouble(Lot,1);
  if (LotStep == 1.0) Lot=NormalizeDouble(Lot,0);
  // Вариант третий
  // if (LotStep == 0.01)     Lot=NormalizeDouble(Lot,2);
  // else if (LotStep == 0.1) Lot=NormalizeDouble(Lot,1);
  // else if (LotStep == 1.0) Lot=NormalizeDouble(Lot,0);
 return(Lot); 
}
 
sergey1294:

Yes, indeed, for some reason errors although there should be none. I ask developers to pay attention to this, I re-did it like this, no errors, but when using switch it still gives error.

  switch(LotStep)
  {
   case 0.01: Lot=NormalizeDouble(Lot,2);break;
   case 0.1 : Lot=NormalizeDouble(Lot,1);break;
   case 1.0 : Lot=NormalizeDouble(Lot,0);break;
  }

You have to send lots as int, i.e. 0.01 = 1000 and 0.10 = 10000...

 
Interesting:

The lots should be sent here as int, i.e. 0.01 = 1000 and 0.10 = 10000...

According to you, it turns out that the function
SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
returns 1000 instead of 0.01
 
sergey1294:
So you're saying that the function
returns a value of 1,000 instead of 0.01.

No, I meant that the error will go away if the code looks like this:

  switch(StepSize)
  {
   case 1000:   Lot=NormalizeDouble(Lot,2);break;
   case 10000:  Lot=NormalizeDouble(Lot,1);break;
   case 100000: Lot=NormalizeDouble(Lot,0);break;
  }
 
Just now noticed that in
switch
cannot use double precision numbers, then this option cannot be used in this case.
 
sergey1294:
Just now noticed that in
cannot use double-precision numbers, then this option cannot be used in this case.
You can if you convert lots to int beforehand. As I said above...
 
the question remains as to why such a design cannot be used
  if (LotStep == 0.01)return(NormalizeDouble(Lot,2));
  if (LotStep == 0.1) return(NormalizeDouble(Lot,1));
  if (LotStep == 1.0) return(NormalizeDouble(Lot,0));
 
Interesting:
You may do it if you convert lots to int. What I said above...

Can I see the code, if you don't mind? I've tried it all ways, but it doesn't work.

I don't know whether it's easier to add the risk in percents of securities. Thank you!

 
FEDOR_MQL:

Can I see the code, if you don't mind? I've tried it all ways, but it doesn't work.

I don't know if there is any other simple variant, just add the risk in percents of the deposit to the EA. Thank you!

It depends on what you need as the result. Here, for example, I gave a number of interesting functions on the calculation of risks


And to make this code work, you only need to multiply the lot by 100000 and input it in switch(StepSize) as a parameter (variable of int type).


PS

And in general, to be honest, I don't quite understand the purpose of all these variants? I mean, in the context of this function, one of the last.... is enough.

 
Interesting:

It depends on what you want to get in the end result, here, for example, I gave some interesting functions on the risk


And to make this code work, you just need to multiply lot by 100000 and pass it to switch(StepSize) as parameter (variable of int type).

Your article is what I think I need. Thanks
Reason: