Click here to Login

Create a trading strategy using the money management tool - Part 1

Updated on 2010-05-25

Even if the simulator plug-in offers many features and can perfectly suits the need of the majority of traders and investors, it isn't sufficient to pundits and traders who want to create sophisticated simulations and backtests.

You may want to create several strategies in a single portfolio and then adjust the equity size of each strategy depending on how it has performed during the last quarter. Or you may want to hedge a long portfolio with some specific stocks or hedge your portfolio against inflation or a particular currency. There are a lot of advanced backtesting scenarios that simply could be performed using the basic simulator, they require the money management tool.

The money management plug-in is composed of five events. Each event is executed during a particular period. As an example, the OnStartSimulation event is executed just before the simulation starts, and the OnEndPeriod event is executed just after a period ends. In a daily timeframe, a period is a day.

Trader can type some line of codes for one or several of these events. The code will tell and instruct the trading software on the course of action to take. You can for example create a position sizing script by catching the OnNewPosition event and updating the number of share to buy or short.

The tool requires some practice and knowledge of the basic functions. In the rest of the article, we will show you how to write a money management script that creates a simple long trading system using buy and sell rules. The trading system will be exactly the same as the one you can create with the basic simulator. However, it will be created entirely by the money management tool and it will be the good example to show you the basic functions of the money management scripting language.

You can open the money management tool by selecting "Analysis" then "Advanced Money Management". Or you can update a trading system, select the money management tab and then create a new script.
Either way, you will end up with a form that looks like this.

Most of the code will be contained in the "OnEndPeriod" event.
This first thing to do is to loop through the symbols (stocks, futures or whatever asset you are trading) that you have or will specify in your trading system.

The list of symbols can be retrieved using the following line:
string[] symbols = Data.GetSymbols();

For each symbol, we must check if the portfolio contains a long position for this symbol and if there is a pending order to sell the security.

Portfolio.IsInPortfolio(symbol, true) -> Check whether a long position for the specified symbol exists in the portfolio

Portfolio.IsInPendingOrders(symbol, "sell") -> Check whether a sell pending order exists

At any time, you can click on CONTROL + SPACE to display the list of available variables. Besides, each time you type the opening parenthesis of a function, a tooltip displays a description of the function and enumerates the parameters the function accepts.

To be continued.

no comments (Log in)

QuantShare Blog
Search Posts

Recent Posts

Create Graphs using the Grid Tool
Posted 1291 days ago

Profile Graphs
Posted 1396 days ago

Previous Posts

Correlation of market indicators
Posted 5150 days ago

Backtesting Process
Posted 5164 days ago

Trading software new features
Posted 5170 days ago

Optimization of a trading system
Posted 5185 days ago

Short Index - Part 2
Posted 5220 days ago

More Posts


Create an account
Affiliate Program
Contact Us
Trading Forum
How-to Lessons
About Us
Terms of Use

Copyright 2024
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
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.