Day Trade Gold With 3 Easy Lines of Code



  • Home
  • /
  • Blog
  • /
  • Day Trade Gold With 3 Easy Lines of Code

Day trading gold is usually a fool's errand, but with these exact and repeatable rules, you can pull in huge profits week after week.

With a strange price fluctuation and 3 unbelievably simple lines of code, you can turn the gold market into your very own mint.

This phenomenon in gold is so unique that I haven't seen anyone else talk about it online and I almost completely missed it myself.

Buckle up, it's time for some data mining and coding!


This Price Anomaly Unlocks The Treasure Chest

If you've read some of my other posts, you'll know I always test my trading ideas first before risking a dime; and I highly recommend you do the same.

(It's your hard-earned money on the line after all, why not be extremely thorough?)

But before I can test if an idea will make or lose money, I first must come up with a trading hypothesis.

All my systems start with observations about the way prices move, and in 2012, I started noticing that gold's price would often rise Friday afternoons.

Maybe funds were hedging their bets over the weekend, or maybe foreign governments were executing their gold purchase plans.

I try not to think too much about the "why" something is happening - I just want to make money.

So, I dived deeper into gold's Friday price movements using scientific analysis not "technical analysis" (which doesn't work).

Gold Day Trading Strategy

Scientific Analysis of Gold Price Movements

Using my computer science background, I wrote a simple program to calculate gold's hourly percentage movements.

I then ran this program over every Friday all the way back to 2002, and the results I averaged together.

I wanted to quickly validate if there was a time of day on Friday that had a bias to the upside.

This is what my program spit out (gold futures trade around the clock):

gold time of day returns

Gold's Time-of-Day Gains

The computer told me there was a small window of time on Fridays when gold prices would rise.

This window appeared to be from around 3 pm to 5 pm local exchange time.

(Gold is traded at the CME in Chicago so local exchange time is US Central Time).

If you couldn't tell, I'm a big fan of "tested analysis" not "technical analysis".

I tell other traders all the time to run away from anyone drawing lines on charts - you need to be more scientific if you want to make the big bucks.

Day Trade Gold Using Data Science

Call me a groupie.  

I cannot overemphasize this; I can't get enough of testing trading ideas.

It's the main reason I don't trust a word of what other traders say because 99% of them never test a damn thing.

And sadly, most Mom and Pop traders haven't adequately tested their ideas either because their trading rules are simply too loose, too subjective, too haphazard, and sad to say, downright hopeless. 

The majority of traders are completely misguided as to the inner workings of the financial markets. 

(Much like people used to think that the earth was flat, most traders believe prices are moved by fundamental information).

The solution is for more traders to get out of their own way.

They need to let a computer find trading systems and prove they work first.

That's exactly what the most successful traders in the world have done and continue to do.

What's the Best Time to Buy Gold?

The results of my first program said there was a window of time that gold prices might rise.

But at exactly what time was the best to buy gold for a day trade?

Once again, I went to the keyboard and wrote up another program.  

This one stepped through each 15-minute period of each Friday looking for the optimal time to buy gold.

The output of this code said that 2:15 pm (14:15) local exchange time was the best (US Central time).

What does that look like in simple pseudo-code?

	If time >= 14:15 and

Gold Needs to Be Trending Higher

At first, however, I was not too impressed with the results of day trading gold at 2:15 pm.  

There were too many times gold would fall instead of rise through the rest of Friday afternoon.

So, scratching my head a little bit, I hypothesized that if gold is a trending market (i.e., it likes to move in one direction for a period of time) that maybe I should only buy gold if it is already moving higher.

A very simple way to determine if something is moving up or down is with a moving average.

In this case, I used a simple moving average and told the computer to only buy gold on Fridays at 2:15 pm if the price was above a simple moving average.

	If price >= average(107, close) then

When To Sell Gold?

Lastly, I needed to know when to sell gold.

I've often noticed that it's easier to buy something than it is to sell it.

Maybe you've felt the same way before.  

How many times have you held onto a position longer than you should have?

It's the selling part of trading that's so hard to do, and why so many traders get into serious trouble.

So once again, I made the computer tell me when I should sell.

I didn't want to "eyeball" the charts and guess.

I wanted to know exactly, in black and white, when I should sell the shares of gold I had bought at 2:15 pm Friday afternoon.

After running the simulation, the program said 6:15 pm Sunday evening was the best time to sell.

	If time >= 18:15 then

Let's put all this code together and see what this day-trading gold system looks like.

Gold Day Trading System Overview

Gold Day Trading Strategy

You don't need to hit a few trading grand slams to make a fortune.

All you need are small base hits.

Conclusion: How to Day Trade Gold

Gold Weekend Day Trading Strategy Performance Report 2024
Gold Weekend Day Trading Strategy Statistics 2024

This system is unbelievably simple.

My philosophy is always "the simpler the better"!

Simple works and simple is robust.  

Robust systems are more likely to continue working in the future.  

There is a repeatable upward bias in gold Friday afternoons into Sunday evenings and you can use the above simple rules to exploit the phenomenon.

Happy Trading!

Want The Full Code?

Start using this strategy today!

About the Author

Hello! I'm Kurt, the "Relaxed Trader" writing the stuff on this website. Shoot me an email at or leave a comment below. Cheers!

  • Anonymous says:

    Hi Kurt. Really nice articles you are posting here love them all !!! Which moving average would you recommend?
    sma(20), sma(50) or sma(200) ?

    would really be appreciated if you could answer this question.

    • Hi John.
      Try the 107 SMA.
      It seems to work the best for now, but you will need to out-of-sample test once a year to make adjustments to changing market conditions.

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}