Consistent Six Figure Forex Trading Strategy

By | 08/07/2022

As you lot may know, the Foreign Exchange (Forex, or FX) market place is used for trading betwixt currency pairs. Simply you might not exist aware that it’south the virtually liquid market in the globe.

A few years ago, driven by my marvel, I took my first steps into the world of Forex algorithmic trading by creating a demo account and playing out simulations (with faux coin) on the Meta Trader 4 trading platform.

Forex cover illustration

After a week of ‘trading’, I’d nigh doubled my money. Spurred on by my own successful algorithmic trading, I dug deeper and eventually signed up for a number of FX forums. Soon, I was spending hours reading about algorithmic trading systems (rule sets that make up one’s mind whether you lot should buy or sell), custom indicators, marketplace moods, and more than.

My First Client

Around this time, coincidentally, I heard that someone was trying to detect a software programmer to automate a simple trading system. This was dorsum in my higher days when I was learning near concurrent programming in Java (threads, semaphores, and all that junk). I idea that this automated arrangement this couldn’t be much more than complicated than my advanced data science form work, so I inquired about the job and came on-lath.

The client wanted algorithmic trading software built with MQL4, a functional programming language used past the Meta Trader 4 platform for performing stock-related actions.

MQL5 has since been released. As you might expect, it addresses some of MQL4’s issues and comes with more congenital-in functions, which makes life easier.

The role of the trading platform (Meta Trader 4, in this case) is to provide a connexion to a Forex broker. The banker and so provides a platform with real-time information near the market and executes your buy/sell orders. For readers unfamiliar with Forex trading, here’s the information that is provided by the data feed:

This diagram demonstrates the data involved in Forex algorithmic trading.

Through Meta Trader 4, y’all tin admission all this data with internal functions, accessible in diverse timeframes: every minute (M1), every 5 minutes (M5), M15, M30, every 60 minutes (H1), H4, D1, W1, MN.

The movement of the Current Price is called a
tick. In other words, a tick is a change in the Bid or Ask toll for a currency pair. During active markets, at that place may be numerous ticks per second. During wearisome markets, there tin be minutes without a tick.
The tick is the heartbeat of a currency market robot.

When you place an lodge through such a platform, you
purchase
or
sell
a sure volume of a certain currency. You also set stop-loss and take-profit limits. The
stop-loss limit
is the maximum corporeality of
pips
(price variations) that you tin can afford to lose before giving up on a trade. The
accept-profit limit
is the corporeality of pips that you’ll accumulate in your favor before cashing out.

If yous want to learn more near the nuts of trading (e.thou., pips, order types, spread, slippage, market orders, and more than), see here.

Baca juga:  Binary Options Traders Choice Indicator

The client’s algorithmic trading specifications were simple: they wanted a Forex robot based on ii indicators. For background, indicators are
very
helpful when trying to define a marketplace state and make trading decisions, equally they’re based on past data (east.m., highest price value in the last
n
days). Many come born to Meta Trader 4. Even so, the indicators that my customer was interested in came from a custom trading system.

They wanted to trade every time 2 of these custom indicators intersected, and only at a certain angle.

This trading algorithm example demonstrates my client’s requirements.

Easily On

As I got my hands muddy, I learned that MQL4 programs have the following structure:

  • [Preprocessor Directives]
  • [External Parameters]
  • [Global Variables]
  • [Init Office]
  • [Deinit Function]
  • [Start Role]
  • [Custom Functions]

The start role is the heart of every MQL4 program since it is executed every time the marketplace moves (ergo, this office will execute once per tick). This is the case regardless of the timeframe you’re using. For case, you could be operating on the H1 (1 hour) timeframe, even so the start function would execute many thousands of times per timeframe.

