Your interactive trading laboratory!
 • 
20 users online

Quantacula Help

How-To
C# API Reference
Extensions
Development Blog
API-Extensions
Indicator Spotlights

QCommunity Extensions
The open-source GitHub repository of source code for the QCommunity Extensions library. Contains indicators and other extensions submitted by the Quantacula Community. Look for QCommunity indicators when you create a Building Block model, mark the "QCommunity" library check box to expose them.

TASC-Extensions
The open-source GitHub repository of source code for the TASCExtensions Quantacula extension. Contains indicators and other extensions adapted from the Traders' Tips articles in Technical Analysis of Stocks & Commodities magazine.
Multiple Position Models
Published by Q Glitch on 9/28/2018

This article will describe how to build models that maintain multiple positions in Quantacula's Building Block Models. You can add more than one entry and exit to your model, but how do they relate to each other? The short answer is that each entry pairs with the exit (or exits) first encountered below in the list of building blocks.

In the example below, entry A will be paired with both exit B (a profit target) and exit C (a stop loss). Even if there are more exits beneath building block D, they will not be paired with entry A because block D is another entry, which begins a new sequence.

Multiple Pos

The model below uses two entry blocks to establish two possible open positions; a buy at stop at the highest high in 20 bars, and a buy at limit at the lowest low of 20 bars. It utilizes two exits, like in the previous example; a profit target and a stop loss. In this case, entry A will be paired with both exit C and exit D. Entry B will also be paired with both exit C and exit D.

Multiple Pos

Managing Multiple Positions

You can use multiple entries to build models that scale into a position. For example, the model below buys if the CMO (Chande Momentum Oscillator) crosses above its oversold level. We duplicated the buy entry block so that the model takes two positions, each of which is paired with both the profit target and the stop loss exit.

Multiple Pos

The above setup is a valid model, but it might not behave exactly as you'd expect. When the CMO crosses above -50, both entry blocks will execute at the same time, so the model will take two positions on exactly the same bar. This could be the result you intended, but you might also want the model to hold off on the second position, waiting until the CMO crosses above the oversold level a second time.

You can accomplish this by adding another condition to the second entry, Open Position Count. By setting the parameter value to 1, the condition evaluates to true only if there is currently an open position being held by the backtester.

The Open Position Count condition has a parameter that controls whether you are testing for the number of positions in the symbol that is currently being backtested, or across the whole portfolio. In this case we set the parameter to count the open positions for the current symbol, so the condition will apply on a symbol-by-symbol basis.

Multiple Pos

Here is a chart from Quantacula Studio of this model in action. Note that the first entry occurred at a slightly lower price than the second. In this case, the 10% profit target was also slightly lower for the first position. Therefore, you see the first position exit prior to the second position.

If you examine the positions list, you might also wonder why the position's profit was reported as 9.80% and not 10%. This is because of the simulated commission that the Quantacula backtester deducts from the position profit.

Multiple Pos