This repo houses python code about topics related to testing, trading and researching forex strategies. The code can be adapted for cryptocurrencies or other tradable asset classes.
- Testing Forex Strategies
- Support and Resistance
- 20 pips challenge
- Automate Chart Patterns
- MACD
- Short Content
- Retracement
- Code Trading
- Data
- License
- Contact
- Buy me coffee
- Disclaimer
Please note this section was rewritten with ChatGPT, May 3 version.
Hey there! I'm always on the lookout for fresh and exciting ideas to try out. That's why I spend a good chunk of my time diving into books, blogs, papers, and even watching YouTube videos for some strategy inspiration. It's amazing how much you can learn from these sources!
Speaking of strategies, I've collected a bunch of Python code in this folder. These are strategies that I stumbled upon during my research and thought they were worth putting to the test. I've even categorized them for easier navigation:
-
First, we have strategies I discovered on YouTube. You know, those hidden gems shared by 'experts' in the field.
-
Then we have strategies from books, because there's nothing like some good old-fashioned wisdom between the pages.
-
Of course, I couldn't miss out on strategies that were requested by fellow enthusiasts. It's always interesting to explore new ideas brought to the table.
-
Next up, we've got strategies from blogs, where some fantastic minds share their insights and experiences.
-
Last but not least, we have chart pattern strategies, because patterns in the charts can hold valuable clues for successful trading.
If you're curious and want to take a peek at the details, I've got you covered. Just head over to the project's documentation here. Feel free to explore and let me know if you have any questions or suggestions!
Below we show the current top 10 results. Please note the following:
- Starting balance: $10,000
- Margin: 1:100
- Commission: None
- Testing period: From January 1, 2020, to December 31, 2022
- Timeframe: 15 minutes
- Currency pair: EURUSD
- Data Source: Dukascopy
Also note the limitations outlined in the documentation.
![top-10-results](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/top-10.png)
Are you interested in effortlessly uncovering support and resistance levels? We've got you covered! We've gathered a bunch of awesome techniques we discovered online to automate the detection of these crucial levels. Right now, we've got nine fantastic methods to share with you, but don't worry, we're always on the lookout for more and will keep expanding our collection.
Take a peek inside this folder, and you'll find all the code for these incredible methods. It's like having your very own treasure trove of support and resistance detection tools!
Here is a list of the methods:
-
Traditional
-
Fibonacci
-
DM
-
Caramilla
-
Kmeans Clustering
-
Agglomerative Clustering
-
Density 1
-
Density 2
-
Fractals
Our aim is to create a python package called supportresist
that will make it easy to compare and detect support and resistance levels. Here is a link to the YouTube video going through the methods and their results.
This is the complete list of references that was were consulted.
You probably don't have $50 000, or $25 000 or $10 000 to start trading forex. Maybe we can start with $20 and grow it to over $50,000. The 20 pips challenge shows how you can grow your small account with at least 30 trades. See the image below.
![20-pips-challenge](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/20-pips.png)
This folder contains scripts that you can test to grow your $20 to over $50,000. You can check out the YouTube video here.
This is a scalping strategy from the "Moving Average" channel.
The strategy uses the Williams Fractals, the RSI and 3 moving averages, namely: the 21 MA, the 50 MA, and the 200 MA. The strategy is tested in the 15 min timeframe.
Here is another scalping strategy but from a different YouTube channel called CodeTrading. The strategy only uses three moving averages. The 50 EMA, the 100 EMA and the 150 EMA. It was tested in the 15-minute time frame.
In his book, Encyclopedia of Chart Patterns , Thomas Bulkowski says, "To knowledgeable investors, chart patterns are not squiggles on a price chart; they are the footprints of the smart money." Let's follow the smart money...
As the folder name states, it contains scripts that automate the detection of chart patterns. Several algorithms can be used to identify chart patterns. We have marked the ones we have used so far:
-
Pivot Points
-
Argrelextrema
-
Kernel Regression
-
Perceptually important points
-
Directional Change
-
Rolling window
-
Clustering Algorithms
The idea is to implement all of the above algorithms and produce a Python library called chart_patterns
. You can check out the YouTube videos discussing the patterns already automated
here.
You can check out the sample outputs below.
![head-and-shoulders](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/head-and-shoulders.png)
![inverse-head-and-shoulders](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/inverse-head-and-shoulders.png)
![triple-top-and-bottom](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/triple-top-and-bottom.png)
![rectangle](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/rectangle.png)
![wedge](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/wedge.png)
![flag](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/flag.png)
The script looks at the MACD strategy and tests it on 31 currency pairs. There are plenty of videos on YouTube on the MACD strategy. But there have the following in common:
-
The focus is on a single currency pair.
-
The backtest is applied in one timeframe.
-
The backtest ends on 100 trades.
We wanted to improve on this by doing the backtest on multiple currency pairs. On three time frames. And focus on more than 100 trades. You can watch the video here.
This folder has code that does not fit in other folders.
Please note this section was written by ChatGPT, Mar 23 version.
Are you ready to be blown away? This script is not your average run-of-the-mill program. It was inspired by a Reddit post that left many Forex enthusiasts in awe. That's right, we're talking about the one and only 47dollars!
This Reddit user calculated correlations for a whopping 47 currency pairs. And we thought that was impressive, until we decided to put our own spin on things. Our script, aptly named 42dollars, consists of 42 carefully selected pairs that will leave your mind boggled.
But wait, there's more! The script goes above and beyond by calculating a rolling correlation for each and every currency pair. That's right, you heard it here first. We're not just talking about static correlations, we're talking about correlations that evolve over time.
And to top it all off, we present to you a stunning heatmap of the results. It's like watching a work of art come to life before your very eyes. So buckle up and prepare to have your mind blown by the incredible power of the 42dollars script!
![Logo](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/heatmap-all.png)
You can also check out the YouTube shorts video of the final result.
This file calculates bullish candlestick patterns. Here are the candlestick patterns:
- engulfing
- harami
- dragonfly doji
- inverted hammer
- morningstar
Here is a YouTube shorts video to the results of the script.
Will the price bounce back? As traders we look for the levels prices will bounce back and continue its trend. These points of retracements can serve as good entry points to catch the trend.
We will use python to calculate different retracement levels. Currently the following have been implemented:
-
Distance
-
Fibonacci
-
DM
-
Caramilla
-
Moving Average
Here are the methods for calculating the pivot points:
-
High and Low (hilo)
-
argrelextrema (arg)
-
Fractals (frc)
-
Perceptual Important Points (pips)
Here is a plot of one result when condition
is set to fibonacci
:
![fibonacci-levels-retracement](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/fibonacci-example.png)
Here is a result when condition
is set to distance
:
![distance-levels-retracement](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/distance-example.png)
The results are not perfect. But we will continue to work on it.
The points found could potentially be reversals. To be "true" retracement points, the price has to be trending. There are many different ways to
measure or detect if price is trending. As an example we defined an upward trend
as being when the close is greater than the 10-period moving average.
A downward trend
as being when the close is less than the 10-period moving average.
Here is a gif of all the signals
:
![signal-gif-retracement](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/signal-gif.gif)
CodeTrading is a YouTube channel where the hosts tests different trading strategies. He also gives access to the code. We have decided to refactor the code and test them across different exits. Here is a gif for some of the results we found.
![code-trading-results](https://raw.githubusercontent.com/wenli/Trading-Code/main/images/code-trading-results.gif)
You can find the playlist were we found the strategies here. The channel is definitely worth checking out. Highly recommended
The data folder contains any files you will need to replicate the results found from testing, etc. This will usually be forex data you can download from Dukascopy.
You can use our python library forexpy to collect forex data from different sources.
Please note there is no affiliation with Dukascopy.
MIT
You can reach me at - info@zetra.io
If you feel like buying me coffee, here is the link. Thank you.
We want to emphasize that this is purely for educational purposes only. We do not offer any financial advice, recommendations, or make any guarantees of profit or success. Trading carries a risk of loss, and it is important to always consult with a qualified professional before making any trading decisions.