Neural Transformer
- Asesores Expertos
- Evgeniy Scherbina
- Versión: 1.0
- Activaciones: 10
The "Neural Transformer" expert is a fully automated expert which is ready to trade on the daily timeframe with 2 symbols: GBPUSD and USDCAD.
In addition to this, you can train the expert to trade on any timeframe with any symbol. The expert will automatically pick up the files of your new customized neural network.
The "Neural Transformer" has made training neural networks for Forex an easy and exciting process! Currently, I am offering one type of network - LSTM. It is the most popular neural network for classifying and forecasting timeseries data. I am going to add 2 other types of networks in the nearest future: Multi Head Attention and ATFnet (the most advanced and controvercial type involving Fourier transform and complex numbers).
Trading
The expert is ready to trade on the daily timeframe with 2 symbols: GBPUSD and USDCAD. If you have done another training, start the expert with the property Action = Trade. And that's it.
Training (check the pictures)
An example of EURUSD training, timeframe D1
1) Collection of data is done in the Strategy Tester
Select the following options in the Strategy Tester:
Expert: Neural Transformer
Symbol: EURUSD
Date: 2004.01.01 - 2024.04.01
Modelling: Open prices only
Select the following options in the inputs of the expert:
Action = Collect_data
Timeframe = D1
Number of bars = 30
Number of forecast bars = 20
Other options do not matter for collecting data. The option "Open prices only" allows collecting data for seconds. Other values of this option do not improve data, but may significantly increase the execution time.
Click "Start" in the Strategy Tester to collect data.
There will appear 2 records in the log of the Strategy Tester after several seconds: "Training complete EURUSD D1 LSTM | patterns 5261" and "Collect_data file saved to ..."
You can open the data file and inspect it in the indicated location.
2) Training is done in the Strategy Tester
Select the following options in the inputs of the expert:
Action = Train
Timeframe = D1
Number of bars = 30
Epochs = 1000
Number of LSTM layers = One
Number of Dense layers = One
Learning rate = 0. 01
Decay for Learning rate = 0.1
Patience = 50
Neurons per layer = 32
Validation percent = 0.2
Other options of the expert do not matter for training.
Click "Start" in the Strategy Tester to start the training.
As a rule, training takes several minutes. There will be different records in the log of the Strategy Tester.
"Epoch 10 >> time 0.48500 sec | loss 0.50258 | custom_err 0.99484 <> 1.00055"
"New lr 0.00729 at epoch 138"
"Best configuration at epoch 422 >> training stopped"
There will appear other files of the training after the training is complete, in the same location where the data file was stored.
3) How to check the training in the Strategy Tester
Select the following options in the Strategy Tester:
Expert: Neural Transformer
Symbol: EURUSD
Date: 2020.01.01 - 2024.09.10 (or the current date)
Modelling: OHLC на М1
Select the following options in the inputs of the expert:
Action = Trade
Timeframe = D1
Forecast minimum = 0.5
Symbol point = 0.0001
Trading start hour = 4
Takeprofit = 400
Trail = 100
Volume = 0.01
Number of bars = 30
Other options do not matter at this step.
Click "Start". The expert will do a usual test.
Warning! I do not recommend doing an optimization with this expert in the Strategy Tester. The expert loads many complex classes. An optimization with this expert may end with a MetaTrader crash. If it is the case, simply restart the MetaTrader. I am working to fix this bug and make optimizations stable. Testing works as usual.
Properties of the Expert
Standard Properties
- Action >> there are 3 actions: Trade, Collect_data, and Train.
- Network type >> it currently features only one type - LSTM. It is the most popular approach to training timeseries data. I am going to add 2 other types in the nearest future: Multi Head Attention and ATFnet.
- Timeframe >> this should be identical for your training and trading.
- Forecast minimum >> values over this value trigger trading signals. The bigger is the value, the less trades there are. Valid values: 0.05 to 1.5.
- Symbol point >> it is used to calculate price moves. For example, for GBPUSD, EURUSD and most other symbols, it is 0.0001. USDJPY - 0.01; USDSEK and USDNOK - 0.001; XAUUSD - 0.2.
- Trading start hour >> new trades are opened after this hour. It is used to skip price gaps which may take place over night.
- Takeprofit
- Trail
- Stoploss
- Volume >> volume per trade. Fixed volume (example: 0.02) or percentage of available funds (example: 0.015%). The expert prints the real volume in the "Expert" tab when starting or changing the timeframe. Always use a fixed amount for accounts that use a deposit currency other than the US dollar (i.e. euro, yuan, bitcoin, Australian dollar, etc.).
Training Properties
- Number of bars >> bars to analyze to make trading decisions.
- Number of forecast bars >> bars ahead to decide which direction the price will go.
- Epochs >> it is a max number. A training of a neural network is done in epochs. As a rule, a training is stopped long before this value is reached.
- Number of LSTM layers >> an architecture of a neural network has LSTM layers which are used to learn dependencies among bars. Dense layers, which follow LSTM layers, are used to learn dependencies common for all bars.
- Number of Dense layers
- Learning rate >> this impacts the calculation of an error during training. A big value cause the training to develop in leaps and end quickly. A small value causes the training to develop slowly and never reach an optimal state.
- Decay for Learning rate >> if a training does not improve, this property decreases the Learning rate according to this formula: lr = lr - lr*decay. This helps push a training in the right direction.
- Patience >> it is a number of epochs to wait for an improvement. A training goes on while a validation error improves. The expert pushes forward the training for this number of epochs because it expects a validation error can still improve. If an improvement does not show up, the last best state of the neural network is saved.
- Neurons per layer >> the more is this number, the longer is the training and the faster is the addiction to data. You should be looking for an optimal number of neurons.
- Validation percent >> 0.2 stands for 20%, 0.3 for 30% etc. All data is divided into 2 sets: training and validation. Validation should be smaller than training.