The "Portfolio" variable allows you to get signals and orders programmatically using the script editor (global script). In this example, I will show you how to run a portfolio (get signals from a trading system), wait until the process ends then display the total number of orders. Steps: - Open the script editor by selecting "Tools" then "Script Editor" - Select "File -> New", and then type a name for your new script - Type the following code: PortfolioTask task = Portfolio.Run("Portfolio Category", "Portfolio Name"); while(!task.IsCompleted) // Wait/Sleep until task is completed { App.Main.Sleep(1000); } MessageBox.Show("Orders: " + task.Orders.Length); - Update "Portfolio Category" and "Portfolio Name" then click on "Execute" Note: - Set "" in the first parameter of the "Run" method if there is no category associated with your portfolio. - All information you need about the new orders are available in "task.Orders". There, you can the order type, the security name, the security last price, the number of shares to enter/exit, the approximate size of the order... Alternatively, you can use the delegate method of the "PortfolioTask" class to be notified when the portfolio rebalance process is completed. Example: PortfolioTask task = Portfolio.Run("Portfolio Category", "Portfolio Name"); task.Completed = PortfolioCompleted; #functions# public void PortfolioCompleted(Task task, EventArgs e) { PortfolioTask task1 = (PortfolioTask)task; MessageBox.Show("Orders: " + task1.Orders.Length); } In the above example, the "PortfolioCompleted" method is called when the portfolio rebalance process ends.
|
|