Positions. Why Are They Important in Algorithmic Trading and OsEngine?

Positions. Why Are They Important in Algorithmic Trading and OsEngine?

Let's understand why such an abstraction as "Position" is needed in algo terminals.

1. OsEngine is an ideological successor of Wealth-Lab.

The mechanics of position management, methods for opening and closing them, have come to OsEngine from Wealth-Lab. Not entirely, but almost, and at this moment, the layer has increased about five times. This terminal was once very popular in Russia and had a pleasant interface back then.

If you look at the script in Wealth-Lab, you can find much in common with what is in the scripts of OsEngine:

1. Language - C#.

2. Similar syntax for declaring parameters.

3. Parameters are created for optimization right away!

4. A delayed method for closing a position through selling when the price drops below. SellAtStop. There are similar methods for opening a position.

5. Requests to positions! Wealth-Lab also tracks its positions within the robot, from which it builds statistics and more. In this case, all open positions are passed to the method for closing positions at the stop. There can be one or several.

6. BuyAtMarket. A method for opening a position at market price. If you look closely at the conditions, we open THREE positions based on one condition, but at different times. NOT THREE ORDERS! BUT THREE POSITIONS! And later, those three positions are closed at the stop.

7. ShortAtMarket. This corresponds to SellAtMarket. The same applies.

For most algo trading platforms, this serves as the foundation.

 

2. The main unit for implementing trade management in many algo terminals (with testers, journals, and optimizers) is a POSITION.

For robots in algorithmic trading, this is necessary because a position has:

A. An entry point, even if it consists of several orders.

B. An exit point, even if it consists of several orders.

C. They allow for convenient statistics to be compiled regarding the Positions, understanding which entry point of your algorithm is profitable and which is losing.

From the perspective of statistics collection in the tester, this is a vital necessity. This is how one can understand the profitability of individual entry and exit points.

 

3. You need to manage positions, not orders.

This is because managing by position allows you to slice statistics across different instruments, various strategies, and types of entries and exits simultaneously and as frequently as possible. If there were 10 positions in a day or a minute, we will have separate statistics for each:

However, if positions are not tracked separately and only orders are used, it will be inaccurate and inconsistent for collecting statistics. In the futures market, if you don’t know your positions yourself and trade different strategies on various instruments, profitability will be calculated by the exchange during clearing. You would see the overall gain/loss a couple of times a day:

It's clear that such a way of collecting trading and algorithmic trading statistics is not suitable at all.

 

4. POSITION and its entry/exit points compel systematic thinking.

Here's a robot that identified some situation in the market. Let's take the simplest case. A breakout of the Bollinger channel:

This is a precise event that cannot be interpreted differently. There is an indicator with boundaries; if the channel is breached, we enter the position! The robot has such initial code.

Non-systematic thinking might lead you to believe that if the position is ultimately losing, you need to average down, pyramid, move the stop, or close manually. Whatever it may be. This is something people learn when trading manually on QUIK for decades!

Unfortunately, this is not allowed in algorithmic trading.

AN ENTRY EVENT INTO A POSITION HAS OCCURRED; THE ROBOT MUST ENTER NEAR THIS EVENT. Then, due to another event, AN EXIT FROM THE POSITION HAS OCCURRED. This way we can gather statistical material, and no other way.

You can optimize the channel width in the tester or optimizer, choose a time frame, and do cross-testing. Anything goes! But during trading, when the robot is active, you cannot act as if the position does not exist, and the entry point is not there or can be "made up" as you wish. You cannot ignore the statistics that cannot be collected without positions.

BollingerTrailing Strategy on Sberbank Shares and Position Statistics in the Journal:

If you need to spread out the entry point, we must determine what signals will be used. For example, in the public build, there is a robot called AlligatorTrendAverage that enters and may further "dilute" the position several times. As a result, a position can have several orders:

The journal will collect statistics for each position separately:

 

5. Rarer Cases When Positions May Seem Unnecessary.

For example, with such types of robots:

1. Grid Traders. Robots that enter not based on signals, but on distance. Generally, collecting statistics from them is supposedly unnecessary, as signals are equivalent, so it is sufficient to check statistics once a day on the exchange.

2. Different types of index arbitrage for trading the spread width between instruments and groups of instruments. Such robots also have buttons like "activate when spread width is here" and "unload when spread width is here." Here, the spread can conditionally change its state from "time to buy" to "time to sell" once a week.

For algo-traders implementing such algorithms where signals are stretched over time, it may be challenging to understand the meaning of using positions. However, both grid traders and index arbitrages can be implemented in OsEngine, though it might not be very convenient in this case.

Good luck with your algorithms!

OsEngine Support: https://t.me/osengine_support_english