// To use this function, strategy_templates must contain exactly 3 strategy ids corresponding to 3:00-4:30, 3:30-4:30 and 4:30-6:30 public static void rollTimingStrategy(int[] strategy_templates, int new_contract_id, string new_maturity_tag, string suffix = "") { string[] model_tags = new string[] { "BT_1_" + new_maturity_tag + "_DST", "BT_2_" + new_maturity_tag + "_DST", "BT_3_" + new_maturity_tag + "_DST" }; string[] model_descriptions = new string[] { "Brent " + new_maturity_tag + " 3:00pm - 4:30pm DST", "Brent " + new_maturity_tag + " 3:30pm - 4:30pm DST", "Brent " + new_maturity_tag + " 4:30pm - 6:30pm DST" }; string[] strategy_tags = new string[] { "BT_1_" + new_maturity_tag + "_DST", "BT_2_" + new_maturity_tag + "_DST", "BT_3_" + new_maturity_tag + "_DST" }; string[] strategy_descriptions = new string[] { "Brent " + new_maturity_tag + " 3:00pm - 4:30pm DST", "Brent " + new_maturity_tag + " 3:30pm - 4:30pm DST", "Brent " + new_maturity_tag + " 4:30pm - 6:30pm DST" }; if (suffix != "") { for (int i = 0; i < 3; ++i) { strategy_tags[i] += "_" + suffix; strategy_descriptions[i] += " " + suffix; } } for (int i = 0; i < 3; ++i) { List <string> infos = db.getStrategyInfo(strategy_templates[i]); string strategyClass = infos[0]; XmlDocument xml = new XmlDocument(); xml.LoadXml(infos[1]); XmlNode xn1 = xml.SelectSingleNode("/Config"); XmlNode common = xn1.SelectSingleNode("Common"); XmlNode blockOrder = xn1.SelectSingleNode("BlockOrder"); XmlNode stopOrderTemplate = blockOrder.SelectSingleNode("StopOrderTemplate"); int template_model_id = int.Parse(xn1["Model"].InnerText); XmlDocument modelXml = new XmlDocument(); modelXml.LoadXml(db.getModel(template_model_id)); XmlNode mn1 = modelXml.SelectSingleNode("/Parameters"); XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; settings.OmitXmlDeclaration = true; //Write Model Xml StringBuilder sm = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(sm, settings)) { //writer.WriteStartDocument(); writer.WriteStartElement("Parameters"); writer.WriteElementString("Asset", new_contract_id.ToString()); writer.WriteElementString("EntryTime", mn1["EntryTime"].InnerText); writer.WriteElementString("ExitTime", mn1["ExitTime"].InnerText); writer.WriteElementString("LongOrShort", mn1["LongOrShort"].InnerText); writer.WriteElementString("LookbackPeriod", mn1["LookbackPeriod"].InnerText); writer.WriteElementString("ProfitRatio", mn1["ProfitRatio"].InnerText); writer.WriteElementString("StopRatio", mn1["StopRatio"].InnerText); writer.WriteEndElement(); //writer.WriteEndDocument(); } string newModelXml = sm.ToString(); int newModelID = db.addModel(new_contract_id, model_tags[i], newModelXml, model_descriptions[i]); StringBuilder sb = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(sb, settings)) { //writer.WriteStartDocument(); writer.WriteStartElement("Config"); writer.WriteStartElement("Common"); writer.WriteElementString("TimeZone", common["TimeZone"].InnerText); writer.WriteElementString("StartTime", common["StartTime"].InnerText); writer.WriteElementString("EndTime", common["EndTime"].InnerText); writer.WriteElementString("Calendar", common["Calendar"].InnerText); writer.WriteEndElement(); writer.WriteElementString("Model", newModelID.ToString()); writer.WriteElementString("Quantity", xn1["Quantity"].InnerText); writer.WriteElementString("EntryPreOffset", xn1["EntryPreOffset"].InnerText); writer.WriteElementString("EntryPostOffset", xn1["EntryPostOffset"].InnerText); writer.WriteElementString("ExitPreOffset", xn1["ExitPreOffset"].InnerText); writer.WriteElementString("ExitPostOffset", xn1["ExitPostOffset"].InnerText); writer.WriteStartElement("BlockOrder"); writer.WriteElementString("UnitSize", blockOrder["UnitSize"].InnerText); writer.WriteElementString("MaxBlockSize", blockOrder["MaxBlockSize"].InnerText); writer.WriteElementString("MaxNumberOfOrders", blockOrder["MaxNumberOfOrders"].InnerText); writer.WriteStartElement("StopOrderTemplate"); writer.WriteElementString("OrderType", stopOrderTemplate["OrderType"].InnerText); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); //writer.WriteEndDocument(); } string newStrategyXml = sb.ToString(); db.addStrategy(strategyClass, strategy_tags[i], newStrategyXml, strategy_descriptions[i]); } }