Getting started

Creating my first Expert Advisor ever… daunting!

I opened the integrated MetaEditor IDE by clicking on Tools – MetaQuotes Language Editor [F4]

Once it had opened, I selected New – Expert Advisor (template). I chose “Test” as my first EA’s name, and selected all the available callback functions / event handlers.

I then added the following code to each event handler, which would show me which functions were called at what point when I ran the EA.

Print(__FUNCTION__);

If you then compile (F7), and run (F5), you will be returned to MetaTrader, and asked to confirm you wish to run the EA. Click on OK.

Now when you click on the chart, or a new tick arrives, etc, you will see the callback function’s name being printed (It is displayed in Experts tab of the Toolbox – if the toolbox is not visible, Ctrl-T will bring it up)

To stop the EA, either right click on the EA icon in the top right corner of the main chart window and click Remove, or return to MetaEditor (F4) and click on Stop debugging (Shift-F5).

This is the source code:

int OnInit()
{
    Print(__FUNCTION__);
    return INIT_SUCCEEDED;
}
//-----------------------------------------------------------

void OnDeinit(const int reason)
{
    Print(__FUNCTION__);
}
//-----------------------------------------------------------

void OnTick()
{
    Print(__FUNCTION__);
}
//-----------------------------------------------------------

void OnTrade()
{
    Print(__FUNCTION__);
}
//-----------------------------------------------------------

void OnTimer()
{
    Print(__FUNCTION__);
}
//-----------------------------------------------------------

double OnTester()
{
    Print(__FUNCTION__);
    return 1.0;
}
//-----------------------------------------------------------

void OnChartEvent(const int     id, // Event ID
                  const long&   l,  // Parameter of type long event
                  const double& d,  // Parameter of type double event
                  const string& s)  // Parameter of type string event
{
    Print(__FUNCTION__);
}
//-----------------------------------------------------------

void OnBookEvent (const string& symbol)                  
{
    Print(__FUNCTION__);
}
//-----------------------------------------------------------
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s