2
votes

Due to differences in technical indicator calculations between my testing platform and MT4 I have decided to try and bring the open source TA-LIB API into MetaTrader via a custom indicator DLL compatible with MetaTrader.

I know that to make functions available to MetaTrader I can simply create an export file and then use the #import declaration in the MT4 code but I am struggling to see how I would use that to write a custom indicator in C and then how to access it via MT4.

I know this can be done but I cannot find any examples anywhere on the internet.

Does anyone have any references or a sample template of an indicator written in C, C++?

3

3 Answers

1
votes

I believe you would make a DLL and then call it from the indicator or EA.

Do a google search on making a DLL and/or go to http://www.mql4.com.

There is also a Yahoo group for Metatrader Experts and Indicators that has a lot of people in it that may be able to give you a better answer.

0
votes

Look into your folder MetaTrader\experts\samples\DLLSample\, there will be source files:

StdAfx.h
ExpertSample.dsp
ExpertSample.dsw
ExpertSample.def
ExpertSample.cpp

There is template for your DLL. Use it.

Don't forget to make correct import from DLL in your MetaTrader.

0
votes

Custom Indicator. __________________C++ Side

// Setup the standard call specification keyword for the compiler.

#define MQL_EXPORT __declspec(dllexport)

#define WINAPI     __stdcall

MQL_EXPORT void WINAPI aCallToSimpleExternalCustomIndicatorCODE(){
     return;
    }

Custom Indicator. __________________MQL4 Side

//

#include <aSimpleExternalCustomIndicatorCODE_HEADER.h>  // should you deploy .h declarations
//

#import       "aSimpleExternalCustomIndicatorCODE.dll"  // #import-<start>
void     aCallToSimpleExternalCustomIndicatorCODE();    //  <fun> interface declaration
#import                                                 // #import-<end>
//

int start(){                                            // MT4.anEventFACTORY -> launched per  each aNewQuoteArrivalEVENT
    aCallToSimpleExternalCustomIndicatorCODE();         // example of a simple external code
    return( 0 );
    }