#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

Updated on 2019-04-01

If you are not familiar with the QS programming language, we strongly suggest you take a look at this article:
QuantShare Programming Language Tutorial

You also need to learn how to create trading strategies before continuing with this tutorial:
The Ultimate Guide to Create Trading Systems in QuantShare

Dynamic Position Sizing

By default, a trading system will allocate an equal amount to each position. The amount is calculated by taking the strategy equity and dividing it by the maximum number of allowed positions.

If you have 100,000 USD in your portfolio and you set up 5 as number of positions, then QuantShare will buy 20,000 USD worth of shares for the new position.

You can change this logic using a single line in your trading system QS language formula. All you need to do is use the "SetSimPosSize" function and define how you want QuantShare to invest in each new position.

The "SetSimPosSize" has two parameters:
Trade Size: Could be an amount in dollars or a percentage value depending on the second parameter
Position Size Type: The position sizing type or technique to use. Possible values are: _DollarValue, _PercentageOfEquity, _Shares

Simple example to buy a fix dollar amount (\$10,000) for each new position:
SetSimPosSize(10000, _DollarValue);

To buy a fixed number of shares (Example: 10 shares) use:
SetSimPosSize(10, _Shares);

To buy 10% of the portfolio equity for each new position use:
SetSimPosSize(10, _PercentageOfEquity);

Of course you can use the QS language to create advanced position sizing techniques. For example, you can instruct QuantShare to buy 50% of equity for SPY and 10% for any other asset. Here is how:
pos = iff(stringequal(name(), "SPY"), 50, 10);
SetSimPosSize(pos, _PercentageOfEquity);

Money Management

For advanced position sizing techniques, you can use the money management tool. This tool allows you to implement C# based scripts that catch different trading events (OnStartSimualtion, OnEndPeriod, OnNewPosition...) and perform different actions such as: Increase the number of shares to be bought, scale-in/out a position...

Here are some examples of position sizing techniques implemented using the money management tool:

And here is how to create a scale-in trading strategy and optimize it (also using the money management script):
Money Management: Optimize the scale-in strategy