/// <summary> /// Duplicates an logic condition. /// </summary> public void DuplicateFilter(int slotToDuplicate) { if (Slot[slotToDuplicate].SlotType == SlotTypes.OpenFilter && OpenFilters < MaxOpenFilters || Slot[slotToDuplicate].SlotType == SlotTypes.CloseFilter && CloseFilters < MaxCloseFilters) { IndicatorSlot tempSlot = Slot[slotToDuplicate].Clone(); if (Slot[slotToDuplicate].SlotType == SlotTypes.OpenFilter) { int iAddedslot = AddOpenFilter(); Slot[iAddedslot] = tempSlot.Clone(); } if (Slot[slotToDuplicate].SlotType == SlotTypes.CloseFilter) { int addedslot = AddCloseFilter(); Slot[addedslot] = tempSlot.Clone(); } // Sets the slot numbers. for (int slot = 0; slot < Slots; slot++) { Slot[slot].SlotNumber = slot; } } }
/// <summary> /// Moves a filter downwards. /// </summary> public void MoveFilterDownwards(int slotToMove) { if (slotToMove >= Slots - 1 || Slot[slotToMove].SlotType != Slot[slotToMove + 1].SlotType) { return; } IndicatorSlot tempSlot = Slot[slotToMove + 1].Clone(); Slot[slotToMove + 1] = Slot[slotToMove].Clone(); Slot[slotToMove] = tempSlot.Clone(); // Sets the slot numbers. for (int slot = 0; slot < Slots; slot++) { Slot[slot].SlotNumber = slot; } }
/// <summary> /// Generates a random strategy /// </summary> private void GenerateStrategySlots() { // Determines the number of slots int openFilters = _random.Next(_lockedEntryFilters, _maxOpeningLogicSlots + 1); int closeFilters = 0; if (_lockedExitSlot == null || _exitIndicatorsWithFilters.Contains(Data.Strategy.Slot[Data.Strategy.CloseSlot].IndicatorName)) { closeFilters = _random.Next(_lockedExitFilters, _maxClosingLogicSlots + 1); } // Create a strategy Data.Strategy = new Strategy(openFilters, closeFilters) { StrategyName = "Generated", UseAccountPercentEntry = _strategyBest.UseAccountPercentEntry, MaxOpenLots = _strategyBest.MaxOpenLots, EntryLots = _strategyBest.EntryLots, AddingLots = _strategyBest.AddingLots, ReducingLots = _strategyBest.ReducingLots }; // Entry Slot int slot = 0; if (_lockedEntrySlot != null) { Data.Strategy.Slot[slot] = _lockedEntrySlot.Clone(); if (Data.Strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked) { GenerateIndicatorParameters(slot); } } else { GenerateIndicatorName(slot); GenerateIndicatorParameters(slot); } // Entry filter slots for (int i = 0; i < _lockedEntryFilters; i++) { slot++; Data.Strategy.Slot[slot] = _aLockedEntryFilter[i].Clone(); Data.Strategy.Slot[slot].SlotNumber = slot; if (Data.Strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked) { GenerateIndicatorParameters(slot); } } for (int i = _lockedEntryFilters; i < openFilters; i++) { slot++; GenerateIndicatorName(slot); GenerateIndicatorParameters(slot); } // Exit slot if (_lockedExitSlot != null) { slot++; Data.Strategy.Slot[slot] = _lockedExitSlot.Clone(); Data.Strategy.Slot[slot].SlotNumber = slot; if (Data.Strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked) { GenerateIndicatorParameters(slot); } } else { slot++; GenerateIndicatorName(slot); GenerateIndicatorParameters(slot); } // Exit filter slots if (IndicatorStore.ClosingIndicatorsWithClosingFilters.Contains(Data.Strategy.Slot[Data.Strategy.CloseSlot].IndicatorName) && closeFilters > 0) { for (int i = 0; i < _lockedExitFilters; i++) { slot++; Data.Strategy.Slot[slot] = _aLockedExitFilter[i].Clone(); Data.Strategy.Slot[slot].SlotNumber = slot; if (Data.Strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked) { GenerateIndicatorParameters(slot); } } for (int i = _lockedExitFilters; i < closeFilters; i++) { slot++; GenerateIndicatorName(slot); GenerateIndicatorParameters(slot); } } }
/// <summary> /// Generates a random strategy /// </summary> void GenerateStrategySlots() { // Determines the number of slots int openFilters = random.Next(lockedEntryFilters, maxOpeningLogicSlots + 1); int closeFilters = 0; if (lockedExitSlot == null || exitIndicatorsWithFilters.Contains(Data.Strategy.Slot[Data.Strategy.CloseSlot].IndicatorName)) { closeFilters = random.Next(lockedExitFilters, maxClosingLogicSlots + 1); } // Create a strategy Data.Strategy = new Strategy(openFilters, closeFilters); Data.Strategy.StrategyName = "Generated"; // Copy the trading sizes Data.Strategy.UseAccountPercentEntry = strategyBest.UseAccountPercentEntry; Data.Strategy.MaxOpenLots = strategyBest.MaxOpenLots; Data.Strategy.EntryLots = strategyBest.EntryLots; Data.Strategy.AddingLots = strategyBest.AddingLots; Data.Strategy.ReducingLots = strategyBest.ReducingLots; int slot = 0; // Entry Slot if (lockedEntrySlot != null) { Data.Strategy.Slot[slot] = lockedEntrySlot.Clone(); if (Data.Strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked) { GenerateIndicatorParameters(slot); } } else { GenerateIndicatorName(slot); GenerateIndicatorParameters(slot); } // Entry filter slots for (int i = 0; i < lockedEntryFilters; i++) { slot++; Data.Strategy.Slot[slot] = aLockedEntryFilter[i].Clone(); Data.Strategy.Slot[slot].SlotNumber = slot; if (Data.Strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked) { GenerateIndicatorParameters(slot); } } for (int i = lockedEntryFilters; i < openFilters; i++) { slot++; GenerateIndicatorName(slot); GenerateIndicatorParameters(slot); } // Exit slot if (lockedExitSlot != null) { slot++; Data.Strategy.Slot[slot] = lockedExitSlot.Clone(); Data.Strategy.Slot[slot].SlotNumber = slot; if (Data.Strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked) { GenerateIndicatorParameters(slot); } } else { slot++; GenerateIndicatorName(slot); GenerateIndicatorParameters(slot); } // Exit filter slots if (Indicator_Store.ClosingIndicatorsWithClosingFilters.Contains(Data.Strategy.Slot[Data.Strategy.CloseSlot].IndicatorName) && closeFilters > 0) { for (int i = 0; i < lockedExitFilters; i++) { slot++; Data.Strategy.Slot[slot] = aLockedExitFilter[i].Clone(); Data.Strategy.Slot[slot].SlotNumber = slot; if (Data.Strategy.Slot[slot].SlotStatus == StrategySlotStatus.Linked) { GenerateIndicatorParameters(slot); } } for (int i = lockedExitFilters; i < closeFilters; i++) { slot++; GenerateIndicatorName(slot); GenerateIndicatorParameters(slot); } } return; }