Code Structure of a Strategy
You now have the necessary prerequisites installed and ready.
This page describes the methods you will use to create your strategy.
You have the following methods.
strategy_select_instruments_for_entry()- You may want to run your strategy for multiple instruments. When you pass those instruments to the strategy, the backend core calls this method for each instrument one by one, every candle time. This allows you to write decision-making code for each instrument, allowing you to decide whether an order is to be punched for that particular instrument or not.
strategy_enter_position()- You can now punch your order in this method for each instrument that you have selected for entry in the previous method.
strategy_select_instruments_for_exit()- Once a position is entered for a particular instrument, the backend core calls this method for those instruments one by one, every candle time. This allows you to write decision-making code for each instrument, allowing you to decide whether that particular instrument is to be exited or not.
strategy_exit_position()- You can now exit positions in this method for each instrument that you have selected for exit in the previous method.
You have the following supporting methods:
__init__()- Thia ia the constructor method used in every strategy. You can perform sanity checks here for each parameter passed as an argument to the strategy. You can also declare the set of variables that you may need for your strategy.
initialize()- This method is called every time the strategy starts for the first time as well as the start of every trading day. You may set initial values for the set of variables that you have declared in the previous method.
name()- This method sets a unique name for your strategy.
versions_supported()- This method sets the version of AlgoBulls Platform on which this strategy is certified tested successfully by you.
You have the following utility function to be used in this strategy :
get_crossover_value()- A utility method available which calculates the crossover value.
Once you create your own strategy or use a ready strategy from the pyalgostrategypool package, this is how it works internally on the AlgoBulls Core Trading Engine.
Next, you code the actual strategy taken as an example in this tutorial. Alternatively, you can pick up a ready strategy and directly upload it.