/// <summary> /// Removes a filter from the strategy. /// </summary> public void RemoveFilter(int slotToRemove) { if (Slot[slotToRemove].SlotType != SlotTypes.OpenFilter && Slot[slotToRemove].SlotType != SlotTypes.CloseFilter) return; if (slotToRemove < CloseSlot) OpenFilters--; else CloseFilters--; var indSlotOld = (IndicatorSlot[]) Slot.Clone(); Slot = new IndicatorSlot[Slots]; // Copy all filters before this that has to be removed. for (int slot = 0; slot < slotToRemove; slot++) Slot[slot] = indSlotOld[slot]; // Copy all filters after this that has to be removed. for (int slot = slotToRemove; slot < Slots; slot++) Slot[slot] = indSlotOld[slot + 1]; // Sets the slot numbers. for (int slot = 0; slot < Slots; slot++) Slot[slot].SlotNumber = slot; }
/// <summary> /// Removes all close filters from the strategy. /// </summary> public void RemoveAllCloseFilters() { CloseFilters = 0; var indSlotOld = (IndicatorSlot[]) Slot.Clone(); Slot = new IndicatorSlot[Slots]; // Copy all slots except the close filters. for (int slot = 0; slot < Slots; slot++) Slot[slot] = indSlotOld[slot]; }
/// <summary> /// Adds a new Close Filter to the strategy. /// </summary> /// <returns>The number of new Close Filter Slot.</returns> public int AddCloseFilter() { CloseFilters++; var aIndSlotOld = (IndicatorSlot[]) Slot.Clone(); Slot = new IndicatorSlot[Slots]; int newSlotNumb = Slots - 1; // The number of new close filter slot. // Copy all old slots. for (int slot = 0; slot < newSlotNumb; slot++) Slot[slot] = aIndSlotOld[slot]; // Create the new slot. Slot[newSlotNumb] = new IndicatorSlot {SlotType = SlotTypes.CloseFilter}; // Sets the slot numbers. for (int slot = 0; slot < Slots; slot++) Slot[slot].SlotNumber = slot; return newSlotNumb; }
/// <summary> /// Adds a new Open Filter to the strategy. /// </summary> /// <returns>The number of new Open Filter Slot.</returns> public int AddOpenFilter() { OpenFilters++; var aIndSlotOld = (IndicatorSlot[]) Slot.Clone(); Slot = new IndicatorSlot[Slots]; int newSlotNumb = OpenFilters; // The number of new open filter slot. // Copy the open slot and all old open filters. for (int slot = 0; slot < newSlotNumb; slot++) Slot[slot] = aIndSlotOld[slot]; // Copy the close slot and all close filters. for (int slot = newSlotNumb + 1; slot < Slots; slot++) Slot[slot] = aIndSlotOld[slot - 1]; // Create the new slot. Slot[newSlotNumb] = new IndicatorSlot {SlotType = SlotTypes.OpenFilter}; // Sets the slot numbers. for (int slot = 0; slot < Slots; slot++) Slot[slot].SlotNumber = slot; return newSlotNumb; }
/// <summary> /// Creates a strategy /// </summary> private void CreateStrategy(int openFilters, int closeFilters) { StrategyName = "Unnamed"; OpenFilters = openFilters; CloseFilters = closeFilters; Slot = new IndicatorSlot[Slots]; for (int slot = 0; slot < Slots; slot++) { Slot[slot] = new IndicatorSlot {SlotNumber = slot, SlotType = GetSlotType(slot)}; } }
/// <summary> /// Shows if the slot has any parameters to generate. /// </summary> private bool IsSlotHasParameters(IndicatorSlot slot) { foreach (ListParam listParam in slot.IndParam.ListParam) if (listParam.Enabled && listParam.ItemList.Length > 1) return true; foreach (NumericParam numericParam in slot.IndParam.NumParam) if (numericParam.Enabled) return true; return false; }
/// <summary> /// Prepare the strategy for generating /// </summary> private void PrepareStrategyForGenerating() { lockedEntrySlot = null; lockedEntryFilters = 0; aLockedEntryFilter = new IndicatorSlot[Math.Max(Strategy.MaxOpenFilters, strategyBest.OpenFilters)]; lockedExitSlot = null; lockedExitFilters = 0; aLockedExitFilter = new IndicatorSlot[Math.Max(Strategy.MaxCloseFilters, strategyBest.CloseFilters)]; // Copy the locked slots for (int slot = 0; slot < strategyBest.Slots; slot++) { if (strategyBest.Slot[slot].SlotStatus == StrategySlotStatus.Locked || strategyBest.Slot[slot].SlotStatus == StrategySlotStatus.Linked) { if (strategyBest.Slot[slot].SlotType == SlotTypes.Open) lockedEntrySlot = strategyBest.Slot[slot]; else if (strategyBest.Slot[slot].SlotType == SlotTypes.OpenFilter) { aLockedEntryFilter[lockedEntryFilters] = strategyBest.Slot[slot]; lockedEntryFilters++; } else if (strategyBest.Slot[slot].SlotType == SlotTypes.Close) lockedExitSlot = strategyBest.Slot[slot]; else if (strategyBest.Slot[slot].SlotType == SlotTypes.CloseFilter) { aLockedExitFilter[lockedExitFilters] = strategyBest.Slot[slot]; lockedExitFilters++; } } } if (chbGenerateNewStrategy.Checked) bestValue = 0; else if (rbnCustomSortingNone.Checked) bestValue = (isOOS ? Backtester.Balance(barOOS) : Backtester.NetBalance); else bestValue = float.MinValue; maxOpeningLogicSlots = chbMaxOpeningLogicSlots.Checked ? (int) nudMaxOpeningLogicSlots.Value : Strategy.MaxOpenFilters; maxClosingLogicSlots = chbMaxClosingLogicSlots.Checked ? (int) nudMaxClosingLogicSlots.Value : Strategy.MaxCloseFilters; }