Each individual bot in OsEngine can open multiple positions in different directions. In order to differentiate between positions for various future management strategies, they need to be labeled. Let's talk about one way to label positions using the SignalTypeOpen and SignalTypeClose fields of a position.
We will analyze a bot that trades TWO trading logics simultaneously, separating the logic based on signals.
1. What Is It About?
Each instance of the bot class can simultaneously manage multiple positions. In fact, there is no limit on the number, as it ultimately depends on the hardware performance and the amount of funds in the account. In such cases, it may be necessary for the bot to differentiate positions based on certain criteria, such as the reasons for opening and/or closing the positions. For these purposes, the Position class has two fields:
public string SignalTypeOpen
public string SignalTypeClose
Both can contain arbitrary string values passed through trading methods.
Typically, signals are used for analyzing positions and facilitating the understanding of information, but they can also be used to build complex trading systems based on branching logic depending on the signal that led to the opening and closing of a position.
2. Open the Example Bot: TwoEntrySample.
This can be found in the OsEngine repository on GitHub here.
Inside the project here:
3. The bot has two indicators through which it trades simultaneously.
Otherwise, it is standard:
1. Configuration parameters.
2. Two indicators: Envelopes and PriceChannel. Two channel indicators.
3. A source for connecting to a single instrument.
4. Logic entry through the candle close event.
The settings are as follows:
Parameters Explained:
1. Regime – working mode.
a. Off – Disabled.
b. On – Enabled, and it will enter both long and short.
2. Volume Type – volume selection mode.
a. Contracts – number of contracts for the instrument.
b. Contract Currency – currency of the contract.
c. Deposit Percent – percentage of the deposit.
3. Volume – volume value. Specifically, this depends on the previous point. In the case of Contracts, the volume of the instrument is specified here. In the case of Contract Currency, the amount in rubles or dollars to enter is specified. In the case of Deposit Percent, a percentage of the total deposit to enter into the contract is specified here.
4. Asset in Portfolio – here you need to specify the currency name that will be used to calculate the volume if you chose the volume type “Deposit Percent”. In the tester, we leave it as “Prime”. In crypto, this is usually “USDT”.
5. Envelop Deviation – deviation for the Envelopes indicator.
6. Envelop Moving Length – length of the central line of the Envelopes indicator.
7. Price Channel Length – length of the PriceChannel indicator.
4. When opening a position, it is marked with a string signal.
To do this, one parameter is added to the position opening method:
5. Buying a second position, paying attention to the signal in the first one.
If we have one position open with some signal, we do not use that signal again in the logic for opening:
6. Sorting positions by different closing methods, looking at the signal.
The closing logic is also divided into two, depending on the opening signal:
7. Position Type in the Interface.
In the positions table in the bots and the main interface, there are columns “Signal Type Open” and “Signal Type Close”. If you label positions in this way, you will see the signal type in the corresponding columns:
Wishing you successful algorithms!