public RandomStrategy(ref PluginServices pluginService, int minind, int maxind, int minper, int maxper, bool disposition) { _randomClass = new Random(); _indicators = new ArrayList(); _entryName = ""; _pluginService = pluginService; _minIndicators = minind; _maxIndicators = maxind; _minPeriod = minper; _maxPeriod = maxper; Disposition = disposition; int indicators = _randomClass.Next(_minIndicators, _maxIndicators + 1); for (int i = 0; i < indicators; i++) { int indicator = _randomClass.Next(1, _pluginService.AvailablePlugins.Count + 1) - 1; int period = _randomClass.Next(_minPeriod, _maxPeriod); AvailablePlugin <IIndicator> plug = _pluginService.AvailablePlugins[indicator]; Assembly pluginAssembly = Assembly.LoadFrom(plug.AssemblyPath); plug.Instance = (IIndicator)Activator.CreateInstance(pluginAssembly.GetType(plug.PlugType.ToString()), period); IIndicator rne = plug.Instance; _indicators.Add(rne); } if (Disposition == true) { _entryName = GetSortedName(_indicators); } else { _exitName = GetSortedName(_indicators); } }
public RandomStrategy(ref PluginServices pluginService, int maxind, int maxper) { _randomClass = new Random(); _indicators = new ArrayList(); _entryName = ""; _pluginService = pluginService; _maxIndicators = maxind; _maxPeriod = maxper; int indicators = _randomClass.Next(1, _maxIndicators + 1); for (int i = 0; i < indicators; i++) { int indicator = _randomClass.Next(1, _pluginService.AvailablePlugins.Count + 1) - 1; int period = _randomClass.Next(1, _maxPeriod); AvailablePlugin <IIndicator> plug = _pluginService.AvailablePlugins[indicator]; Assembly pluginAssembly = Assembly.LoadFrom(plug.AssemblyPath); plug.Instance = (IIndicator)Activator.CreateInstance(pluginAssembly.GetType(plug.PlugType.ToString()), period); IIndicator rne = plug.Instance; _indicators.Add(rne); } if (Disposition == true) { for (int i = 0; i < _indicators.Count; i++) { _entryName += ((IIndicator)_indicators[i]).GetName(); if (i != _indicators.Count - 1) { _entryName += ":"; } } } else { for (int i = 0; i < _indicators.Count; i++) { _exitName += ((IIndicator)_indicators[i]).GetName(); if (i != _indicators.Count - 1) { _exitName += ":"; } } } /* * if (_exitFlag == true) * { * _exitIndicators.Add(new StandardExit(_maximumHoldingPeriodBars, _profitTragetVolatilityUnits, _moneyManagementStopVolatilityUnits)); * * for (int i = 0; i < _exitIndicators.Count; i++) * { * ExitIndicatorName += ((IIndicator)_exitIndicators[i]).GetName(); * if (i != _exitIndicators.Count - 1) * ExitIndicatorName += ":"; * } * } */ }
private void AddPlugin(string filename) { //Create a new assembly from the plugin file we're adding.. Assembly pluginAssembly = Assembly.LoadFrom(filename); //Next we'll loop through all the Types found in the assembly foreach (Type pluginType in pluginAssembly.GetTypes()) { if (pluginType.IsPublic) //Only look at public types { //if (!pluginType.IsAbstract) //Only look at non-abstract types //{ //Gets a type object of the interface we need the plugins to match Type typeInterface = pluginType.GetInterface("MarketSage.Library.IIndicator", true); //Make sure the interface we want to use actually exists if (typeInterface != null) { //Create a new available plugin since the type implements the IPlugin interface AvailablePlugin <IIndicator> newPlugin = new AvailablePlugin <IIndicator>(); //Set the filename where we found it newPlugin.AssemblyPath = filename; newPlugin.PlugType = pluginType; newPlugin.Name = pluginType.Name; //Create a new instance and store the instance in the collection for later use //We could change this later on to not load an instance.. we have 2 options //1- Make one instance, and use it whenever we need it.. it's always there //2- Don't make an instance, and instead make an instance whenever we use it, then close it //For now we'll just make an instance of all the plugins //newPlugin.Instance = (IIndicator)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); //MessageBox.Show(pluginType.ToString()); //Set the Plugin's host to this class which inherited IPluginHost //NOTE: no need to d this here //newPlugin.Instance.Host = this; //Call the initialization sub of the plugin //newPlugin.Instance.Initialize(); //Add the new plugin to our collection here this._availablePlugins.Add(newPlugin); //cleanup a bit newPlugin = null; } typeInterface = null; //Mr. Clean //} } } pluginAssembly = null; //more cleanup }