Simple strategy
How to create you first strategy and run it the OptimusFLOW trading platform
Last updated
How to create you first strategy and run it the OptimusFLOW trading platform
Last updated
In our previous articles, we showed you how to use OptimusFLOW Algo extension and write your own indicators. Now we show you how to create you first strategy and run it the OptimusFLOW trading platform.
We use the name "Strategy" for code, that can implement absolutely any logic and can be executed in OptimusFLOW. You can use strategies for the realization of trading algorithms, a specific logic of controlling closing orders (for example Trailing stop), for arbitrage between different connections, etc. We don't have any restrictions or limitations for this, moreover, we provide you access to almost all functions from our trading core.
OptimusFLOW Algo provides you with two predefined templates of strategies. We will start from a blank template, which contains only basic functions. Use "File -> New project" in the main menu of Visual Studio to open "New project" window. Type "Strategy" and you will see special project type for blank Strategy:
You will get generated code with a few empty functions:
As you can see, this blank version is not related to any trading functionality - it is a just general code-basis. It is inherited of class Strategy, by this OptimusFLOW recognize that your code is compatible and can be executed in OptimusFLOW.
Let's go deep into the code - it contains a few methods:
Will be called when user select required strategy from Strategy lookup. Use this method to implement logic, that needs to be executed once on creation.
Will be called when user press Run button in Strategy Runner panel. Use this method to set initial values before running.
Will be called when user press Stop button in Strategy Runner panel. Use this method to clear state of your strategy (if required).
Will be called when user close Strategy Runner Panel or select another strategy. Use this method for final clearing used resources.
Via this method, you can display the required information in the Strategy Panel and control your strategy. For example, you can display how many quotes were processes, or how many but or sell orders were sent, etc.
You don't need to add logic to all these methods, the most often used is a pair of OnRun/OnStop methods.
The most popular case is when you use strategy to implement some trading algorithm and you need only one instrument and one account for this. For this we have a predefined template - you can use it as a basis. Use "One symbol strategy" in "New project" window:
Now we have a little more code - strategy contains Symbol and Account input variables, which we described before. It subscribes to all type of quotes for selected symbol in OnRun() method and you can receive and process them if it required by your algorithm.
Let's create some trivial example and try to run it in the OptimusFLOW platform. We will talk about retrieving current trading information and trading operations in our next articles, for the current moment, we just add counters for each type of quotes and strategy metrics for displaying in Strategy Runner panel. We will add examples of logs also - you should always use them, as it can help you to understand the current strategy state or display error information. You can specify a type of log: Info, Error or Trading.
Build your project, and if your OptimusFLOW Algo is properly assigned to an instance of OptimusFLOW, your strategy will be automatically copied to an appropriate folder and you will see it in Strategy Lookup window:
You need to specify the required input parameters: symbol and account and then press the "Run" button. Now your strategy is running and you will see logs and metrics, that we have added:
It is a very simple example and it provides you only basic knowledge about how strategies are working in OptimusFLOW. In our further lessons, we will show you how to create real algorithms using analysis of your current trading portfolio and trading operations.