Files
aiomql/docs/strategy.md
T

66 lines
2.6 KiB
Markdown
Raw Normal View History

2024-02-12 21:09:28 +01:00
# Strategy
2023-10-11 09:49:06 +01:00
The base class for creating strategies.
2024-02-12 21:09:28 +01:00
## Table of Contents
- [Strategy](#strategy)
- [\_\_init\_\_](#init)
- [sleep](#sleep)
- [trade](#trade)
<a id="strategy"></a>
### Strategy
2023-10-11 09:49:06 +01:00
```python
class Strategy(ABC)
```
The base class for creating strategies.
2024-02-12 21:09:28 +01:00
#### Attributes
| Name | Type | Description | Default |
|--------------|--------------|----------------------------------------------|---------|
| `name` | `str` | A name for the strategy. | None |
| `account` | `Account` | Account instance. | None |
| `mt5` | `MetaTrader` | MetaTrader instance. | None |
| `config` | `Config` | Config instance. | None |
| `symbol` | `Symbol` | The Financial Instrument as a Symbol Object | None |
| `parameters` | `Dict` | A dictionary of parameters for the strategy. | None |
| `sessions` | `Sessions` | Trading sessions. | None |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
### Notes
2023-10-16 15:36:31 +01:00
Define the name of a strategy as a class attribute. If not provided, the class name will be used as the name.
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
<a id="init"></a>
2023-10-16 15:36:31 +01:00
### \_\_init\_\_
2023-10-11 09:49:06 +01:00
```python
2023-10-16 15:36:31 +01:00
def __init__(*, symbol: Symbol, params: dict = None, sessions: Sessions)
2023-10-11 09:49:06 +01:00
```
2023-10-16 15:36:31 +01:00
Initiate the parameters dict and add name and symbol fields. Use class name as strategy name if name is not provided.
2024-02-12 21:09:28 +01:00
#### Parameters
| Name | Type | Description | Default |
|------------|------------|-----------------------------|---------|
| `symbol` | `Symbol` | The Financial instrument | None |
| `params` | `Dict` | Trading strategy parameters | None |
| `sessions` | `Sessions` | Trading sessions | None |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
<a id="sleep"></a>
2023-10-16 15:36:31 +01:00
### sleep
2023-10-11 09:49:06 +01:00
```python
@staticmethod
async def sleep(secs: float)
```
Sleep for the needed amount of seconds in between requests to the terminal.
computes the accurate amount of time needed to sleep ensuring that the next request is made at the start of
a new bar and making cooperative multitasking possible.
2024-02-12 21:09:28 +01:00
#### Parameters
| Name | Type | Description | Default |
|--------|---------|----------------------------------------------------------------|---------|
| `secs` | `float` | The time in seconds. Usually the timeframe you are trading on. | None |
2023-10-11 09:49:06 +01:00
2024-02-12 21:09:28 +01:00
<a id="trade"></a>
2023-10-16 15:36:31 +01:00
### trade
2023-10-11 09:49:06 +01:00
```python
@abstractmethod
async def trade()
```
Place trades using this method. This is the main method of the strategy.
It will be called by the strategy runner.