SkillAgentSearch skills...

Strategies

Custom trading strategies using the freqtrade framework

Install / Use

/learn @nateemma/Strategies
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Phil's Custom freqtrade Crypto Trading Strategies

I am only periodically developing these strategies because - work, family etc...

I recently re-organised all of the strategies. Originally, they were in exchange-based folders (binanceus etc.). This became unwieldly, plus it is now difficult to use multiple exchanges anyway. So, I have moved all of the strategies into new directories based on the underlying family (or group), such as Anomaly, PCA, NNPredict etc. <br>

tree -d -L 1
.
├── Anomaly
├── NNPredict
├── NNTC
├── TSPredict
├── archived
├── binanceus
├── config
├── hyperopts
├── reference
├── scripts
└── utils

archive contains abandoned strategies (which are still sometimes useful for cut & paste) <br> binanceus is a remnant from when I was running with multiple exchanges (which no longer seems possible). I no longer develop here, but left it for reference

NOTES:

  • Scripts: All scripts (in user_data/strategies/scripts) have been updated such that they now take the group name (but the old exchange method will still work)

  • Binance: I live in the USA, and the most exchanges recently blocked API access from here. So, I cannot ( easily) test the code in any other exchange. I know I could use a VPN, but I'm busy with a bunch of other stuff - sorry. <br> All strats should work, but you will need to run hyperopt on them to get good hyperparameters

  • Mac M1: My development machine is a Mac M1 laptop. While it is very fast, it does present some challenges in terms of packages. See here for more details.<br> As an aside, all of my scripts are written for zsh, not bash (this is the default shell on MacOS, plus the version of bash that is pre-installed is very old)

  • NNPredict: this uses neural networks to predict changes in the price of a pair. Timeseries prediction is a cutting edge problem, and I do not appear to have solved it! These algorithms perform OK in backtesting, but if you look at the details, the predictions are not good. <br>So, I am currently not working on these, but I may circle back and apply lessons learned from te NNTC work

  • Tensorflow: several strategies use neural network models implemented using tensorflow (and keras). For some reason, the latest versions of tensorflow dropped support for serialisation of models (at least on MacOS), so hyperopt of these strategies no longer works (because hyperopt saves and restores the strategies via pickle).

Intro

This folder contains the code for a variety of custom trading strategies for use with the freqtrade framework.

Please read through the instructions at https://www.freqtrade.io before attempting to use this software.

Note: I have tried many different strategies, most of which perform quite badly or inconsistently. The abandoned strategies are in the archived/ folder for reference (I sometimes cut & paste pieces of them into new strategies).

I currently focus on strategies that revolve around one of several approaches:

  1. creating a model of the expected behaviour and comparing it to the actual behaviour. If the model projects a higher price (above a certain margin) then buy, similarly sell if the model predicts a lower price. There are variants that use Discrete Wavelet Transforms (DWT), Fast Fourier Transforms (FFTs) and Kalman filters. The DWT variants seem to perform the best (and are the fastest).
  2. Use Principal Component Analysis (PCA) to reduce the dimensions of the dataframe columns, then use that to train classifiers, which are then used to predict buys and sells. The PCA analysis is pretty cool because you just add indicators and let the PCA reduction figure out which of them are actually important.<br> Note that this is quite similar in approach to freqAI, but I started it before I knew about that, so just kept going (because I find it interesting).<br> All of the PCA logic is contained in a base class named PCA. There are several variants (prefixed with PCA_) that try out different approaches to identify buy/sell signals that are used for training the classifiers.
  3. Use Neural Networks to create trinary classifiers that return a buy/sell prediction.<br> Logic is very similar to the PCA classes, and the base class is NNTC (Neural Network Trinary Classifier). The internals are a little more complex because the Neural Network code works with 'tensors' rather than dataframes. These have to be trained over long time periods because there aren't enough buys/sells otherwise. Models are saved in the models/ directory and will be used if present.
  4. Neural Network prediction models (NNPredict_*.py)<br> Similar to NNBC, but predicts an actual price, rather than a buy/sell recommendation. Same issues as NNBC
  5. Anomaly Detection (Anomaly.py)<br> The main issue with using neural networks is that there are not many buy/sell recommendations relative to the number of samples (typically about 1%). This approach uses various anomaly detection algorithms by training them on historical data, which will mostly model the normal cases (no buy or sell). Then we run it against actual data and anything identified as an 'anomaly' should be a buy or sell.<br> I also combine this with various compression techniques, such as PCA, to make the anomaly detection algorithms more efficient.

For the approaches that use Neural Networks (usually with 'NN' somewhere in the name), I have started saving and reloading models, which are in the models/ subdirectory of the exchange folder. These are created by running backtest over long periods of time, and are then loaded and reused in any other mode (hyperopt, plot, dryrun etc)

All of these strategies use the custom sell/stoploss approach from the Solipsis strategy (by werkrew). This makes a huge difference in performance, but the downside is that each strategy requires a lot of hyperopt-ing to get decent performance. Also, I am suspicious that the custom stoploss code is over-fitting, because it has such a drastic effect on performance and because it doesn't seem to work the same way in dry runs.<br> I am currently trying to find a simpler custom stoploss approach that transfers better to a live environment (look in Anomaly.py)

Disclaimer

These strategies are for educational purposes only

Do not risk money which you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.

Always start by testing strategies using backtesting then run the trading bot in Dry-run mode (live data but simulated trades). Some instructions on how to do this are provided below. <br>Never, ever, go to live trading without first going through a dry-run - it is not at all uncommon for a strategy to achieve fantastic results in backtesting, only to perform very badly in a live situation. The main reason for this is that the backtesting simulation cannot reproduce the behaviour of the live environment. For example, real trades take a relatively long time and the price can move significantly during that time. Also, market conditions such as trading volume, spreads, volatility etc. cannot be reproduced from the historical data provided by the exchanges

Do not engage money before you understand how it works and what profit/loss you should expect. Also, do not backtest the strategies in a period of huge growth (like 2020 for example), when any strategy would do well. I recommend including periods where the market performed poorly (e.g. May, Nov and Dec 2021)

List of Strategies

The following is a list of my custom strategies that I am currently testing.

| Strategy | Description | |-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | DWT | Model behaviour using a Digital Wavelet Transform (DWT) | | DWT_short | Same as DWT, but with shorting added | | FFT | Model behaviour using a Fast Fourier Transform (FFT) | | FBB_* | Adds Fisher/Bollinger band filtering to DWT/FFT/Kalman | | Kalman | Model behaviour using a Kalman Filter (from pykalman) | | KalmanSIMD | Model behaviour using a Kalman Filter (from simdkalman) | | PCA_* | Uses Principal Component Analysis (PCA) and classifiers trained on prior data to predict buy/sells. Each PCA_* variant uses a different approach to predict buys/sells. | | NNBC_* | Neural Network Binary Classifiers - approaches to predict buy/sell events | | | NNTC_* | Neural Network Trinary Classifiers - approaches to predict hold/buy/sell events |

View on GitHub
GitHub Stars419
CategoryDevelopment
Updated9h ago
Forks113

Languages

Python

Security Score

80/100

Audited on Apr 2, 2026

No findings