コード例 #1
0
 /// <summary>
 /// Copies all sessions.
 /// </summary>
 public static Session[] GetAllSessionsCopy()
 {
     var sessions = new Session[Bars];
     for (int bar = 0; bar < Bars; bar++)
         sessions[bar] = session[bar].Copy();
     return sessions;
 }
コード例 #2
0
        /// <summary>
        ///     Resets the variables and prepares the arrays
        /// </summary>
        private static void ResetStart()
        {
            MarginCallBar = 0;
            SentOrders = 0;
            totalPositions = 0;
            IsScanPerformed = false;
            micron = InstrProperties.Point/2d;
            lastEntryTime = new DateTime();

            // Sets the maximum lots
            maximumLots = 100;
            foreach (IndicatorSlot slot in Strategy.Slot)
                if (slot.IndicatorName == "Lot Limiter")
                    maximumLots = (int) slot.IndParam.NumParam[0].Value;

            maximumLots = Math.Min(maximumLots, Strategy.MaxOpenLots);

            session = new Session[Bars];
            for (int bar = 0; bar < Bars; bar++)
                session[bar] = new Session(MaxPositions, MaxOrders);

            for (int bar = 0; bar < FirstBar; bar++)
            {
                session[bar].Summary.MoneyBalance = Configs.InitialAccount;
                session[bar].Summary.MoneyEquity = Configs.InitialAccount;
            }

            ordCoord = new OrderCoordinates[Bars*MaxOrders];
            posCoord = new PositionCoordinates[Bars*MaxPositions];

            openTimeExec = Strategy.Slot[Strategy.OpenSlot].IndParam.ExecutionTime;
            closeTimeExec = Strategy.Slot[Strategy.CloseSlot].IndParam.ExecutionTime;

            openStrPriceType = StrategyPriceType.Unknown;
            if (openTimeExec == ExecutionTime.AtBarOpening)
                openStrPriceType = StrategyPriceType.Open;
            else if (openTimeExec == ExecutionTime.AtBarClosing)
                openStrPriceType = StrategyPriceType.Close;
            else
                openStrPriceType = StrategyPriceType.Indicator;

            closeStrPriceType = StrategyPriceType.Unknown;
            if (closeTimeExec == ExecutionTime.AtBarOpening)
                closeStrPriceType = StrategyPriceType.Open;
            else if (closeTimeExec == ExecutionTime.AtBarClosing)
                closeStrPriceType = StrategyPriceType.Close;
            else if (closeTimeExec == ExecutionTime.CloseAndReverse)
                closeStrPriceType = StrategyPriceType.CloseAndReverce;
            else
                closeStrPriceType = StrategyPriceType.Indicator;

            if (Configs.UseLogicalGroups)
            {
                Strategy.Slot[Strategy.OpenSlot].LogicalGroup = "All";
                // Allows calculation of open slot for each group.
                Strategy.Slot[Strategy.CloseSlot].LogicalGroup = "All";
                // Allows calculation of close slot for each group.

                groupsAllowLong = new Dictionary<string, bool>();
                groupsAllowShort = new Dictionary<string, bool>();
                for (int slot = Strategy.OpenSlot; slot < Strategy.CloseSlot; slot++)
                {
                    if (!groupsAllowLong.ContainsKey(Strategy.Slot[slot].LogicalGroup))
                        groupsAllowLong.Add(Strategy.Slot[slot].LogicalGroup, false);
                    if (!groupsAllowShort.ContainsKey(Strategy.Slot[slot].LogicalGroup))
                        groupsAllowShort.Add(Strategy.Slot[slot].LogicalGroup, false);
                }

                // List of logical groups
                openingLogicGroups = new List<string>();
                foreach (var kvp in groupsAllowLong)
                    openingLogicGroups.Add(kvp.Key);

                // Logical groups of the closing conditions.
                closingLogicGroups = new List<string>();
                for (int slot = Strategy.CloseSlot + 1; slot < Strategy.Slots; slot++)
                {
                    string group = Strategy.Slot[slot].LogicalGroup;
                    if (!closingLogicGroups.Contains(group) && group != "all")
                        closingLogicGroups.Add(group); // Adds all groups except "all"
                }

                if (closingLogicGroups.Count == 0)
                    closingLogicGroups.Add("all"); // If all the slots are in "all" group, adds "all" to the list.
            }

            // Search for N Bars
            hasNBarsExit = false;
            slotNBarsExit = -1;
            foreach (IndicatorSlot slot in Strategy.Slot)
                if (slot.IndicatorName == "N Bars Exit")
                {
                    hasNBarsExit = true;
                    slotNBarsExit = slot.SlotNumber;
                    break;
                }

            // Search for Enter Once indicator
            hasEnterOnce = false;
            slotEnterOnce = -1;
            foreach (IndicatorSlot slot in Strategy.Slot)
                if (slot.IndicatorName == "Enter Once")
                {
                    hasEnterOnce = true;
                    slotEnterOnce = slot.SlotNumber;
                    break;
                }

            // Martingale
            consecutiveLosses = 0;
        }