- Not a function, it is a variable.
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);
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);
Your code is easy to misread because of your use of variables with similar names
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");
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;
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.