Hi everyone,
I aim to code something saying that only 80% of the position will be closed when reaching TP1.
I am scared that the value will not accepted by the broker.
Ho to tell the EA to choose a value around 80%..
Do you have any suggestions? or link to help me through this step.
Thanks for you help !
Luciole
0.8 * currentLotSize, then normalize against minlot,maxlot.
0.8 * currentLotSize, then normalize against minlot,maxlot.
That's not correct and produces invalid values as it ignores MODE_LOTSTEP.
Following is the correct approach in pure MQL4. After that you still need to check the returned value against violations of MODE_MINLOT/MODE_MAXLOT. However that's a different story:
/** * Round a lot size according to the specified symbol's lot step value (MODE_LOTSTEP). * * @param double lots - lot size * @param string symbol [optional] - symbol (default: the current symbol) * * @return double - rounded lot size */ double NormalizeLots(double lots, string symbol = "") { if (!StringLen(symbol)) symbol = Symbol(); double lotstep = MarketInfo(symbol, MODE_LOTSTEP); return(NormalizeDouble(MathRound(lots/lotstep) * lotstep, 2)); }
Regards
PS: You not only use this function to calculate 80% of something. You also use it for calculating 100% (i.e. your initial order lotsize) as your money management (risk, leverage, SL) will almost always calculate "something" for you which doesn't match the broker's expectations.
That's not correct and produces invalid values as it ignores MODE_LOTSTEP.
Following is the correct approach in pure MQL4. After that you still need to check the returned value against violations of MODE_MINLOT/MODE_MAXLOT. However that's a different story:
Regards
double NormLot(double lot) { double maxLot = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX); double minLot = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN); double lotStep = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP); double useLot = minLot; if(lot>useLot) { if(lot>maxLot) useLot = maxLot; else useLot = floor(lot/lotStep)*lotStep; } return useLot; }but of course you need to loop OrderSelect to get CurrentLotSize first,
then * 0.8
Sorry, the usage of floor() is again wrong. I would expect somebody with a rating of 15k to be more exact.
rating means nothing brother..
this is my approach, you can use ceil, round or whatever method you like.
i'm just try to help.
I really want to thank you both for your help.
I do not have enough experience to fully understand the problem,
but I will work on it this week-end in order to understand the situation.
Have a great day !
Luciole
I really want to thank you both for your help.
I do not have enough experience to fully understand the problem,
but I will work on it this week-end in order to understand the situation.
Have a great day !
Luciole
- If you want to close 80% the safe way would probably be to round up, so you close 0.07 lots.
- If you have no open position, intend to open a new one and your money management calculates 0.064 lots you probably want to round down, so you only open 0.06 lots.
This is what I mean with context. Usually people don't want to increase their intended risk, so they round in the direction of the smaller risk. This rounding direction cannot be known without knowing the trader's context. Are you opening a position (you increase your overall risk) or are you closing (part of) a position (you lower your overall risk)?
Imagine your lotstep is 0.1, you have an open position of 0.8 lots and want to close 70%. What do you do?
Good morning everyone
thanks for your help
the CDouble library seems to be very easy to use.
I have a question. what is lotStep?
why do you divide the lot by the lotStep and then multiply by the lot step again?
I understand that mathfloor() or mathround() only applied the first division
how much will be lot step if i want to close 80%?
A short example with number will definitely help..
I may ask a lot, sorry and thanks for your help
Have a great Monday
Luciole

- 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 aim to code something saying that only 80% of the position will be closed when reaching TP1.
I am scared that the value will not accepted by the broker.
Ho to tell the EA to choose a value around 80%..
Do you have any suggestions? or link to help me through this step.
Thanks for you help !
Luciole