-
Notifications
You must be signed in to change notification settings - Fork 71
Adding a MQL4 Function to the Framework
This procedure shows how to add a MQL4 command/function to the framework. When deciding on whether it would be worthwhile to script the generation, I decided that I only need a handful of functions so the manual approach would be quicker for now. Atleast until it starts pissing me off. (update, gonna move forward with automation here. it's the sensible approach)
1. Update C# Command ENUM
Add a new entry to the MQL4CSharp.Base.Enums.Command enum to match the command (this mustbe a 1:1 with a MQL command) Go to the MQL docs and add all methods (from the left) to enum list for a given function, even if just implementing one function.
2. Update C# Base Strategy
Add the method in C# code to MQL4CSharp.Base.Startegy. Put it under an existing category (ie. Orders, Objects) or create a new category. Overload methods where ever possible. Look at ObjectCreate methods as an example
Within the new method:
- create a parameter list and add the method parameters
List<Object> parameters = new List<Object>();
parameters.Add(chart_id);
- Call the ExecCommand method from CommandManager:
CommandManager.getInstance().ExecCommand(Command.objectCreate1, parameters);
- Block the current Thread and check if the command is still running:
while (CommandManager.getInstance().IsCommandRunning()) Thread.Sleep(1);
- Then return the result of the MQL command:
return (bool) CommandManager.getInstance().GetCommandResult(); // change bool to mql function return type
3. Add to MQL expert:
- add a case to the switch in execute[ReturnType]Command to execute the MQL command (where returnType is bool, int, etc)
- The id in the switch must equal the C# Command ENUM as above