Click here to Login





How to get trading orders from a portfolio programmatically

Updated on 2012-03-10 03:54:23

Share |

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.











one review (Log in)







Other how-to articles




How to generate buy/sell signals from a trading system





How to add trades from one portfolio to another one





How to download a trading item from the Sharing Server





How to hide a trading indicator from a particular time frame





How to set order type of a trading system programmatically





How to import trading data from CSV files





How to import trading items from other accounts





How to hide stock data outside of regular trading hours





How to import trades into a portfolio







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.