How to calculate profit in ea

 

Been looking around and did not find my answer for this question

i want to know how to calculate the profit/loss

but i dont want it to calculate the totalprofit so using orderprofit will not work because it calculates the profit loss on all open pairs.

here is an example

i have the following open positions

i want to calculate the profit/loss on this hedge

Long gbpusd

short eurusd

and on this hedge

long eurusd

long usdchf

the to hedges should be calculated seperatly

zleepan

 

First selcect order that u want to count (by magic number or position , and currency)

And then:

For long orders:

Bid - OrderOpenPrice() - Spread;

For short orders

OrderOpenPrice - Bid;

 

you can use:

if(OrderSelect(10, SELECT_BY_POS)==true)

Print("Profit for the order 10 ",OrderProfit());

 
forex_trader:
you can use:

if(OrderSelect(10, SELECT_BY_POS)==true)

Print("Profit for the order 10 ",OrderProfit());

Hi forex_trader, did u read the question?

zleepan:
but i dont want it to calculate the totalprofit so using orderprofit will not work because it calculates the profit loss on all open pairs.
 

buy :

{(OrderClosePrice-OrderOpenPrice)*lotsize*ContractSize}/OrderClosePrice

sell :

{(OrderOpenPrice-OrderClosePrice)*lotsize*ContractSize}/OrderClosePrice

 

Profit!

Kalenzo:
First selcect order that u want to count (by magic number or position , and currency)

And then:

For long orders:

Bid - OrderOpenPrice() - Spread;

For short orders

OrderOpenPrice - Bid;

Maybe this formula better:

if(OrderType()==OP_BUY)

profit = (Bid - OrderOpenPrice()) / MarketInfo(OrderSymbol(),MODE_POINT);

if(OrderType()==OP_SELL)

profit = (OrderOpenPrice() - Ask) / MarketInfo(OrderSymbol(),MODE_POINT);
Reason: