/// <summary> /// Initializes the global variables. /// </summary> private void InitTrade() { // Sets the maximum lots _maximumLots = 100; foreach (IndicatorSlot slot in Data.Strategy.Slot) if (slot.IndicatorName == "Lot Limiter") _maximumLots = (int) slot.IndParam.NumParam[0].Value; _maximumLots = Math.Min(_maximumLots, Data.Strategy.MaxOpenLots); _openTimeExec = Data.Strategy.Slot[Data.Strategy.OpenSlot].IndParam.ExecutionTime; _openStrPriceType = StrategyPriceType.Unknown; if (_openTimeExec == ExecutionTime.AtBarOpening) _openStrPriceType = StrategyPriceType.Open; else if (_openTimeExec == ExecutionTime.AtBarClosing) _openStrPriceType = StrategyPriceType.Close; else _openStrPriceType = StrategyPriceType.Indicator; _closeTimeExec = Data.Strategy.Slot[Data.Strategy.CloseSlot].IndParam.ExecutionTime; _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.CloseAndReverse; else _closeStrPriceType = StrategyPriceType.Indicator; if (Configs.UseLogicalGroups) { Data.Strategy.Slot[Data.Strategy.OpenSlot].LogicalGroup = "All"; // Allows calculation of open slot for each group. Data.Strategy.Slot[Data.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 = Data.Strategy.OpenSlot; slot < Data.Strategy.CloseSlot; slot++) { if (!_groupsAllowLong.ContainsKey(Data.Strategy.Slot[slot].LogicalGroup)) _groupsAllowLong.Add(Data.Strategy.Slot[slot].LogicalGroup, false); if (!_groupsAllowShort.ContainsKey(Data.Strategy.Slot[slot].LogicalGroup)) _groupsAllowShort.Add(Data.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 = Data.Strategy.CloseSlot + 1; slot < Data.Strategy.Slots; slot++) { string group = Data.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 if N Bars Exit is present as CloseFilter, could be any slot after first closing slot. - Krog _nBarsExit = 0; for (int slot = Data.Strategy.CloseSlot; slot < Data.Strategy.Slots; slot++) { if (Data.Strategy.Slot[slot].IndicatorName == "N Bars Exit") { _nBarsExit = (int) Data.Strategy.Slot[slot].IndParam.NumParam[0].Value; break; } } }
/// <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; _consecutiveWins = 0; _moneyManager = new MoneyManager(Strategy.MoneyManagementStrat); }
/// <summary> /// Resets the variables and prepares the arrays /// </summary> static void ResetStart() { marginCallBar = 0; totalOrders = 0; totalPositions = 0; isScanned = 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(bar, 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 (System.Collections.Generic.KeyValuePair<string, bool> 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; } return; }
/// <summary> /// Initializes the global variables. /// </summary> void InitTrade() { micron = Data.InstrProperties.Point / 2d; // Sets the maximum lots maximumLots = 100; foreach (IndicatorSlot slot in Data.Strategy.Slot) if (slot.IndicatorName == "Lot Limiter") maximumLots = (int)slot.IndParam.NumParam[0].Value; maximumLots = Math.Min(maximumLots, Data.Strategy.MaxOpenLots); openTimeExec = Data.Strategy.Slot[Data.Strategy.OpenSlot].IndParam.ExecutionTime; openStrPriceType = StrategyPriceType.Unknown; if (openTimeExec == ExecutionTime.AtBarOpening) openStrPriceType = StrategyPriceType.Open; else if (openTimeExec == ExecutionTime.AtBarClosing) openStrPriceType = StrategyPriceType.Close; else openStrPriceType = StrategyPriceType.Indicator; closeTimeExec = Data.Strategy.Slot[Data.Strategy.CloseSlot].IndParam.ExecutionTime; 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.CloseAndReverse; else closeStrPriceType = StrategyPriceType.Indicator; if (Configs.UseLogicalGroups) { Data.Strategy.Slot[Data.Strategy.OpenSlot].LogicalGroup = "All"; // Allows calculation of open slot for each group. Data.Strategy.Slot[Data.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 = Data.Strategy.OpenSlot; slot < Data.Strategy.CloseSlot; slot++) { if (!groupsAllowLong.ContainsKey(Data.Strategy.Slot[slot].LogicalGroup)) groupsAllowLong.Add(Data.Strategy.Slot[slot].LogicalGroup, false); if (!groupsAllowShort.ContainsKey(Data.Strategy.Slot[slot].LogicalGroup)) groupsAllowShort.Add(Data.Strategy.Slot[slot].LogicalGroup, false); } // List of logical groups openingLogicGroups = new List<string>(); foreach (System.Collections.Generic.KeyValuePair<string, bool> kvp in groupsAllowLong) openingLogicGroups.Add(kvp.Key); // Logical groups of the closing conditions. closingLogicGroups = new List<string>(); for (int slot = Data.Strategy.CloseSlot + 1; slot < Data.Strategy.Slots; slot++) { string group = Data.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 if N Bars Exit is present as CloseFilter, could be any slot after first closing slot. - Krog NBarsExit = 0; for (int slot = Data.Strategy.CloseSlot; slot < Data.Strategy.Slots; slot++) { if (Data.Strategy.Slot[slot].IndicatorName == "N Bars Exit") { NBarsExit = (int)Data.Strategy.Slot[slot].IndParam.NumParam[0].Value; break; } } return; }