Forex_Strategy_Builder.Backtester.Commission C# (CSharp) Method

Commission() public static method

Calculates the commission in pips.
public static Commission ( double lots, double price, bool isPosClosing ) : double
lots double
price double
isPosClosing bool
return double
        public static double Commission(double lots, double price, bool isPosClosing)
        {
            double commission = 0;

            if (InstrProperties.Commission == 0)
                return 0;

            if (InstrProperties.CommissionTime == Commission_Time.open && isPosClosing)
                return 0; // Commission is not applied to the position closing

            if (InstrProperties.CommissionType == Commission_Type.pips)
                commission = InstrProperties.Commission;

            else if (InstrProperties.CommissionType == Commission_Type.percents)
            {
                commission = (price / InstrProperties.Point) * (InstrProperties.Commission / 100);
                return commission;
            }

            else if (InstrProperties.CommissionType == Commission_Type.money)
                commission = InstrProperties.Commission / (InstrProperties.Point * InstrProperties.LotSize);

            if (InstrProperties.CommissionScope == Commission_Scope.lot)
                commission *= lots; // Commission per lot

            return commission;
        }