Forex_Strategy_Builder.Backtester.AccountExchangeRate C# (CSharp) Method

AccountExchangeRate() public static method

Account Exchange Rate.
public static AccountExchangeRate ( double price ) : double
price double
return double
        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;
        }

Usage Example

        /// <summary>
        /// Calculates the result
        /// </summary>
        private void Calculate()
        {
            bool         isLong       = (CbxDirection.SelectedIndex == 0);
            PosDirection posDir       = isLong ? PosDirection.Long : PosDirection.Short;
            int          lotSize      = Data.InstrProperties.LotSize;
            var          lots         = (double)NUDLots.Value;
            var          entryPrice   = (double)NUDEntryPrice.Value;
            var          exitPrice    = (double)NUDExitPrice.Value;
            var          daysRollover = (int)NUDDays.Value;
            double       point        = Data.InstrProperties.Point;
            string       unit         = " " + Configs.AccountCurrency;
            double       entryValue   = lots * lotSize * entryPrice;
            double       exitValue    = lots * lotSize * exitPrice;

            // Required margin
            double requiredMargin = (lots * lotSize / Configs.Leverage) *
                                    (entryPrice / Backtester.AccountExchangeRate(entryPrice));

            AlblOutputValues[0].Text = requiredMargin.ToString("F2") + unit;

            // Gross Profit
            double grossProfit = (isLong ? exitValue - entryValue : entryValue - exitValue) /
                                 Backtester.AccountExchangeRate(exitPrice);

            AlblOutputValues[1].Text = grossProfit.ToString("F2") + unit;

            // Spread
            double spread = Data.InstrProperties.Spread * point * lots * lotSize / Backtester.AccountExchangeRate(exitPrice);

            AlblOutputValues[2].Text = spread.ToString("F2") + unit;

            // Entry Commission
            double entryCommission = Backtester.CommissionInMoney(lots, entryPrice, false);

            AlblOutputValues[3].Text = entryCommission.ToString("F2") + unit;

            // Exit Commission
            double exitCommission = Backtester.CommissionInMoney(lots, exitPrice, true);

            AlblOutputValues[4].Text = exitCommission.ToString("F2") + unit;

            // Rollover
            double rollover = Backtester.RolloverInMoney(posDir, lots, daysRollover, exitPrice);

            AlblOutputValues[5].Text = rollover.ToString("F2") + unit;

            // Slippage
            double slippage = Data.InstrProperties.Slippage * point * lots * lotSize / Backtester.AccountExchangeRate(exitPrice);

            AlblOutputValues[6].Text = slippage.ToString("F2") + unit;

            // Net Profit
            double netProfit = grossProfit - entryCommission - exitCommission - rollover - slippage;

            AlblOutputValues[7].Text = netProfit.ToString("F2") + unit;
        }
All Usage Examples Of Forex_Strategy_Builder.Backtester::AccountExchangeRate