Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Profit/loss of opened orders
 Post subject: Profit/loss of opened orders Post rating: 0   New post Posted: Thu 03 Jun, 2010, 09:41 

User rating: 0
Joined: Thu 03 Jun, 2010, 09:26
Posts: 2
Hello

I would write in a .txt file the profit/loss of all my current opened orders.
How can I do this?

Thanks


 
 Post subject: Re: Profit/loss of opened orders Post rating: 0   New post Posted: Thu 03 Jun, 2010, 20:03 

User rating: 0
Joined: Fri 07 May, 2010, 02:59
Posts: 61
1) Look at Java's BufferedWriter class for doing the file I/O.
2) Figure out how to calculate the profit/loss of an order. It will look something like this:
Quote:
sign(direction) * (current price - entry price) * (total volume of order including leverage)

... where sign(direction) = +1 for long/buy, and -1 for short/sell
3) Write your result from the 2nd step to the file from the 1st step


 
 Post subject: Re: Profit/loss of opened orders Post rating: 0   New post Posted: Fri 04 Jun, 2010, 14:45 

User rating: 0
Joined: Thu 03 Jun, 2010, 09:26
Posts: 2
Thanks, but I am a newbie in java language so...
I saw this method in IOrder Class of JForex api: getProfitLossInAccountCurrency()
Maybe it can help, but I don't know how to write the code

Concerning writing in a file, I have already implement this code (to write the equity) :

public void onAccount(IAccount account) throws JFException {
this.account = account;
this.equity = account.getEquity();
// Stream to write file
FileOutputStream fout;

try
{
// Open an output stream
fout = new FileOutputStream ("C:\\Program Files\\MetaTrader - Alpari UK\\experts\\files\\equity.txt");

// Print a line of text
new PrintStream(fout).println (this.equity);

// Close our output stream
fout.close();
}
// Catches any error conditions
catch (IOException e)
{
System.err.println ("Unable to write to file");
System.exit(-1);
}
}

It works well, but now I would like to write the Profit/loss in another file.
If someone could write the code for me... thanks


 
 Post subject: Re: Profit/loss of opened orders Post rating: 0   New post Posted: Sat 05 Jun, 2010, 00:45 

User rating: 0
Joined: Fri 07 May, 2010, 02:59
Posts: 61
You should look at the Advertisement section and see if you can contract someone to do it for you, instead of asking someone to do your programming for free.

-Brian


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com