Ali Morakabi

Algorithmic Trading, Blockchain, Data science, Forex

How to develop MetaTrader server plugin ?

A MetaTrader Server plugin is a special module designed to expand the set of functions available on the trading platform. These plugins are represented as separate DLL files and can be utilized to modify algorithms used in certain server operations, such as margin or swap calculations. The development of MetaTrader Server plugins is achieved through the use of the MetaTrader Server API.

It’s always hard to do the first ones. Even if you are a senior programmer, creating the first plugin for MetaTrader can be challenging . this C++ Source code is where you can start from. A prototype project that does not perform specific operations on the server, but the starting point to process users orders, transactions and anything that MetaTrader allows developers to access through the MetaTrader Server API.
You can change the Entry point and execution time of your plugin by changing the Hooks.

//+----------------------------------------------------------+
//|                                                 MtSrvDev |
//+----------------------------------------------------------+
#include "stdafx.h"
#include "common.h"

PluginInfo        ExtPluginInfo={ "PluginName",100,"Company Name .",{0} };
CServerInterface *ExtServer=NULL;

BOOL APIENTRY DllMain(HANDLE hModule,DWORD  ul_reason_for_call,LPVOID lpReserved)
{
	switch(ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
			break;
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
			break;
		case DLL_PROCESS_DETACH:
			break;
	}

	return(TRUE);
}

void APIENTRY MtSrvAbout(PluginInfo *info)
{
	if(info!=NULL) memcpy(info,&ExtPluginInfo,sizeof(PluginInfo));
}

int APIENTRY MtSrvStartup(CServerInterface *server)
{

	if(server==NULL)                        return(FALSE);
	if(server->Version()!=ServerApiVersion) return(FALSE);
	ExtServer=server;
	ExtServer->LogsOut(CmdOK,"PluginName","initialized");

	return(TRUE);
}

//+-----------------------------------------+
//| Incoming requests                       |
//+-----------------------------------------+
void APIENTRY MtSrvTradeRequestApply(RequestInfo *request,const int isdemo)
  {
	// Your Code
  }
//+-----------------------------------------+
//|                                         |
//+-----------------------------------------+

You can download the project from github.

Leave a Response