Skip to content

Adding a MQL4 Function to the Framework

jseparovic edited this page Jan 20, 2016 · 10 revisions

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.


1. 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

2. 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)

Within the new method:

  • create a parameter list and add the method parameters
            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```


**4.** 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