Click here to Login




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

Updated on 2010-06-01





Before continuing, please read the first part of the article here: Create a trading strategy using the money management tool - Part 1

After passing the last two tests (Is it in the portfolio? Is it in the pending orders list?), we check if there is market data for the security on the current date (The current date can be retrieved using the "Divers.CurrentDate" function).
After that, we must verify that the security passes our buy rules. To do that, we will have to parse the formula that will contain the buy rules, execute it, extract the result and then verify it.

Look at the following code:
MMParser parser = Data.ParseFormula("a = " + buyrule + ";");
TimeSeries a = parser.GetTimeSeries(symbol, "a");
if(a[0] == 1)
{
// Pass
}


In the first line, we create the formula parser, we then extract the appropriate time series in the second line and finally we verify that the current value of the time series is equal to 1.
Note that "a[0]" gets the current value of the time series "a", while "a[n]" gets the time series value N bars ago. Negative values of N reference future bars.

Once the security meets the rule's criteria, we create our order by calling the "Functions.AddLongPosition" function.
Functions.AddLongPosition(symbol, null);

If we don't specify the number of shares to buy, the trading software will automatically assign a number of shares that depends on the maximum number of positions allowed for the category (Long Positions) and the available amount of cash.
We set the Trading Order parameter (the second parameter) to null in order to use the default order type that was defined in the first screen of the trading system editor.

Instead of the previous line, you can type the following code to assign one or several stops to the long position:
MMPositionSettings settings = Functions.CreatePositionSettings("long");
settings.AddNBarsStop(10);
Functions.AddLongPosition(symbol, null, settings);


You can debug any money management script, using the "Divers.Output" method. The output or log is visible in the simulation report, under the "Details" tab.

A slightly more advanced version of this money management script can be downloaded here Long strategy created with the money management tool.











no comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Lock, Link and Undock your Charts
Posted 534 days ago

QuantShare
Previous Posts

Correlation of market indicators
Posted 3478 days ago

Backtesting Process
Posted 3492 days ago

Trading software new features
Posted 3498 days ago

Optimization of a trading system
Posted 3513 days ago


More Posts

Back







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 2019 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.