Skip to content

Adding a MQL4 Function to the Framework

Jason Separovic edited this page Jan 23, 2016 · 10 revisions

This procedure shows how to add a MQL4 command/function to the framework. This is automated now using https://github.com/jseparovic/MQL4DocScraper

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
Clone this wiki locally