Hany Taha:
The calculated LotSizeBuy = 0.04875487 and OrderLots() = 0.04
The calculated LotSizeBuy = 0.04875487 and OrderLots() = 0.04
when i try to Normalize LotSizeBuy it gives 0.05 which isn't equal to 0.04
is there any suggestion so the condition ( OrderLots() == LotSizeBuy ) can be true ?
- 0.048 rounded to two digits is 0.05. Why are you comparing the sizes? If you want to close it close it.
- 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.
- close=OrderClose(OrderTicket(),OrderLots()/2,Bid,3);The close amount must be a multiple of LotStep and be between min and max. The remaining amount must be also. Normalize OrderLots()/2 properly and test.
- Check your return codes
What are Function
return values ? How do I use them ? - MQL4 forum and Common Errors
in MQL4 Programs and How to Avoid Them - MQL4 Articles
Thnx all guys I tried honest_knave's idea and it worked fine
NOTES : (1) I changed plan and decided to close 2/3 of OrderLots instead of 1/2 OrderLots
(2) Numbers 1.01 & 2.9 are obtained by experiment and covers almost all LotSize probabilities
now the comparison code is :
if(LotSizeBuy / OrderLots() > 1.01 && LotSizeBuy / OrderLots() < 2.9)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
hi everyone,
I have an issue with my partial close code
The calculated LotSizeBuy = 0.04875487 and OrderLots() = 0.04
when i try to Normalize LotSizeBuy it gives 0.05 which isn't equal to 0.04
is there any suggestion so the condition ( OrderLots() == LotSizeBuy ) can be true ?
{
for(int n=OrdersTotal()-1; n>=0; n--)
{
select=OrderSelect(n,SELECT_BY_POS,MODE_TRADES);
{
RiskAmount = AccountBalance()*RiskPercent/100;
double LotSizeBuy=NormalizeDouble(RiskAmount/(((OrderOpenPrice()-OrderStopLoss())/pips)*10),2);
double LotSizeSell=NormalizeDouble(RiskAmount/(((OrderStopLoss()-OrderOpenPrice())/pips)*10),2);
{
if(OrderLots() == LotSizeBuy)
//
if (OrderType()==OP_BUY)
if((Ask - OrderOpenPrice())>((PartialClosePercent/100)*(OrderTakeProfit() - OrderOpenPrice())))
close=OrderClose(OrderTicket(),OrderLots()/2,Bid,3);
}
{
if(NormalizeDouble(OrderLots(),1) == NormalizeDouble(LotSizeSell,1))
if (OrderType()==OP_SELL)
if((OrderOpenPrice()-Ask)>((PartialClosePercent/100)*(OrderOpenPrice()-OrderTakeProfit())))
close=OrderClose(OrderTicket(),OrderLots()/2,Ask,3);
}
}
}
}