List<ToolStripItem> CreateMnisForScriptContexts(Strategy strategy) { var ret = new List<ToolStripItem>(); foreach (string scriptContextName in strategy.ScriptContextsByName.Keys) { var mni = new ToolStripMenuItem(scriptContextName, null, this.mniStrategyOpenWithScriptContext_Click, "mni" + scriptContextName); ret.Add(mni); } return ret; }
ChartFormManager chartCreateShowPopulateSelectorsSlidersFromStrategy(Strategy strategy) { ChartFormManager chartFormManager = new ChartFormManager(); chartFormManager.InitializeWithStrategy(this.mainForm, strategy); this.mainForm.GuiDataSnapshot.ChartFormManagers.Add(chartFormManager.DataSnapshot.ChartSerno, chartFormManager); chartFormManager.ChartFormShow(); chartFormManager.StrategyCompileActivatePopulateSlidersShow(); return chartFormManager; }
void syncFolderStrategySelectedFromRowIndexClicked(int itemIndexSelected) { string folder = this.tree.SelectedObject as string; if (folder != null) { this.FolderSelected = folder; this.StrategySelected = null; return; } Strategy strategy = this.tree.SelectedObject as Strategy; if (strategy == null) { string msg = "this.tree.SelectedObject is not a Strategy and wasn't a Folder either"; Assembler.PopupException(msg); return; } this.StrategySelected = strategy; this.FolderSelected = strategy.StoredInFolderRelName; }
public void Initialize(Strategy strategy) { this.Strategy = strategy; //this.InitializeParameterSetMenuItemsFromStrategyScriptContexts(); base.SuspendLayout(); foreach (UserControl control in base.Controls) control.Dispose(); base.Controls.Clear(); try { if (this.Strategy == null) return; if (this.Strategy.Script == null) return; foreach (ScriptParameter parameter in this.Strategy.ScriptParametersMergedWithCurrentContext.Values) { SliderComboControl slider = this.SliderComboFactory(parameter); base.Controls.Add(slider); } } finally { base.Height = this.PreferredHeight; base.ResumeLayout(true); } }
public void StrategyDelete(Strategy strategy) { string currentJsonAbspath = strategy.StoredInJsonAbspath; string msig = "StrategyDelete(" + currentJsonAbspath + "): "; this.currentJsonAbspathCheckThrow(strategy, msig); try { File.Delete(currentJsonAbspath); } catch (Exception e) { string msg = "Permission denied in [" + strategy.StoredInJsonAbspath + "]?"; throw new Exception(msig + msg, e); } this.StrategiesInFolders[strategy.StoredInFolderRelName].Remove(strategy); }
public void StrategyAdd(Strategy strategy, string folderName) { string msig = "StrategyAdd(" + strategy.Name + ", " + folderName + "): "; strategy.StoredInJsonAbspath = this.StrategyJsonAbsNameFor(strategy, null, folderName); string path = this.AbsPath + folderName + strategy.Name; if (File.Exists(path)) { string msg = "StrategyFolder already saved as [" + path + "]"; throw new Exception(msig + msg); } var strategyFound = this.LookupByName(strategy.Name); if (strategyFound != null && strategyFound.StoredInJsonAbspath.ToUpper() == folderName.ToUpper()) { string msg = "StrategyFolder is not saved as [" + path + "] but exists in this.StrategiesInFolders as " + "[" + strategyFound.StoredInJsonAbspath + Path.DirectorySeparatorChar + strategyFound.Name + "]"; throw new Exception(msig + msg); } try { this.FolderAdd(folderName, false); if (this.StrategiesInFolders.ContainsKey(folderName) == false) { this.StrategiesInFolders.Add(folderName, new List<Strategy>()); } if (this.StrategiesInFolders[folderName].Contains(strategy) == false) { this.StrategiesInFolders[folderName].Add(strategy); } this.StrategySave(strategy, false); } catch (Exception e) { string msg = "Permission denied in [" + strategy.StoredInJsonAbspath + "]?"; throw new Exception(msig + msg, e); } }
public void CancelStrategyOrders(string account, Strategy strategy, string symbol, BarScaleInterval dataScale) { try { Exception e = new Exception("just for call stack trace"); throw e; } catch (Exception ex) { string msg = "I won't cancel any orders; reconsider application architecture"; Assembler.PopupException(msg, ex); } }
public string StrategyJsonAbsNameFor(Strategy strategy, string newStrategyName = null, string newFolderName = null) { string jsonCurrentOrRenamed = (newStrategyName == null) ? strategy.Name : newStrategyName; string folderCurrentOrRenamed = (newFolderName == null) ? strategy.StoredInFolderRelName : newFolderName; return Path.Combine(this.FolderAbsPathFor(folderCurrentOrRenamed), jsonCurrentOrRenamed + ".json"); }
public void StrategyRename(Strategy strategy, string strategyNameTo) { string currentJsonAbspath = strategy.StoredInJsonAbspath; string msig = "StrategyRename(" + currentJsonAbspath + "=>" + strategyNameTo + "): "; this.currentJsonAbspathCheckThrow(strategy, msig); this.StrategyRenameCheckThrow(strategy, strategyNameTo); string newJsonAbspath = this.StrategyJsonAbsNameFor(strategy, strategyNameTo); try { File.Move(currentJsonAbspath, newJsonAbspath); } catch (Exception e) { string msg = "Permission denied in [" + strategy.StoredInJsonAbspath + "]?"; throw new Exception(msig + msg, e); } strategy.Name = strategyNameTo; strategy.StoredInJsonAbspath = newJsonAbspath; }
public bool StrategyRenameIsLikelyToSucceed(Strategy strategy, string strategyNameTo) { try { this.StrategyRenameCheckThrow(strategy, strategyNameTo); } catch (Exception e) { return false; } return true; }
public void Initialize(ChartShadow chartShadow, Strategy strategy, OrderProcessor orderProcessor, IStatusReporter statusReporter) { string msg = " at this time, FOR SURE this.Bars==null, strategy.Script?=null"; this.ChartShadow = chartShadow; this.Strategy = strategy; this.OrderProcessor = orderProcessor; this.StatusReporter = statusReporter; if (this.Strategy != null) { if (this.Bars != null) { this.Strategy.ScriptContextCurrent.Symbol = this.Bars.Symbol; this.Strategy.ScriptContextCurrent.DataSourceName = this.DataSource.Name; } if (this.Strategy.Script == null) { msg = "I will be compiling this.Strategy.Script when in ChartFormsManager.StrategyCompileActivatePopulateSliders()"; //} else if (this.Bars == null) { // msg = "InitializeStrategyAfterDeserialization will Script.Initialize(this) later with bars"; } else { this.Strategy.Script.Initialize(this); } } this.ExecutionDataSnapshot.Initialize(); // Executor.Bars are NULL in ScriptExecutor.ctor() and NOT NULL in SetBars //this.Performance.Initialize(); this.MarketSimStreaming.Initialize(); }
protected ScriptExecutor(ChartShadow chartShadow, Strategy strategy, OrderProcessor orderProcessor, IStatusReporter statusReporter) : this() { this.Initialize(chartShadow, strategy, orderProcessor, statusReporter); }
public Alert(Bar bar, double qty, double priceScript, string signalName, Direction direction, MarketLimitStop marketLimitStop, OrderSpreadSide orderSpreadSide, Strategy strategy) : this() { if (direction == Direction.Unknown) { string msg = "ALERT_CTOR_DIRECTION_MUST_NOT_BE_UNKNOWN: when creating an Alert, direction parameter can't be null"; throw new Exception(msg); } if (bar == null) { string msg = "ALERT_CTOR_BAR_MUST_NOT_BE_NULL: when creating an Alert, bar parameter can't be null"; throw new Exception(msg); } if (bar.ParentBars == null) { string msg = "ALERT_CTOR_PARENT_BARS_MUST_NOT_BE_NULL: when creating an Alert, bar.ParentBars can't be null"; throw new Exception(msg); } this.Bars = bar.ParentBars; this.PlacedBar = bar; this.PlacedBarIndex = bar.ParentBarsIndex; this.Symbol = bar.Symbol; this.BarsScaleInterval = this.Bars.ScaleInterval; if (this.Bars.SymbolInfo != null) { SymbolInfo symbolInfo = this.Bars.SymbolInfo; this.SymbolClass = (string.IsNullOrEmpty(symbolInfo.SymbolClass) == false) ? symbolInfo.SymbolClass : "UNKNOWN_CLASS"; this.MarketOrderAs = symbolInfo.MarketOrderAs; } this.AccountNumber = "UNKNOWN_ACCOUNT"; if (this.DataSource.BrokerProvider != null && this.DataSource.BrokerProvider.AccountAutoPropagate != null && string.IsNullOrEmpty(this.Bars.DataSource.BrokerProvider.AccountAutoPropagate.AccountNumber) != false) { this.AccountNumber = this.Bars.DataSource.BrokerProvider.AccountAutoPropagate.AccountNumber; } this.Qty = qty; this.PriceScript = priceScript; this.SignalName = signalName; this.Direction = direction; this.MarketLimitStop = marketLimitStop; this.OrderSpreadSide = orderSpreadSide; this.Strategy = strategy; if (this.Strategy != null) { this.StrategyID = this.Strategy.Guid; this.StrategyName = this.Strategy.Name; } if (this.Strategy.Script != null) { string msg = "Looks like a manual Order submitted from the Chart"; return; } }
public StrategyEventArgs(string folder, Strategy strategy) { this.Folder = folder; this.Strategy = strategy; }
public void SelectStrategy(Strategy strategy) { if (strategy == null) { string msg = "why would you pass strategy[" + strategy+ "]=null???"; Assembler.PopupException(msg); return; } if (Assembler.InstanceInitialized.RepositoryDllJsonStrategy.AllStrategiesAvailable.Contains(strategy) == false) { string msg = "you may have removed {strategy[" + strategy+ "]" + "from tree before application restart" + ", but an open chart with this strategy became Active and requests SelectStrategy()"; Assembler.PopupException(msg); return; } if (this.tree.IsExpanded(strategy.StoredInFolderRelName) == false) { this.tree.Expand(strategy.StoredInFolderRelName); this.tree_Expanded(this, new TreeBranchExpandedEventArgs(strategy.StoredInFolderRelName, null)); } this.tree.EnsureModelVisible(strategy); this.tree.SelectObject(strategy); //int index = this.tree.IndexOf(strategy); //this.tree.SelectedIndex = index; this.StrategySelected = strategy; }
public void StrategyMoveToFolder(Strategy strategy, string folderTo) { string currentJsonAbspath = strategy.StoredInJsonAbspath; string folderFrom = strategy.StoredInFolderRelName; string msig = "StrategyMoveToFolder(" + currentJsonAbspath + "=>" + folderTo + "): "; string newJsonAbspath = this.StrategyJsonAbsNameFor(strategy, null, folderTo); strategy.StoredInJsonAbspath = newJsonAbspath; string strategyName = strategy.Name; strategy.Name = "$$$DUMMY_STRATEGY_NAME"; strategy.Name = this.StrategyRenameModifyNameTillNoException(strategy, strategyName); strategy.StoredInJsonAbspath = this.StrategyJsonAbsNameFor(strategy, null, folderTo); //if (File.Exists(newJsonAbspath)) { // string msg = "File.Exists(newJsonAbspath=" + newJsonAbspath + ") = true"; // throw new Exception(msig + msg); //} try { //this.currentJsonAbspathCheckThrow(strategy, msig, strategy.Name); File.Move(currentJsonAbspath, strategy.StoredInJsonAbspath); } catch (Exception e) { strategy.StoredInJsonAbspath = currentJsonAbspath; strategy.Name = strategyName; string msg = "Permission denied in [" + strategy.StoredInJsonAbspath + "]?"; throw new Exception(msig + msg, e); } StrategiesInFolders[folderTo].Add(strategy); StrategiesInFolders[folderFrom].Remove(strategy); }
public string StrategyRenameModifyNameTillNoException(Strategy strategy, string strategyNameTo) { if (StrategyRenameIsLikelyToSucceed(strategy, strategyNameTo) == true) { return strategyNameTo; } int limit = 10; Exception lastException = null; for (int i = 1; i <= limit; i++) { string ret2 = strategyNameTo + i; //if (StrategyRenameIsLikelyToSucceed(strategy, strategyNameTo) == true) return ret2; try { this.StrategyRenameCheckThrow(strategy, ret2); } catch (Exception e) { lastException = e; continue; } return ret2; } //string msg = "strategies [" + folderNameTo + "] ... [" + (folderNameTo + limit) + "] already exist, can't generate name"; //throw new Exception(msg, lastException); throw lastException; }
protected Dictionary<string, List<Strategy>> StrategiesScanFolders() { var ret = new Dictionary<string, List<Strategy>>(); string[] directories = Directory.GetDirectories(this.AbsPath); foreach (string subfolderAbsPath in directories) { string subfolderOnly = subfolderAbsPath.Substring(this.AbsPath.Length); if (ret.ContainsKey(subfolderOnly) == false) { ret.Add(subfolderOnly, new List<Strategy>()); } string[] jsonFiles = Directory.GetFiles(subfolderAbsPath, "*.json"); foreach (string strategyJsonAbsFile in jsonFiles) { try { Strategy strategy = this.StrategyDeserializeFromJsonFile(strategyJsonAbsFile); strategy.StoredInJsonAbspath = strategyJsonAbsFile; ret[subfolderOnly].Add(strategy); } catch (Exception e) { string msg = "STRATEGY_unJSON_FAILED: StrategyDeserializeFromJsonFile(" + strategyJsonAbsFile + ")"; Assembler.PopupException(msg, e); var sample = new Strategy("sampleStrategy"); sample.ScriptSourceCode = "namespace sample.Strategies {\r\n" + "public class MyScript : Script {\r\n" + "public override void ExecuteOnNewQuote(Quote quote) {\r\n" + "log(\"ExecuteOnNewQuote(): [\" + quote.ToString() + \"]\");\r\n" + "}\r\n" + "}\r\n" + "}\r\n"; this.StrategyAdd(sample, "sampleFolder"); } } } return ret; }
public void StrategyRenameCheckThrow(Strategy strategy, string strategyNameTo) { string msig = "StrategyRepository.StrategyRenameCheckThrow([" + strategy.Name + "]=>[" + strategyNameTo + "]): "; if (String.IsNullOrWhiteSpace(strategyNameTo)) { string msg = "Destination strategyNameTo IsNullOrWhiteSpace"; throw new Exception(msig + msg); } var strategyNamesInThisFolder = new List<string>(); foreach (Strategy strategySibling in this.StrategiesInFolders[strategy.StoredInFolderRelName]) { strategyNamesInThisFolder.Add(strategySibling.Name); } if (strategyNamesInThisFolder.Contains(strategyNameTo)) { string msg = "strategyNameTo is alreadyin the this.StrategiesInFolders[" + strategy.StoredInFolderRelName + "] list; add '1' at the end"; throw new Exception(msig + msg); } string newJsonAbspath = this.StrategyJsonAbsNameFor(strategy, strategyNameTo); if (File.Exists(newJsonAbspath)) { string msg = "File.Exists(newJsonAbspath=" + newJsonAbspath + ") = true"; throw new Exception(msig + msg); } }
protected Dictionary<Assembly, List<Script>> StrategiesScanDllsInitDeserialized(string dataOrStartupPath) { ScriptRepository repo = new ScriptRepository(); repo.InitializeAndScan(dataOrStartupPath); Dictionary<Assembly, List<Script>> ret = repo.CloneableInstancesByAssemblies; foreach (Assembly assembly in ret.Keys) { List<Script> cloneableInstancesForAssembly = ret[assembly]; // WONT_BE_EMPTY if (cloneableInstancesForAssembly.Count == 0) continue; string assemblyName = Path.GetFileName(assembly.Location); if (this.StrategiesInFolders.ContainsKey(assemblyName) == false) { //this.StrategiesInFolders.Add(assemblyName, new List<Strategy>()); this.FolderAdd(assemblyName, false); //} else { // string msg = "StrategyRepository::StrategiesScanDllsInitDeserialized(" + dataOrStartupPath + "):" // + " Assembly [" + assembly.Location + "] wasn't added to this.StrategiesInFolders" // + " because already existed among AllFoldersAvailable[" + AllFoldersAvailable + "]"; // Assembler.Constructed.StatusReporter.PopupException(msg); // continue; } List<Strategy> strategiesForAssmbly = this.StrategiesInFolders[assemblyName]; foreach (Script script in cloneableInstancesForAssembly) { string scriptName = script.GetType().Name; Strategy strategyFound = this.LookupByName(scriptName, assemblyName); if (strategyFound == null) { strategyFound = new Strategy(scriptName); strategyFound.StoredInJsonAbspath = Path.Combine(this.FolderAbsPathFor(assemblyName), scriptName + ".json"); strategiesForAssmbly.Add(strategyFound); } strategyFound.Script = script; strategyFound.DllPathIfNoSourceCode = assembly.Location; this.StrategySave(strategyFound); } } return ret; }
private void currentJsonAbspathCheckThrow(Strategy strategy, string msig, string renamingTo = null) { if (renamingTo == null && strategy.StoredInJsonAbspath != this.StrategyJsonAbsNameFor(strategy)) { string msg = "folder.JsonAbsFile[" + strategy.StoredInJsonAbspath + "] != " + "this.StrategyJsonAbsNameFor(" + strategy.Name + ")[" + this.StrategyJsonAbsNameFor(strategy) + "]"; throw new Exception(msig + msg); } if (strategy.ActivatedFromDll == true) { string msg = "Adjust your GUI so that folder.ActivatedFromDll is not rename-able and its folder"; throw new Exception(msig + msg); } if (this.StrategiesInFolders.ContainsKey(strategy.StoredInFolderRelName) == false) { string msg = "this.StrategiesInFolders should contain Folder[" + strategy.StoredInFolderRelName + "] before manipulating; re-read by StrategiesScanFoldersDlls()?"; throw new Exception(msig + msg); } if (this.StrategiesInFolders[strategy.StoredInFolderRelName].Contains(strategy) == false) { string msg = "this.StrategiesInFolders[" + strategy.StoredInFolderRelName + "] should contain StrategyFolder[" + strategy.Name + "] before manipulating; re-read by StrategiesScanFoldersDlls()?"; throw new Exception(msig + msg); } string currentJsonAbspath = this.StrategyJsonAbsNameFor(strategy, renamingTo); if (File.Exists(currentJsonAbspath) == false) { string msg = "File.Exists(currentJsonAbspath=" + currentJsonAbspath + ") = false"; throw new Exception(msig + msg); } }
public void StrategySerializeToJsonFile(Strategy strategy, string strategyJsonAbsFile) { string json = JsonConvert.SerializeObject(strategy, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects}); File.WriteAllText(strategyJsonAbsFile, json); }
public Strategy StrategyDuplicate(Strategy strategy, string strategyNameUserTyped = "") { //string nameToRestore = strategy.Name; Strategy strategyShallowCopy = strategy.Clone(); //strategyShallowCopy.Name = "$$$STRATEGY_DUNNY_NAME_TO_BE_RENAMED"; //strategyShallowCopy.Name = this.StrategyRenameModifyNameTillNoException(strategyShallowCopy, strategy.Name); if (string.IsNullOrEmpty(strategyNameUserTyped)) strategyNameUserTyped = strategy.Name; strategyShallowCopy.Name = this.StrategyRenameModifyNameTillNoException(strategyShallowCopy, strategyNameUserTyped); this.StrategySave(strategyShallowCopy, true, true); Strategy strategyDeepCopy = this.StrategyDeserializeFromJsonFile(strategyShallowCopy.StoredInJsonAbspath); this.StrategyAdd(strategyDeepCopy, strategyDeepCopy.StoredInFolderRelName); //strategy.Name = nameToRestore; return strategyDeepCopy; }
public void StrategySave(Strategy strategy, bool lastModIsNow = true, bool creating = false) { if (strategy.HasChartOnly) { throw new Exception("CREATE_CHART_CONTEXT_AND_SERIALIZE_IT_IN_CHART_FORM_DATASNAPSHOT"); return; //stub for a strategy-less chart } //if (lastModIsNow) strategy.LastModified = DateTime.Now; string strategyJsonAbsFile = this.StrategyJsonAbsNameFor(strategy); try { this.StrategySerializeToJsonFile(strategy, strategy.StoredInJsonAbspath); } catch (Exception e) { string msg = "STRATEGY_SERIALIZE_JSON_FAILED: StrategySerializeToJsonFile(" + strategyJsonAbsFile + ")"; throw new Exception(msg, e); } if (creating == false && this.LookupByName(strategy.Name) == null) { throw new Exception("StrategyFolder MUST have been already included in internal dictionnaries"); //this.AllStrategiesAvailable.Add(strategy); } }
public void InitializeWithStrategy(MainForm mainForm, Strategy strategy) { string msig = "ChartFormsManager.InitializeWithStrategy(" + strategy + "): "; this.MainForm = mainForm; this.Strategy = strategy; //this.Executor = new ScriptExecutor(mainForm.Assembler, this.Strategy); if (this.DataSnapshot.ChartSerno == -1) { int charSernoNext = mainForm.GuiDataSnapshot.ChartSernoNextAvailable; bool createdNewFile = this.DataSnapshotSerializer.Initialize(Assembler.InstanceInitialized.AppDataPath, "ChartFormDataSnapshot-" + charSernoNext + ".json", "Workspaces", Assembler.InstanceInitialized.AssemblerDataSnapshot.CurrentWorkspaceName, true, true); this.DataSnapshot = this.DataSnapshotSerializer.Deserialize(); this.DataSnapshot.ChartSerno = charSernoNext; } this.DataSnapshot.StrategyGuidJsonCheck = strategy.Guid.ToString(); this.DataSnapshotSerializer.Serialize(); if (this.ChartForm == null) { // 1. create ChartForm.Chart.Renderer this.ChartForm = new ChartForm(this); this.ChartForm.FormClosed += this.MainForm.MainFormEventManager.ChartForm_FormClosed; // 2. create Executor with Renderer this.Executor.Initialize(this.ChartForm.ChartControl as ChartShadow, this.Strategy, Assembler.InstanceInitialized.OrderProcessor, Assembler.InstanceInitialized.StatusReporter); // 3. initialize Chart with Executor (I don't know why it should be so crazy) //this.ChartForm.Chart.Initialize(this.Executor); //ScriptExecutor.DataSource: you should not access DataSource before you've set Bars //this.ChartForm.ChartStreamingConsumer.Initialize(this); this.scriptEditorFormFactory = new ScriptEditorFormFactory(this, Assembler.InstanceInitialized.RepositoryDllJsonStrategy); this.ChartForm.CtxReporters.Items.AddRange(this.ReportersFormsManager.MenuItemsProvider.MenuItems.ToArray()); this.EventManager = new ChartFormEventManager(this); this.ChartForm.AttachEventsToChartFormsManager(); } else { // we had chart already opened with bars loaded; then we clicked on a strategy and we want strategy to be backtested on these bars this.Executor.Initialize(this.ChartForm.ChartControl as ChartShadow, this.Strategy, Assembler.InstanceInitialized.OrderProcessor, Assembler.InstanceInitialized.StatusReporter); if (this.ChartForm.CtxReporters.Items.Count == 0) { this.ChartForm.CtxReporters.Items.AddRange(this.ReportersFormsManager.MenuItemsProvider.MenuItems.ToArray()); } } if (this.DataSnapshot.ChartSettings == null) { this.DataSnapshot.ChartSettings = this.ChartForm.ChartControl.ChartSettings; // opening from Datasource => save } else { this.ChartForm.ChartControl.ChartSettings = this.DataSnapshot.ChartSettings; // otherwize JustDeserialized => propagate this.ChartForm.ChartControl.PropagateSettingSplitterDistancePriceVsVolume(); } //this.ChartForm.CtxReporters.Enabled = true; this.ChartForm.DdbReporters.Enabled = true; this.ChartForm.DdbStrategy.Enabled = true; this.ChartForm.DdbBacktest.Enabled = true; this.ChartForm.MniShowSourceCodeEditor.Enabled = !this.Strategy.ActivatedFromDll; try { //I'm here via Persist.Deserialize() (=> Reporters haven't been restored yet => backtest should be postponed); will backtest in InitializeStrategyAfterDeserialization this.PopulateSelectorsFromCurrentChartOrScriptContextLoadBarsSaveBacktestIfStrategy(msig, true, true); } catch (Exception ex) { string msg = "PopulateCurrentChartOrScriptContext(): "; Assembler.PopupException(msg + msig, ex); } }
void mniltbStrategyCreate_UserTyped(object sender, LabeledTextBoxUserTypedArgs e) { string msig = "StrategiesTree.mniltbStrategyCreate_UserTyped(): "; if (this.FolderSelected == null) { string msg = "this.FolderSelected==null; please set mniFolderCreate.Enabled=false when right-clicked not on the folder"; statusReporter.PopupException(new Exception(msig + msg)); return; } Strategy strategyNew = null; try { string strategyNameGenerated = e.StringUserTyped; if (string.IsNullOrEmpty(strategyNameGenerated)) strategyNameGenerated = strategyRepository.GenerateStrategyName(); strategyNew = new Strategy(strategyNameGenerated); } catch (Exception ex) { statusReporter.PopupException(ex); return; } strategyRepository.StrategyAdd(strategyNew, this.FolderSelected); this.tree.RebuildAll(true); this.tree.SelectObject(strategyNew, true); // does it work?? this.StrategySelected = strategyNew; //var olvStrategy = this.treeListView.FindItemWithText(strategyNew.Name, true, 0); // finds first occurency, not what I've inserted! //var olvStrategy = this.tree.ModelToItem(strategyNew); //this.tree.EditSubItem(olvStrategy as OLVListItem, 0); this.tree.Expand(this.FolderSelected); e.RootHandlerShouldCloseParentContextMenuStrip = true; this.RaiseOnStrategyCreated(msig); }