/// <summary> /// set fields to config from xml /// </summary> void ConfigLoad(string path, string file) { // load config from xml ConfigXml22 xml = new ConfigXml22(path, file); xml.Load(); // set fields to xml values configBearContValue = xml.BearContValue; configBearInitType = xml.BearInitType; configBearInitValue = xml.BearInitValue; configBearRangeMax = xml.BearRangeMax; configBearRangeMin = xml.BearRangeMin; configBullContValue = xml.BullContValue; configBullInitType = xml.BullInitType; configBullInitValue = xml.BullInitValue; configBullRangeMax = xml.BullRangeMax; configBullRangeMin = xml.BullRangeMin; configCloseOption = (EmCloses)Enum.Parse(typeof(EmCloses), xml.CloseOption); configOpenOption = (EmOpens)Enum.Parse(typeof(EmOpens), xml.OpenOption); // calculate bear/bull min/max RangeInit(); // update configLoaded configLoaded = true; }
/// <summary> /// reset form to config /// </summary> void OnConfigReset() { // load config from xml config.Load(); // set form values from xml FormApplyXml(config); // flag apply button OnApplyNeeded(false); // flag save button OnSaveNeeded(false); }
/// <summary> /// loads config from file, apply to form, sync chart, reload chart /// </summary> void OnConfigLoad() { // update status message StatusMessage("Loading ...", Color.DarkRed); // set initial directory dialogOpen.InitialDirectory = configPath; // return if no file selected if (dialogOpen.ShowDialog() != DialogResult.OK) { // reset status message StatusMessageReady(); // return return; } try { // get file from dialog string filename = dialogOpen.FileName; string path = Path.GetDirectoryName(filename) + @"\"; string file = Path.GetFileName(filename); // get new xml object ConfigXml22 xml = new ConfigXml22(path, file); // load config from xml xml.Load(); // set form values from xml FormApplyXml(xml); // update status message StatusMessage(string.Concat("Loaded ", file), Color.DarkRed); // flag apply button OnApplyNeeded(true); // flag save button OnSaveNeeded(true); } catch (Exception) { // error handling StatusMessage("Error! Please click [apply].", Color.DarkRed); } }
/// methods /// <summary> /// sets data-box values /// </summary> void DataBoxInit() { // only fire for EmBars dataBox = (Bars.BarsType.DisplayName.Contains("EmBars")) ? true : false; if (dataBox) { // local variables int configId = BarsPeriod.Value; string file = string.Format(@"EmBars-Config-{0}.xml", configId); string path = NinjaTrader.Cbi.Core.UserDataDir + @"bin\Custom\"; Font font = new Font("Courier New", dataBoxFontSize, dataBoxFontStyle); // load config from xml ConfigXml22 xml = new ConfigXml22(path, file); xml.Load(); // set fields to xml values int emBearContValue = xml.BearContValue; int emBearInitType = xml.BearInitType; int emBearInitValue = xml.BearInitValue; int emBearRangeMax = xml.BearRangeMax; int emBearRangeMin = xml.BearRangeMin; int emBullContValue = xml.BullContValue; int emBullInitType = xml.BullInitType; int emBullInitValue = xml.BullInitValue; int emBullRangeMax = xml.BullRangeMax; int emBullRangeMin = xml.BullRangeMin; string emCloseOption = xml.CloseOption; string emOpenOption = xml.OpenOption; // build rows string dbmMin = string.Format("Min {0}{1} | {2}{3}", emBullRangeMin, (emBullInitType == -1) ? "*" : " ", emBearRangeMin, (emBearInitType == -1) ? "*" : ""); string dbmMax = string.Format("Max {0}{1} | {2}{3}", emBullRangeMax, (emBullInitType == 1) ? "*" : " ", emBearRangeMax, (emBearInitType == 1) ? "*" : ""); string dbmInit = string.Format("Init {0}{1}{2} | {3}{4}{5}", (emBullInitValue >= 0) ? " " : "", emBullInitValue, (emBullInitType == 0) ? "*" : " ", (emBearInitValue >= 0) ? " " : "", emBearInitValue, (emBearInitType == 0) ? "*" : ""); string dbmCont = string.Format("Cont {0}{1} | {2}{3}", (emBullContValue >= 0) ? " " : "", emBullContValue, (emBearContValue >= 0) ? " " : "", emBearContValue); // build message box string dataBoxMsg = string.Format("EmBars {0}\r\nConfig #{1}\r\n{2}\r\n{3}\r\n{4}\r\n{5}\r\nOpen {6}\r\nClose {7}", Bars.Instrument.FullName, configId.ToString(), dbmMin, dbmMax, dbmInit, dbmCont, emOpenOption, emCloseOption); // draw text-box DrawTextFixed("EmBarsDataBox", dataBoxMsg, dataBoxPosition, dataBoxFontColor, font, dataBoxBorderColor, dataBoxBackColor, dataBoxOpacity); // flag data-box loaded dataBoxLoaded = true; } }