To piece of work effectually this, I forced the function to execute once per menses unit of measurement:

        int first() {  if(currentTimeStamp == Time[0]) return (0);        currentTimeStamp  = Time[0];  ...
        
      

Getting the values of the indicators:

        // Loading the custom indicator extern cord indName = "SonicR Solid Dragon-Trend (White)"; double dragon_min; double dragon_max; double dragon; double tendency; int start() {   …   // Updating the variables that concur indicator values   actInfoIndicadores();  …. string actInfoIndicadores() {       dragon_max=iCustom(NULL, 0, indName, 0, 1);     dragon_min=iCustom(Zilch, 0, indName, 1, 1);     dragon=iCustom(NULL, 0, indName, four, one);     trend=iCustom(NULL, 0, indName, 5, 1); }
        
      

The determination logic, including intersection of the indicators and their angles:

        int start() { …    if(ticket==0)     {            if (dragon_min > tendency && (ordAbierta== "OP_SELL" || primeraOP == true) && anguloCorrecto("Purchase") == true && DiffPrecioActual("BUY")== true ) {             primeraOP =  false;             abrirOrden("OP_BUY", false);          }          if (dragon_max < trend && (ordAbierta== "OP_BUY" || primeraOP == true) && anguloCorrecto("SELL") == true && DiffPrecioActual("SELL")== true ) {             primeraOP = simulated;             abrirOrden("OP_SELL", false);          }      }         else    {               if(OrderSelect(ticket,SELECT_BY_TICKET)==truthful)        {            datetime ctm=OrderCloseTime();            if (ctm>0) {                ticket=0;               return(0);            }        }        else           Print("OrderSelect failed mistake code is",GetLastError());         if (ordAbierta == "OP_BUY"  && dragon_min <= trend  ) cerrarOrden(imitation);        else if (ordAbierta == "OP_SELL" && dragon_max >= trend ) cerrarOrden(false);    } }
        
      

Sending the orders:

        void abrirOrden(string tipoOrden, bool log) {      RefreshRates();    double volumen = AccountBalance() * bespeak;     double pip     = betoken * pipAPer;       double ticket  = 0;    while( ticket <= 0)    {  if (tipoOrden == "OP_BUY")   ticket=OrderSend(simbolo, OP_BUY,  volumen, Ask, three, 0/*Bid - (point * 100)*/, Ask + (point * 50), "Orden Buy" , 16384, 0, Green);       if (tipoOrden == "OP_SELL")  ticket=OrderSend(simbolo, OP_SELL, volumen, Bid, three, 0/*Ask + (indicate * 100)*/, Bid - (point * l), "Orden Sell", 16385, 0, Cherry);       if (ticket<=0)               Impress("Error abriendo orden de ", tipoOrden , " : ", ErrorDescription( GetLastError() ) );     }  ordAbierta = tipoOrden;        if (log==true) mostrarOrden(); }
        
      

If yous’re interested, you tin find the complete, runnable code on GitHub.

Backtesting

In one case I congenital my algorithmic trading system, I wanted to know: 1) if it was behaving appropriately, and two) if the Forex trading strategy it used was whatsoever good.

Baca juga:  Korvo Binary Options Forex Trading System

Backtesting
(sometimes written “back-testing”)
is the process of testing a particular (automated or non) system under the events of the by.
In other words, you examination your arrangement using the past as a proxy for the present.

MT4 comes with an acceptable tool for backtesting a Forex trading strategy (nowadays, at that place are more professional person tools that offer greater functionality). To first, yous setup your timeframes and run your program under a simulation; the tool will simulate each tick knowing that for each unit information technology should open at sure toll, close at a certain price and, reach specified highs and lows.

Later on comparing the deportment of the programme confronting historic prices, you’ll have a good sense for whether or not it’s executing correctly.

The indicators that he’d called, along with the conclusion logic, were non profitable.

From backtesting, I’d checked out the FX robot’southward render ratio for some random time intervals; needless to say, I knew that my client wasn’t going to get rich with it—the indicators that he’d called, along with the determination logic, were not profitable. Every bit a sample, here are the results of running the program over the M15 window for 164 operations:

These are the results of running the trading algorithm software program I’d developed.

Annotation that our rest (the blue line) finishes below its starting point.

