Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennislwm/b153a1c8183f6e93864e348eca6601d6 to your computer and use it in GitHub Desktop.
Save dennislwm/b153a1c8183f6e93864e348eca6601d6 to your computer and use it in GitHub Desktop.
FX-Git Packages in Metatrader 4 (MT4)

How NOT to Quickly Turn a Profitable Strategy into a Loss-Making One

Introduction

Did I get your attention?

One of the limitations of using a demo broker account is that there is no or very little slippage, hence it does not reflect actual trades.

The result is that a "profitable" robot or Expert Advisor ["EA"] on a demo account can quickly become a loss-making robot in a live account.

There have been books written about how some Forex brokers utilize tools to perform stop-hunting, which contribute to more losses, on live accounts. Again, this activity does not happen on a demo account.

I decided to create a Ghost package in Metatrade Query Language ["MQL"] to mitigate these problems. This package utilizes a live account for tick data, but orders are processed by Ghost and stored in an Sqlite database.

The benefit of this is that the orders created by a robot are never sent to the broker, but they are intercepted and processed by the Ghost package, and sent back to the robot.

Hence, the whole process is transparent to the robot and as far as the robot is concerned, it is as good as trading on a live account.


About Ghost Package

The Ghost package supports THREE (3) modes:

  1. Broker - Orders are sent to broker (same as without Ghost package)
  2. Ghost - Orders are sent to SqLite Database (paper trading)
  3. Excel - Orders are sent to Excel Spreadsheet (NO longer supported)

Project Structure

 MQL4/                         <-- Root of your MQL4 folder
   +- Include/                 <-- Holds any MQH file
      |- PlusGhost.mqh         <-- Main Package
      |- PlusTurtle.mqh        <-- Broker functions
      |- GhostBroker.mqh       <-- Interface to Broker Orders
      |- GhostExcel.mqh        <-- Interface to Excel Orders
      |- GhostSqLite.mqh       <-- Interface to SqLite Orders
      |- SqLite.mqh            <-- DLL functions
   +- Indicators/              <-- Holds any MQ4 Indicator file
      |- GhostTerminal.mqh     <-- Ghost indicator to display paper trades
   +- Libraries/               <-- Holds any DLL file
      |- sqlite3_wrapper.dll   <-- DLL for Sqlite database
      |- excellink.dll         <-- DLL for Excel spreadsheet (NO longer supported)

YouTube Video

This video Paper Trading in MT4 using SQL (Updated) on my YouTube channel explains how the Ghost package works on a live broker account.


Example Usage

In your MT4 Client, Click on File-->Open Data Folder.

Download and copy the above files into the corresponding subfolders under your MQL4 root folder.

Get the source code for Dynamic Breakout Strategy EA to view an example.


Reach Out!

Please consider giving my repository dennislwm/FX-Git a star on GitHub.Empty File

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment