# count profit of the oldest Sell-position / Buy-position

256

Hello

i would like to calculate the Profit of the oldest Sell / oldest Buy Position in the Chart....

same like that:

```//+------------------------------------------------------------------+
double countprofitBS(int mode,int order_type)
{
double profit=0;
if(OrdersTotal()>0)
{
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSymbol()==Symbol() && OrderType()==order_type && OrderMagicNumber()==magic)
{
if(mode==0)profit=profit+(OrderClosePrice()-OrderOpenPrice())/pt;
if(mode==1)profit=profit+OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
return(profit);
}
```

i would like to get the Funktion for countprofitBS-oldest.....

could someone help me?

20214

christion: could someone help me?
1. Help you with what? You haven't stated a problem, you stated a want.
You have only four choices:
1. Search for it,
2. Beg at
3. learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
4. or pay (Freelance) someone to code it.
We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
No free help
urgent help.

2. ```(int mode,
:
if(mode==0)
if(mode==1)```
Don't use ints when you mean an enumeration.
256

i would like to know the Profit in Dollar of the oldest open/pending order in the Chart for the sell and buy. and yes i don't know really how...

twice i was looiking for someone who could code it, but I am still at the same Position....

```//+------------------------------------------------------------------+
double countprofitoldestshort(int mode,int order_type)
{
double profit=0;
if(OrdersTotal()>0)
{
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSymbol()==Symbol() &&  && OrderType()==OP_SELL && OrderMagicNumber()==magic)
{
if(mode==0)profit=profit+(OrderClosePrice()-OrderOpenPrice())/pt;
if(mode==1)profit=profit+OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
return(profit);
}

//+------------------------------------------------------------------+
double countprofitoldestlong(int mode,int order_type)
{
double profit=0;
if(OrdersTotal()>0)
{
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSymbol()==Symbol() &&  && OrderType()==OP_BUY && OrderMagicNumber()==magic)
{
if(mode==0)profit=profit+(OrderClosePrice()-OrderOpenPrice())/pt;
if(mode==1)profit=profit+OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
return(profit);
}

```
38685

christion:

i would like to know the Profit in Dollar of the oldest open/pending order in the Chart for the sell and buy. and yes i don't know really how...

twice i was looiking for someone who could code it, but I am still at the same Position....

Welcome,

• Usually people who can't code don't receive free help on this forum, though it could happen if you are lucky, be patient.
• If you don't want to learn to code, nothing bad, you can either look at the Codebase if something free already exists, or in the Market for paid products (sometimes free also).
• Finally, you also have the option to hire a programmer in the Freelance section.

Good luck.

20214

christion: and yes i don't know really how...

i was looiking for someone who could code it,

1. If you had it on a piece of paper, how would you do it? Assume the first. Compare it to the second and choose the older. Compare that to the third. Etc. Code that.
2. Asked and answered twice. <edited by moderator> Learn to code or pay someone.
38685

whroeder1:
1. If you had it on a piece of paper, how would you do it? Assume the first. Compare it to the second and choose the older. Compare that to the third. Etc. Code that.
2. Asked and answered twice. <edited by moderator> Learn to code or pay someone.