Are u looking for total pips or total lots? When you paste your codes use the SRC button above.
Replace
int totallots; int totalnumberlots;
to
double totallots; double totalnumberlots;
Great. Thanks ubzen.
- OrderLots is a double. Sum doubles and the return type is also.
- Always use magic numbers. You want THIS EA's total on this chart, not all open orders. Always initialize your variables.
double GetTotalLots(){ double openLots = 0.0; for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){ openLots += OrderLots(); } return (openLots); }
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,
I am new to mql programming. I have a good knowledge in .Net programming language (c#, VB.NET). I read the books of MQL and now trying to implement my knowledge. I am trying to show the result of how may pips involved as a total in trades. Here is my code:
int ReturnTotalLots()
{
int totallots;
int totalnumberlots;
for (int i=0;i<OrdersTotal();i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
totallots=OrderLots();
if (totallots>0)
{
totalnumberlots=totalnumberlots+totallots;
}
}
}
return (totalnumberlots);
}
It is always returning 0. Tried many hours now. Is it a bug in MQL?
Thanks.