A Beginners Guide to Forex Trading Bots and Python – Pivot Point Theory

Rate this post
A Beginners Guide to Forex Trading Bots and Python - Pivot Point Theory

We are going to stick with Python and trading basics for one more lesson, and then we will have to kick it up a notch to move forward.  So I want to make sure you have a good foundation and are doing your work to get ready.

Intro Requirements for Forex and Python

Moving forward in this series, it will be very helpful if you have done a few of the things we have talked about in the first two lessons.

We have been pushing hard in the first two lessons, and I want to step back and take a breath – then press on again in the next breath!

What Are the Basics of Python?

Syntax – Python uses indentation to construct the code, not the usual semicolon you may have seen in other languages.

This makes Python very readable and maintainable.

Comments – We have talked about the simplicity of Python comments in previous examples, and if you don’t understand docstrings take another look at those.

Keywords – Memorizing the list of Python keywords is a great place to start learning.  Take each one and play with it to see what it does.

Variables – Creating clear and concise variables is another awesome feature of Python, making code understandable to others reading it.

Data Types – Including ints, strings, floats, Booleans, etc.

I hope you’re feeling comfortable in these areas –   we are going to clarify a few of these things as we go through this lesson.

Pivot Point History and Forex

The world of trading is completely different now than it was twenty-five years ago – but then what isn’t?

Have you ever seen a movie that shows the chaos of the trading pit in the old days?

Pit traders would calculate the pivots on the back of their cards and then have an idea of where they would like to buy or sell in the next period – the next day.

Those days are all but gone, and the trading floor looks more like a Silicon Valley software geek hangout.

But the pivot points still live on.

I have to warn you about three things here:

  1. Pivot points are not a trade signal.
  2. I learned pivot point theory from someone who figured it out on his own, so it may not look like anything you’ve seen before.  And I don’t take his advice, I use them my own way.
  3. Most of what you will find online about pivot points is garbage.

My First Python Code for Trading

Shortly after I began learning Python, I was working on my long-term trade plans for the coming year.

 It was New Year’s Eve, and I was using the down time over the holiday to calculate the following year’s pivot points. 

I had my pen, paper, and calculator out, (prehistoric, right?) and was plugging away when it hit me – “I could write a short bit of code and save all this time.”

It would take me about twenty minutes per pair and at that time I was doing all 28 of the majors.

So, here is the code that saved me 18 minutes per pair x 28 pairs. (8.5 hours!)

Don’t laugh, I had been learning Python for two weeks, and besides – it worked!

Code:

# 2021-22
H = 1.2347        #High
L = 1.1186        #Low
C = 1.1377        #Close

There is no output here, I’m just setting the variables and then I updated the numbers for 2021-22.

First, we calculate the central pivot point by adding the High, Low, and Close and then dividing the total by 3 – creating a weighted average.

1.1636666666666666  # We will use four decimal places - 1.1636

All the other pivot points are calculated off the CPP

Next, we will calculate the range.

RANGE = H - L             #Difference between high and low
print(RANGE)
# 0.11609999999999987  # we will round down to 4 decimal places again - .1161

Note: The range from high to low for this time period is 1161 pips.

Now let’s calculate the other pivots.

S1, S2, R1, R2 – two support pivots and two resistance pivots.  There are more, but these are the ones I use the most.

S_1 = 2 * CPP - H         # Support level 1
print(S_1)
# 1.0926333333333333
S_2 = CPP - RANGE         # Support level 2
print(S_2)
# 1.0475666666666668
R_1 = 2 * CPP - L         # Resistance level 1
print(R_1)
# 1.2087333333333332
R_2 = CPP + RANGE         #Resistance level 2
print(R_2)
# 1.2797666666666665

Points to Consider Before We Go to the Charts

  • I’m going to do all the info on forex in the video portion of the lesson from now on, it just works better, and frankly, is more fun if we are on live charts.
  • Pivot points are a leading indicator and should be used as an area of interest where you can potentially ambush price.
  • Pivot points are one piece of the puzzle, and should be combined with other analysis and indicators.  We’ll cover that on the charts.
  • One of my favorite indicators to use with the bots is the KD – “Knoxville Divergence”, created by Rob Booker. 
  • Everything in these lessons is for educational purposes only.  Nothing we do, no matter how usable it may seem, is meant to be taken as a stand alone trading system.  Even the training I received from Rob has been altered to fit my system and trading style.
  • When trading –   stay small, stay humble, and never risk money you cannot afford to lose.
  • Keep killing it with Python, math, and your coding career.  It’s our responsibility to contribute to the Universal collective intelligence through continuous incremental improvement – known as “Kaizen” to the Japanese – martial arts wouldn’t be bad to add to your learning mix!