public void Register(IMarketWatch mw, IStrategyRepositoryHelper repHelper) { if (mw != null) { marketWatch = mw; } if (repHelper != null) { helper = repHelper; } }
public void Register(ClientContext context) { IMarketWatch mw = context.MarketWatch; mw.MarketMeterProcess += new MarketUpdateEventHandler(updateMarketInfo); for (int i = 0; i < mw.InstrumentCount; i++) { Instrument inst = mw.GetInstrument(i); foreach (int tf in GeneralConfig.ValidTimeFrames) { currentVolatility.Add(inst.ToString() + tf.ToString(), 0); currentTrend.Add(inst.ToString() + tf.ToString(), 0); } } }
public ClientContext() { DefaultAccount = new Account(); PortfolioManager = new PortfolioManager(); GeneticEnvironment = new GeneticEnvironment(); MarketWatch = new MarketWatch(); MarketMeter = new MarketMeter(); PerformanceLogic = new PerformanceLogic(); PositionLogic = new PositionLogic(); StrategyRepository = new StrategyRepository(); IndicatorRepository = new IndicatorRepository(); PersistenceLogic = new PersistenceLogic(); PersistenceLogic.Register(this); //we need marketWatch.Instruments in strategyRep before connecting to server when loading report StrategyRepository.Register(MarketWatch, null); //we need this when loading performance PerformanceLogic.Register(this); }
public static Strategy LoadFromDescription(string desc, IndicatorRepository ir, IMarketWatch mw) { int rulesIndex = desc.IndexOf("Rules:"); int instIndex = desc.IndexOf("INST:"); string tfs = desc.Substring(3, instIndex - 3); string[] tfsList = tfs.Replace("(", "").Replace(")", "").Split(' '); Strategy result = new Strategy(ir); result.smallPeriod = int.Parse(tfsList[0]); result.defaultPeriod = int.Parse(tfsList[1]); result.largePeriod = int.Parse(tfsList[2]); string inst = desc.Substring(instIndex + 6, rulesIndex - instIndex - 7); result.defaultInstrument = mw.FindInstrument(inst); if (result.defaultInstrument == null) { throw new Exception("Cannot find strategy instrument"); } rulesIndex = desc.IndexOf('{', rulesIndex); string[] rules = desc.Substring(rulesIndex).Split('{'); foreach (string rule in rules) { if (rule.Length == 0) { continue; } string trule = rule.Substring(0, rule.Length - 1); BaseRule ruleObject = BaseRule.LoadFromDescription(trule); //ruleObject.SetPeriods(result.smallPeriod, result.defaultPeriod, result.largePeriod); result.AddRule(ruleObject); } return(result); }
public void Register(IMarketWatch mw) { //SLTP has to check before market strategy and genetic env are executed mw.AccountProcess += new MarketUpdateEventHandler(OnTick); }