Robot for pair arbitrage on a breakout based on correlation and cointegration in OsEngine.

Robot for pair arbitrage on a breakout based on correlation and cointegration in OsEngine.

Overview of a free robot for pair arbitrage in OsEngine. The robot is already ready to be launched on the Moscow Exchange (MOEX), cryptocurrency exchanges such as Binance, Bitget, etc. In general, join us.

Logic:

A robot that catches a trend in pairs.

The essence of the idea. If the correlation is below -0.8 - we enter, expecting further divergence:

Fig. 1. Entry logic.

After entering, we wait for the correlation to become greater than 0.8 - we exit positions:

Fig. 2. Exiting positions.

Location: 

Fig. 3. Robot location in the project.

Robot code: 

Fig. 4. Constructor.

1. Create a private field of type BotTabPair.

2. Call the method from the base class of the robot TabCreate, passing BotTabType enumeration as a parameter, in our case Pair. And below, we write a reference to the previously created field.

3. Subscribe to the CorrelationChangeEvent event.

4. Create a Regime parameter to check the status of the robot, whether it is on or off.

5. Next, the MaxPositionCount parameter to set the maximum number of positions.

6. MaxCorrelationToEntry parameter to denote the correlation threshold for entry.

7. MixCorrelationToExit parameter for the correlation threshold for exiting positions.

Fig. 5. Method GetNameStrategyType.

1. Create the GetNameStrategyType method and write the name of the robot in it.

Fig. 6. CorrelationChangeEvent event handler.

Go to the event handler:

1. Check the status of the robot - on or off.

2. Check for positions. If we have positions, we go to the closing logic, if not, we go to the opening logic of positions.

Fig. 7. Logic for closing positions.

1. Check the correlation value, if it breaks the level for exit, then close the positions.

Fig. 8. Logic for opening positions.

1. Check the correlation, if it meets the condition, then continue with the method, if not, exit.

2. Compare the number of open positions with the maximum allowable value. If it does not exceed this number, move on to opening positions.

3. If the cointegration is greater than zero, then we go Long on the first instrument and Short on the second, if the cointegration is below zero, then vice versa.

Testing:

We conducted testing on 10 pairs, and here are the results:

Fig. 9. Testing results.

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