1 caveat: saying that a system is “profitable” or “unprofitable” isn’t e’er genuine. Often, systems are (un)profitable for periods of time based on the market’s “mood,” which can follow a number of nautical chart patterns:

A few trends in our algorithmic trading example.

Parameter Optimization, and its Lies

Although backtesting had made me wary of this FX robot’s usefulness,
I was intrigued when I started playing effectually with its external parameters and noticed large differences in the overall Return Ratio.
This detail science is known as
Parameter Optimization.

I did some rough testing to try and infer the significance of the external parameters on the Return Ratio and came up with something similar this:

One aspect of a Forex algorithm is Return Ratio.

Or, cleaned upwards:

The algorithmic trading Return Ratio could look like this when cleaned up.

You may recollect (as I did) that y’all should employ the Parameter A. But the determination isn’t as straightforward as information technology may announced. Specifically, note the
unpredictability
of Parameter A: for small error values, its return changes dramatically. In other words, Parameter A is very likely to over-predict future results since any uncertainty, whatsoever shift at all will result in worse operation.

But indeed, the future is uncertain! And so the render of Parameter A is as well uncertain. The best option, in fact, is to rely on unpredictability. Oftentimes, a parameter with a lower maximum return but superior predictability (less fluctuation) will be preferable to a parameter with high return but poor predictability.

The only thing you tin be sure is that yous don’t know the future of the market place, and
thinking you know how the market is going to perform based on by data is a error.
In plow, you must acknowledge this unpredictability in your Forex predictions.

Baca juga:  Best Time To Trade Binary Options In Singapore

Thinking you know how the market is going to perform based on by data is a fault.

This does non necessarily hateful we should use Parameter B, because fifty-fifty the lower returns of Parameter A performs better than Parameter B; this is just to show you that Optimizing Parameters can outcome in tests that overstate likely time to come results, and such thinking is non obvious.

Overall Forex Algorithmic Trading Considerations

Since that showtime algorithmic Forex trading experience, I’ve built several automated trading systems for clients, and I tin can tell you that there’s always room to explore and further Forex analysis to be done. For example, I recently built a system based on finding and so-called “Big Fish” movements; that is, huge pips variations in tiny, tiny units of time. This is a discipline that fascinates me.

Edifice your own FX simulation system is an first-class option to learn more about Forex market trading, and the possibilities are countless. For case, you could try to decipher the probability distribution of the toll variations as a office of volatility in one market (EUR/USD for instance), and maybe make a Monte Carlo simulation model using the distribution per volatility state, using whatever degree of accurateness you want. I’ll leave this equally an practice for the
eager
reader.

The Forex globe can be overwhelming at times, but I promise that this write-up has given you lot some points on how to start on your own Forex trading strategy.

Further Reading

Present, in that location is a vast pool of tools to build, exam, and amend Trading System Automations: Trading Blox for testing, NinjaTrader for trading, OCaml for programming, to proper name a few.

I’ve read extensively about the mysterious world that is the currency market. Here are a few write-ups that I recommend for programmers and enthusiastic readers:

  • BabyPips: This is the starting point if you don’t know squat about Forex trading.
  • The Style of the Turtle, past Curtis Faith: This 1, in my stance, is the
    Forex Bible. Read information technology once you have some experience trading and know some Forex strategies.
  • Technical Analysis for the Trading Professional — Strategies and Techniques for Today’southward Turbulent Global Financial Markets, by Constance K. Brown
  • Expert Advisor Programming – Creating Automatic Trading Systems in MQL for Meta Trader 4, by Andrew R. Young
  • Trading Systems – A New Approach to System Development and Portfolio Optimisation, past Urban Jeckle and Emilio Tomasini: Very technical, very focused on FX testing.
  • A Step-By-Stride Implementation of a Multi-Amanuensis Currency Trading System, by Rui Pedro Barbosa and Orlando Belo: This one is very professional, describing how you might create a trading system and testing platform.

Source: https://www.toptal.com/data-science/algorithmic-trading-a-practical-tale-for-engineers