# Trying to incorporate MaxLots and MinLots into EA

227

Hi Everyone.  I need help again, please.  I would like to incorporate the following into my EA, but it is completely ignored.  Why does the EA not call the Maxlots function?  When I run the EA on the Strategy tester, the Lotsize go much higher than my input.  Thank you.  EDIT:  Also I just noticed that the Stoploss feature doesn't work either.

```extern double Maxlots=50;  //<------ This is ignored

int start()
{
int TS=TrailingStart-TrailingStop;
int stoplevel=(MarketInfo(Symbol(),MODE_STOPLEVEL))/10;
if(StopLoss<=stoplevel) StopLoss=stoplevel;
if(Stoploss<=stoplevel) Stoploss=stoplevel;
if(TS<=stoplevel) TrailingStart=stoplevel+TrailingStop;
double Lots = NormalizeDouble(AccountEquity()*Percentage*Lotsize/100, 2);
double SL=StopLoss*Point*10;
double point=Point*10;
double MinLots = MarketInfo(Symbol(),MODE_MINLOT);
double MaxLots = MarketInfo(Symbol(),MODE_MAXLOT);
double HedgeLots=NormalizeDouble(OrderLots()*Multiplier,2);

if(Lots>MaxLots) Lots=MaxLots;
if(Lots>Maxlots) Lots=Maxlots;
if(Lots<MinLots) Lots=MinLots;
if(HedgeLots>MaxLots) HedgeLots=MaxLots;
if(Lots>MaxLots || Lots<MinLots || HedgeLots>MaxLots)
{
}
//Rest of code for OrderSelect and OrderSend, etc.```
15321

Trader3000: Why does the EA not call the Maxlots function?
1. Not a function, it is a variable.
2.  Of course it is ignored because you declared a local variable of the same name. You would know this had you set #property strict. ```extern double Maxlots=50;  //<------ This is ignored int start(){    :    double MaxLots = MarketInfo(Symbol(),MODE_MAXLOT);```

3.  Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right. `double HedgeLots=NormalizeDouble(OrderLots()*Multiplier,2);`
Moderator
10376

MaxLots and Maxlots

StopLoss and Stoploss

You don't show any code for OrderSend, so we don't know what variables you are using for that

`   if(Lots>MaxLots || Lots<MinLots || HedgeLots>MaxLots)`

There is little point in this test after you have modified the values.

```  if(a!=b)
a=b;
if(a!-b)
Print("This will never be printed because I have modified a to equal b");```
227

Thank you very much to both of you for your help.  I'm not sure what I did wrong, but the MaxLots/MinLots does work now.  Thank you also for the links.  I will study the information and fix my issues such as point to ticksize because I do want to do it right.  My apologies also for the confusion I caused with using small and capital letters.  I fixed this.  In future I will also use #property strict.  Since I started using this, I now have the following warning: "possible loss of data due to type conversion" on this line:

`int stoplevel=(MarketInfo(Symbol(),MODE_STOPLEVEL))/10;`

I googled this and it appears as if the issue lies with whether the value that is returned is an integer or double.  I printed the stoplevel for the EURUSD, and it prints "5.0".  So I changed from int stoplevel to double stoplevel, but the warning still exists. While I read all the articles and documentation on this issue I am unable to resolve it.

My code looks like this:

```extern double MyMaxlots=20;

int start()
{
int TS=TrailingStart-TrailingStop;
double stoplevel=(MarketInfo(Symbol(),MODE_STOPLEVEL))/10;
if(StopLossOriginal<=stoplevel) StopLossOriginal=stoplevel;
if(StopLossHedge<=stoplevel) StopLossHedge=stoplevel;
if(TS<=stoplevel) TrailingStart=stoplevel+TrailingStop;
double Lots = AccountEquity()*Percentage*Lotsize/100;
double point=Point*10;
double SL=StopLossOriginal*point;
double MinLots = MarketInfo(Symbol(),MODE_MINLOT);
double MaxLots = MarketInfo(Symbol(),MODE_MAXLOT);
double HedgeLots=NormalizeDouble(OrderLots()*Multiplier,2);

if(Lots>MaxLots) Lots=MaxLots;
if(Lots>MyMaxlots) Lots=MyMaxlots;
if(Lots<MinLots) Lots=MinLots;
//if(HedgeLots>MaxLots) HedgeLots=MaxLots;
if(HedgeLots>MyMaxlots) HedgeLots=MyMaxlots*3;```