MT4 Floating Charts Extension API
Access and/or extend MT4 Floating Charts functionality
MT4 Floating Charts Extension API
Download

Introduction

The MT4 Floating Charts extension API can be used to access existing functionality and/or add functionality. Extensions should always be scripts.
Although it is possible to create indicators and expert advisors, it is NOT recommended. All code and examples assume that you are writing a script.

Have an idea but do not know how to code in MQL4? Contact us and we just might make it for you for free.

Requirements

  1. MetaTrader 4 build 600 or higher.
  2. Allow DLL imports. In MT4, go to Tools > Options> Expert Advisors, check the box next to 'Allow DLL imports', and press OK.
  3. MT4 Floating Charts running on the system.

Installation

Download and extract FloatingChartsAPI.zip to <metatrader4_data_folder>\MQL4\Scripts, where <metatrader4_data_folder> is the path of the directory opened when you go to File > Open Data Folder in MetaTrader. In the Scripts directory, there should be a new subdirectory named FloatingCharts. This new directory contains the following subdirectories:

Getting Started

The best way to get started is to look at the examples. You should also take a brief look at the documentation.
The code to get started is as simple as the following:

#include "../api/FloatingCharts.mqh"
void OnStart()
{
    FloatingCharts fc;
    // Now do some something ...
    // For this example, just float the current chart.
    fc.Float(ChartID());
}

Code like the above is generally ok if the script is for yourself, but if you share it with others or if it just is not working for you, then you should probably add some prechecks. You may want to check if Float succeeded. This is encouraged. However, checking the result of most floating chart commands is usually overkill IF you do prechecks. Our extensions will not perform the extra check unless we have a specific reason to. The following is an improvement to the above code example:

#include "../api/FloatingCharts.mqh"
void OnStart()
{
    FloatingCharts fc;
    if (FCPreCheck(fc) != FC_ERR_SUCCESS) {
        return;
    }

    // Float the current chart and check result.
    int float_res = fc.Float(ChartID());
    if (float_res != FC_ERR_SUCCESS) {
        Print("Failed to float chart: ", FCErrorDescription(float_res));
    }
}

int FCPreCheck(const FloatingCharts &fc)
{
    int result = FC_ERR_SUCCESS;

    if (!IsDllsAllowed()) {
        Alert("DLLs are not allowed!\n",
              "This script cannot communicate with MT4 Floating Charts unless\n",
              "Tools > Expert Advisors > 'Allow DLL Imports' is checked.");
        result = FC_ERR_DLL_NOT_ALLOWED;
    } else if (!fc.IsFCRunning()) {
        Alert("MT4 Floating Charts is not running!\n",
              "This script only works with MT4 Floating Charts running.");
        result = FC_ERR_NOT_RUNNING;
    }

    return result;
}

General Notes

The acronym FC stands for Floating Charts and is used throughout the code and examples.