A Beginners Guide to Forex Trading Bots and Python

What You Need to Know Before You Begin

I was trading forex bots long before I started learning Python.  When I look back on the experience, I wish I had done it in reverse.

There are three basic reasons:

  1. Learning to code with Python is easier.  I know it’s hard to believe, but it’s true.  If you learn some Python you can start freelancing and start making some money pretty quickly. (I’m assuming you are interested in Forex to make money)
  2. If you’re new to Forex and trading with bots, you are going to lose money.  It’s a steeper learning curve and will take longer to get educated.
  3. Knowing how to program is an essential skill if you are going to be using robots to trade.

In this introductory lesson, I’m going to share some resources that will get you off to a solid start.

Start Learning Python Now

There’s a saying that “The best time to start was ten years ago – the second best time is RIGHT NOW.”

If you are completely new to Python – read on – then COME BACK HERE.

BONUS: Even though you may be a beginner, I’m going to give you the benefit of the doubt and assume you are serious about digging in.

One of the main Python features that you will use in programming your bots is the function.

💡 Python function – “A block of code designed to perform a computational task that can be used many times without writing the entire code again and again.”

Let’s write some code to define our own function.

Simple Python function code:

def sum(x, y):
    return x + y

We have defined a simple function named sum with 2 parameters (x, y) followed by a colon :, and we want it to return the sum of x and y.

Now, let’s call our function using its name and entering 2 parameters

sum(5, 5)

Output:

10

Can you see the power even in this simple function?  Anytime I want to sum, instead of two short lines of code, I have a tiny snippet.

Apply the K.I.S.S. principle when you can – “Keep It Simple Sweetie” (I used your mom’s version).  Everyone wants to show off –  but with Python, the simpler and cleaner, the better.

“The Art of Clean Code”  by Christian Mayer

Let’s try one more that’s a bit more advanced.

We will need the math module for this example.

import math
math.pi                 #returns Pi (the hash in front creates a comment)
# 3.141592653589793

def volume(r):
    """Returns the volume of a sphere with radius r."""  #docstring
    v = (4.0/3.0) * math.pi * r**3
    return v

Now let’s call our volume function with parameter 2 for radius

volume(2)

Output:

33.510321638291124

There’s a lot for you to digest here, but I assure you, with some consistent practice you will get this in no time.

The other thing to note here is Python’s powerful math abilities.  It is one of my favorite things about the language, and if you are going to trade or program robots, you are going to use a TON OF MATH!

Introduction to Forex Trading and Bots

This is a starter list of subjects with brief descriptions that you can use as a guide.

🌍 Financial literacy.  Learn what you and most others don’t know – Financial Literacy – Overview, Benefits, Importance (corporatefinanceinstitute.com).

 Statistics show that 66% of adults in the U.S. are financially illiterate. (Source)

  • What is Forex?  Forex is short for foreign exchange, and is the largest and most liquid market in the world
  • How do I find a broker?  I suggest that after you find some good mentors that you trust, take their advice and then do your own research.
  • Technical vs Fundamental analysis.  This subject is as controversial as whether or not to use robots.  Study hard, and draw your own conclusions.  This will get you started.

One of my mentors had a slide that read “Everything Works, and Nothing Works.” 

I took this to mean that what works for you may not work for me, and vice versa.  This is why I stress that you must make your own decisions. (and realize the internet is filled with crap!) 

  • Leverage and Margin.  I saw a YouTube title the other day that read “$200 to $190k in 4 hours!”  I’d like to translate that for you: “$200 to Broke in 5 seconds, my account blown up, and my Forex career over in 4 minutes.”  Don’t fall for it – Lose the lottery mentality!
  • Chart Styles.  Bar charts, line charts, or candlestick charts – this is a matter of preference.  I prefer candles because they are very visual and tell a complete story.
  • Indicators.  Leading or lagging?  Some examples of lagging indicators are moving averages, MACD, RSI, and Bollinger bands.  They’re lagging because they are created by, and follow price movement.  My favorite leading indicator by far are pivot points, and second is Fibonacci tools.
  • Know Your Platform.  The most popular platform is called mt4, and it provides an amazing array of capabilities.  I’ve seen a lot of traders that have no idea about what they can do with their charts.  Learn your platform thoroughly. 
  • Be Patient.  If you get in a hurry you will most likely be slaughtered and someone else will have your money in their account.  It took me a year to decide on the mentors I wanted to work with and to find my main broker.  Slow and steady wins this race.

One Last Point on Forex Trading (with or without bots)

Most people think they know what money actually is, but the truth be told, I believe that the 66% figure of financially illiterate is quite low.

Don’t be that trader.  Get an alternate education:

 

The Bottom Line

No matter how you envision your future, it’s only going to be what you want it to be if you take action.

Lots of people dream about how things can be, but they never take action and never get things done.

Take whichever parts of this article resonate with you and your goals and just get started.

CONSISTENCY!  Spend some time every single day – even if it’s ten minutes – coding Python, working math puzzles, researching Forex, and building your own freelance business.

CHALLENGE:  Do this every day for 90 days.  Don’t skip weekends, holidays, etc. – make it a game!  You are going to do other habits for that time, just add these to them.

Eat – then a new habit. 

Brush your teeth – then study.

Read about Python or finance – then play a video game.

You get the idea!

This is just the tip of a massive iceberg of knowledge that trading and Python have to offer – and that should keep you excited for years to come.

Come back to this article and its resources whenever you need encouragement and we will see a new you in 90 days!

In the second article, I will discuss APIs, strategies, more Python, and getting started coding the bots, as well as more information on trading fundamentals.

Programmer Humor

Q: What is the object-oriented way to become wealthy?
💰

A: Inheritance.