Download MetaTrader 5

Strange Problem with OrderCommission() function

To add comments, please log in or register
Yochanan Gerbi
612
Yochanan Gerbi  

Hello freinds,

I set

ProfitB = rderProfit()+OrderCommission();

The value of the parameter "ProfitB" is seen on the screen.

The problem is sometimes that the value of "ProfitB" is seen (and computed) without the Commission value. 

Any idea, please?

Thanks

Yochanan Gerbi
612
Yochanan Gerbi  
Has any one an idea??
Keith Watford
Moderator
10566
Keith Watford  

Without more details I doubt that anyone can help you.

Can you show the relevant code? 

Yochanan Gerbi
612
Yochanan Gerbi  
GumRai:

Without more details I doubt that anyone can help you.

Can you show the relevant code? 

OK GumRai, here are the relevant details from the code:

void Comput_Profits_of relevant_Pair()
{
  ProfitB1=0.0;

  for (j = 0; j < OrdersTotal(); j++)
  {
    OrderSelect(j,SELECT_BY_POS,MODE_TRADES);

    if (OrderMagicNumber() == MagicNumber_A && OrderSymbol() == "EURUSD") ProfitB = ProfitB+OrderProfit()+OrderCommission();

  }
  return(0);
}


Comment  "ProfitB =   $ " + DoubleToStr(ProfitB1,2) +


And as I wrote I see on the screen the profit without the commission.


BTW at the moment The screen is correct, but 6 hours ago it was shown as I wrote!!


Any idea...?


Thanks

Keith Watford
Moderator
10566
Keith Watford  
crossy:

OK GumRai, here are the relevant details from the code:

void Comput_Profits_of relevant_Pair()
{
  ProfitB1=0.0;

  for (j = 0; j < OrdersTotal(); j++)
  {
    OrderSelect(j,SELECT_BY_POS,MODE_TRADES);

    if (OrderMagicNumber() == MagicNumber_A && OrderSymbol() == "EURUSD") ProfitB = ProfitB+OrderProfit()+OrderCommission();

  }
  return(0);
}


Comment  "ProfitB =   $ " + DoubleToStr(ProfitB1,2) +


And as I wrote I see on the screen the profit without the commission.


BTW at the moment The screen is correct, but 6 hours ago it was shown as I wrote!!


Any idea...?


Thanks



I don't believe that is your code

void Comput_Profits_of relevant_Pair()

 It will not compile with the space between "of" and "relevant"

 Also

void Comput_Profits_of relevant_Pair()
{
  ProfitB1=0.0;

  for (j = 0; j < OrdersTotal(); j++)
  {
    OrderSelect(j,SELECT_BY_POS,MODE_TRADES);

    if (OrderMagicNumber() == MagicNumber_A && OrderSymbol() == "EURUSD") ProfitB = ProfitB+OrderProfit()+OrderCommission();

  }
  return(0);
}



Comment  "ProfitB =   $ " + DoubleToStr(ProfitB1,2) +

 

 You set a variable named ProfitB1 to zero before the loop but use a different variable, ProfitB for the running total in the loop.

As you use ProfitB1 in your comment ( which I assume is within another function and not as it shows here), your comment will always show zero. Unless the value is changed elsewhere. 

whroeder1
16349
whroeder1  
crossy: here are the relevant details from the code:
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Check your return codes (OrderSelect) 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
  3. Get in the habit of counting down Loops and Closing or Deleting Orders - MQL4 forum
GumRai: I don't believe that is your code
And you can't return zero from a void function.
Yochanan Gerbi
612
Yochanan Gerbi  
GumRai:

I don't believe that is your code

 It will not compile with the space between "of" and "relevant"

 Also

 

 You set a variable named ProfitB1 to zero before the loop but use a different variable, ProfitB for the running total in the loop.

As you use ProfitB1 in your comment ( which I assume is within another function and not as it shows here), your comment will always show zero. Unless the value is changed elsewhere. 

Hello GamRai,


You are correct. What I wrote is not exacly the function (from the EA) that I use. The truth is that

I cann't attach the ful EA since it is not my purpose. So what I did was: taking the main part of it and try to show you the main line code that can help you to solve the problem.

I paste again the problem:


void Comput_Profits_of relevant_Pair()
{
  ProfitB1=0.0;

  for (j = 0; j < OrdersTotal(); j++)
  {
    OrderSelect(j,SELECT_BY_POS,MODE_TRADES);

    if (OrderMagicNumber() == MagicNumber_A && OrderSymbol() == "EURUSD") ProfitB1 = ProfitB1+OrderProfit()+OrderCommission();

  }
  return(0);
}


Comment  "ProfitB1 =   $ " + DoubleToStr(ProfitB1,2) +


and thre problem is:

I set

ProfitB1 = rderProfit()+OrderCommission();

The value of the parameter "ProfitB1" is seen on the screen.

The problem is sometimes that the value of "ProfitB" is seen (and computed) without the Commission value. 

Any idea, please?

Thanks

SYED NAUFAL GADDAFI
1399
SYED NAUFAL GADDAFI  
Can't really say much since you don't properly post your codes using SRC (besides video icon).
Keith Watford
Moderator
10566
Keith Watford  

 "I paste again the problem:"

  and once again

It will not compile with the space between "of" and "relevant"

You are not copying and pasting working code. If you want help, then copy and paste from your actual code that has compiled with no errors 

whroeder1
16349
whroeder1  
and use SRC
Yochanan Gerbi
612
Yochanan Gerbi  
GumRai:

 "I paste again the problem:"

  and once again

It will not compile with the space between "of" and "relevant"

You are not copying and pasting working code. If you want help, then copy and paste from your actual code that has compiled with no errors 

Thankes.
12
To add comments, please log in or register