Home Forex Forex Videos Forex Trading Algorithms Part 1-Converting Trading Strategy To EA’s & Running Tests...

Forex Trading Algorithms Part 1-Converting Trading Strategy To EA’s & Running Tests On Profitability


Trading Algorithms –  An Introduction


Almost all traders, novices and pros alike, know at least the basics of technical analysis. Still, not many know how to convert a trading idea into a set of rules and then test them for profitability.  This video series aims to be an introduction to algorithms applied to trading. Even if you are not considering creating one EA or trading bot, we think it is very interesting to be proficient in converting your trading idea into formal code and test it. We will use mostly pseudo-code, but also python, a very easy-to-learn but powerful high-level language, and Easylanguage, developed by Tradestation, which is almost as pseudo-code because it was designed to be read as a natural language.


What is an algorithm?

An algorithm is a set of rules to perform a task in a finite number of steps. Basically, an algorithm is a recipe.


For example, if we were to create an algorithm to make a phone call manually. A possible solution could be this :

1.- Open the phone
2.- select the keyboard
3.- dial each number from left to right
4.- Click the green phone icon
5.- Hear the calling sound

6.- Busy tone?
    A- no ---> wait  60 seconds for the answer.
        Did somebody answer?
                Yes--> Start a conversation
                    I - Conversation ended?
                            Yes --> Hang up.
                No --> Hang up
    B- Yes ---> Wait 120 seconds and go to 4th step

Algorithms  used in Trading

There are many ways to create Trading algorithms, including advanced sentiment analysis, evaluating the words used in trading forums and news releases. Still, we will focus on algorithms for historical price action data series.

 The ability to create, test, and evaluate a trading algorithm is a terrific ability to own. This allows creating market models that map and profit from the market’s inefficiencies. If you happen to find one set of rules that historically made profits, it could likely continue making profits in the future. This is the basic premise of automated algos, expert advisors, and trading bots.


Algorithm properties

  • Inputs: zero or more values can be externally supplied. Some algorithms don’t need inputs, although the majority will, and of course, a trading algorithm will need to get timely data from the market to generate outputs.
  • Outputs: at least one result should be delivered. That is logical. The output may not only be a text. It can be a picture, a sound, or a market trading order.
  • Unambiguous: Each instruction must be explicit, with a single meaning.
  • Finite: It ends after a limited number of steps.
  • The algorithm should precisely specify what the computer should do. The computer is not smart. It is dumb. You should tell it precisely the action it has to make.
  • Effective: Every instruction should be basic enough to be made by hand or uses other algorithmic sub-units with the same property. Of course, the action must be feasible, which means the computer can perform that action because the instruction is included in the instruction set of the programming language you’re using.

The key to a good algorithm, as with recipes, is to break the ideas down into simple building blocks.

Flow Diagrams

Algorithms can be more complicated than a simple recipe. Besides, a recipe is interpreted by a (supposedly) intelligent cooker. On the other hand, algorithms are to be interpreted by brainless CPUs. Besides, algorithms usually accept a stream of data inputs, which must be transformed until an output or output is produced.  Flow diagrams are a pictorial representation of the algorithm’s process and data flow.

A Flow diagram is a very handy tool to develop your ideas into coherent algorithms because it helps you spot potential flaws and improvements and should be the first step before proceeding to the actual code.


In the next chapters, we will continue developing this basic idea, applied to trading, using trading examples.


Further reading:

The Ultimate Algorithm Trading Toolbox, by George Pruitt.



Please enter your comment!
Please enter your name here