
Overview of a free robot for pair arbitrage in OsEngine. The robot is ready to be launched on the Moscow Exchange (MOEX), as well as on crypto exchanges like Binance, Bitget, and others. In general, join us.
Logic:
The robot trades on the chart of deviations of one instrument from another, calculated through their difference with a multiplier.
Two lines are overlaid on this chart (Cointegration), calculated from the standard deviation, multiplied by a multiplier. Above and below zero.

Fig. 1. Cointegration.
1. When the current deviation is above the upper line on the deviation chart, we enter a position, anticipating the convergence of instruments. We close the previous position.
2. When the current deviation is below the lower line on the deviation chart, we enter a position, anticipating the convergence of instruments. We close the previous position.

Fig. 2. Example of robot logic.
Placement:

Fig. 3. Placement of the robot in the project.
Robot code:

Fig. 4. Constructor.
1. Create a private field of type BotTabPair.
2. Call the TabCreate method from the base class of the robot, passing the BotTabType enumeration as a parameter, in our case Pair. And below, store the reference in the previously created field.
3. Subscribe to the CointegrationPositionSideChangeEvent event.
4. Create a Regime parameter to check the robot's state, whether it is enabled or not.
5. Also create a MaxPositionCount parameter to configure the maximum number of positions.

Fig. 5. Method GetNameStrategyType.
Create the GetNameStrategyType method and assign the robot's name to it.

Fig. 6. CointegrationPositionSideChangeEvent event handler.
Move to the event handler:
1. Check if the robot is enabled or not, if not, exit the event.
2. Check if we have open positions. If yes, enter the logic of closing positions and then the logic of opening positions. If there are no open positions, immediately move to the logic of opening positions.

Fig. 7. Logic of closing positions.
1. Check the direction of Cointegration:
a. Direction above the upper line.
b. Past value was below the lower line.
Then we close the positions.
2. Also check the direction.
a. Value below the lower line.
b. Past value was above the upper line.
Close the positions.

Fig. 8. Logic of opening positions.
1. Check the number of open positions and exit the method if they equal the maximum allowed number of positions.
2. Compare the current direction of Cointegration, if it is equal to the previous value, exit the method.
3. If the cointegration broke the upper line, then on the first instrument we enter Short, and on the second instrument we enter Long.
If the lower line was broken, then the first instrument - entry into Long, and the second - entry into Short.
Testing:
We conducted testing on 5 pairs, and here are the results we obtained:

Fig. 9. Testing results.
If you have any difficulties or questions, please write to the support chat. Link