1 (edited by krog 2010-08-03 02:16:07)

Topic: how to calculate floating p/l?

I am trying to match FSB's calculation of the floating p/l. What is the formula to calculate it? I've tried the entry price with the closing price (of a later bar) and the high and low, subtracting spreads, but I can not get my number to match FSB's number.
I think it's for USDJPY. In Market>Edit Instruments.. for USDJPY, it has:
Account Exchange Rate  -  Deal Price  -  00000
instead of
Account Exchange Rate  -  USDJPY  -  100.0000
like for EURJPY and GBPJPY, which don't have the difference.

Re: how to calculate floating p/l?

Psevdo Code

Opening a new long position:
posPrice = orderPrice + (spread + slippage) * point;
FloatingPL = orderLots * (barClose - posPrice) / point;
MoneyFloatingPL = orderLots * (barClose - posPrice) * lotSize / AccountExchangeRate(orderPrice);

Adding to a long pos:
posPrice = (lotsOld * priceOld + orderLots * (orderPrice + (spread + slippage) * point)) / (lotsOld + orderLots);
FloatingPL = (lotsOld + orderLots) * (barClose - posPrice) / point;
MoneyFloatingPL = (lotsOld + orderLots) * (barClose - posPrice) * lotSize / AccountExchangeRate(orderPrice);

Reducing a long position (we are still long):
posPrice = priceOld;
FloatingPL = (lotsOld - orderLots) * (barClose - priceOld) / point;
MoneyFloatingPL = (lotsOld - orderLots) * (barClose - priceOld) * lotSize / AccountExchangeRate(orderPrice);

Reversing a long position (it becomes a short position):
posPrice = orderPrice - (spread + slippage) * point;
FloatingPL = (orderLots - lotsOld) * (posPrice - barClose) / point;
MoneyFloatingPL = (orderLots - lotsOld) * (posPrice - barClose) * lotSize / AccountExchangeRate(orderPrice);

Transferring to the next bar:
posPrice += point * days * swapLongPips;
FloatingPL = posLots * (barClose - posPrice) / point;
MoneyFloatingPL = orderLots * (barClose - posPrice) * lotSize / AccountExchangeRate(barClose);

/// <summary>
/// Account Exchange Rate
/// </summary>
public static double AccountExchangeRate(double price)
{
    double exchangeRate = 0;

    if (InstrProperties.PriceIn == Configs.AccountCurrency)
        exchangeRate = 1;
    else if (InstrProperties.InstrType == Instrumet_Type.Forex && Symbol.StartsWith(Configs.AccountCurrency))
        exchangeRate = price;
    else if (Configs.AccountCurrency == "USD")
        exchangeRate = InstrProperties.RateToUSD;
    else if (Configs.AccountCurrency == "EUR")
        exchangeRate = InstrProperties.RateToEUR;

    return exchangeRate;
}

EDIT:
For full information you can use the  Command Console (Tools - Additional - Command Console). For example if you want to see the params of position 345, write pos 345.

Re: how to calculate floating p/l?

Thanks for the explanation, it makes it very clear. The command console showed the difference -- my custom indicator was getting Floating PL in pips, and FSB Floating PL was in dollars.

I see in Indicator.cs, there are some Data.InstrProperties properties exposed to the Custom Indicator, eg Point, Digits, Spread. Is there a full list of what properties are exposed?

If AccountExchangeRate is static, how is it called?

Can it find out the number of open lots, or number of maximum open lots if set in Strategy Properties? Can it find out the Permanent Stop Loss and Permanent Take Profit from Strategy Properties?