• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 3:12am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 3:12am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

How to calculate average price for open orders 26 replies

Close all open trades if current total open lotsize exceeds"X" 0 replies

Close all pending orders and open orders once they reach profit target 3 replies

function to calculate stoploss for all open orders based X% DrawDown 0 replies

script to "close open orders" and "open opposite orders" 3 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: How do I calculate total profit of all open orders?
Cancel

How do I calculate total profit of all open orders?

  • Post #1
  • Quote
  • First Post: Aug 19, 2010 2:40pm Aug 19, 2010 2:40pm
  •  mindreality
  • | Joined Mar 2010 | Status: Member | 249 Posts
I understand that OrderProfit() is used to get the open order profit.

But if I have more than one open order, how do I calculate total profit of all open orders?
  • Post #2
  • Quote
  • Aug 19, 2010 2:52pm Aug 19, 2010 2:52pm
  •  TJPLD
  • Joined Jan 2008 | Status: Inertial Member | 2,297 Posts
How about looping trough all Open Orders and summing up all the OrderProfit()s?
 
 
  • Post #3
  • Quote
  • Aug 19, 2010 2:53pm Aug 19, 2010 2:53pm
  •  ecntrader
  • | Joined Jul 2010 | Status: Profitable | 68 Posts
double profit()
{
total=OrdersTotal();
profit=0;
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
profit+=OrderProfit();
}
return(profit);
}
Today I BUY, tomorrow I SELL!
 
 
  • Post #4
  • Quote
  • Aug 19, 2010 3:25pm Aug 19, 2010 3:25pm
  •  mindreality
  • | Joined Mar 2010 | Status: Member | 249 Posts
Why OrderMagicNumber()!=Magic ?

I thought it should be OrderMagicNumber == Magic
 
 
  • Post #5
  • Quote
  • Aug 19, 2010 3:35pm Aug 19, 2010 3:35pm
  •  mindreality
  • | Joined Mar 2010 | Status: Member | 249 Posts
WHere do I place the code?

I get the (- function definition unexpected error
 
 
  • Post #6
  • Quote
  • Aug 20, 2010 11:20am Aug 20, 2010 11:20am
  •  Oksana17
  • | Membership Revoked | Joined Sep 2007 | 903 Posts
Not sure if you got any help from these guys, but here's what I use.. let me write it up right now..

PHP Code
  
double totalprofit
;
for(
int a=0;a<OrdersTotal();a++)
if(
OrderSelect(a,0,0))
totalprofit+=OrderProfit(); 
Request custom Expert Advisor or Indicator: dostapyuk "at" gmail . com
 
 
  • Post #7
  • Quote
  • Aug 20, 2010 11:29am Aug 20, 2010 11:29am
  •  tunera
  • | Commercial Member | Joined Sep 2005 | 2,784 Posts
Why not use AccountProfit() ?

It show the profit for all the opened positions (profit or loss of course)
 
 
  • Post #8
  • Quote
  • Aug 20, 2010 12:42pm Aug 20, 2010 12:42pm
  •  mindreality
  • | Joined Mar 2010 | Status: Member | 249 Posts
AccountProfit() ?

That solves everything then.
 
 
  • Post #9
  • Quote
  • Aug 20, 2010 12:44pm Aug 20, 2010 12:44pm
  •  mindreality
  • | Joined Mar 2010 | Status: Member | 249 Posts
But then again, AccountProfit() wouldn't be the best thing to use if I only need to know the combined open trade profits of a certain magic number right? Which means I need to add up only those open trades and not others of the same account.
 
 
  • Post #10
  • Quote
  • Last Post: Aug 20, 2010 12:48pm Aug 20, 2010 12:48pm
  •  mindreality
  • | Joined Mar 2010 | Status: Member | 249 Posts
Anyway I found a solution, which is to take each open order (of the same magic number) and substract it from the current bid price or ask price depending on whether it is a long or short order. Bid for closing long, and ask for closing short.

I add up all the positive or negative values to get a net positive or negative value to determine how many points I am in profit or loss.
 
 
  • Platform Tech
  • /
  • How do I calculate total profit of all open orders?
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023