Every algorithm should have this basic form:
# import modules # Python C# connector class QuickSMA : MEAlgorithm def Initialize(): SetupHistory() def OnData(): """ Iteratate through candle data received from the Initialize() method """
Note for Python users: Because the Machina Engine code base is written in C# your Python script needs to import a C# connector clr and specifically reference the C# modules that are required for script execution.
When executed, an algorithm first does preparation work before consuming data:
- import modules (and reference C# modules in the case of Python)
- Instantiate the MEAlgorithm and name this algorithm instance (e.g. QuickSMA)
- Initialize parameters such as
- exchange account information
- instrument(s) to be traded
- fetch candle data
Question: modules in C#? instruments or symbols?
The minimum required modules for executing an algorithm are the following:
using System; using System.Linq; using MachinaEngine.Data; using MachinaEngine.Orders; using MachinaEngine.Brokerages; using MachinaEngine.Parameters; using MachinaEngine.Configuration; using MachinaEngine.Securities; using Humanizer; from clr import AddReference AddReference("System") AddReference("MachinaEngine.Algorithm") AddReference("MachinaEngine.Common") from System import * from MachinaEngine import * from MachinaEngine.Algorithm import * from MachinaEngine.Brokerages import * from MachinaEngine.Orders import *