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 parametersinputdouble Lots=0.1;
inputbool MM = true;
inputdouble Risk = 10.0;
double lots;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
return(0);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
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);
}
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.
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));
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.
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.
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.
You have to send lots as int, i.e. 0.01 = 1000 and 0.10 = 10000...
The lots should be sent here as int, i.e. 0.01 = 1000 and 0.10 = 10000...
returns 1000 instead of 0.01
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:
switchcannot use double precision numbers, then this option cannot be used in this case.Just now noticed that in
cannot use double-precision numbers, then this option cannot be used in this case.
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!
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.
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).