
Goals of this course
Disclaimer lecture
Main topics of this Section
Get prepared for the day/week
Read about the Programming Language
Learn about Trading Strategies
Read Threads and get involved
Open Codes from other programmers
Observations:
Remember that this section is an introduction to Tools and habits that you should use and implement in your everyday routines. In the next section, we will use some of them as I am going to explain some mechanisms of the expert advisors that we use. And help you think like an Algo trader!
Enjoy the classes!
Sometimes there is just not enough time to study all these techniques and real goal is to learn computer and data science...
Advantages:
Deploy in hours using Environmental Variables
Adapt and expand
All in ‘one place’
Description
Introduction to coding in MQL4... if one is serious about it - almost any idea can be implemented in code!
Lecture to explain components of the algorithmic trading system
MQL[C++] code may be hard as it is creating a level of 'abstraction'. This means that Programmer must keep in mind all the instructions while writing a code. This makes it difficult to supervise your work and even may lead to bugs. We don't want to waste our time by finding those bugs. This is an invitation for students to create a very basic test script to be able to test pieces of codes!
Simply test anything here! From definition of simple variables to testing for loops and functions...
Data Types:
bool
int
string
double
...
This is just needed to create our variables or sections in the memory. Our program will be able to operate them...
Getting the value from MQL4 function is probably the most common activity within any Trading Robot
Ability to define Conditions are the key to define trading robot logic
Rule of thumb:
Create function if you copy/paste code more than 3 times...
Save your functions inside …MQL4/Include/MyFunctions.mqh file
Refer to your functions using #include < MyFunctions.mqh> inside every trading robot
Three popular functions to debug code:
Pop-up message on screen: Alert();
Comment on the chart: Comment();
Logs in the tab Experts Print();
For loop in MQL4
these are probably some useful facts about arrays
used to store information, e.g. array [ ]
needs to be declared (reserve memory), fast code execution
can be dynamic or static
can be of several levels
hard to interpret
Be able to distinguish between types and possibly take informed decision which one is the best one...
Author's consideration about types of Algorithmic Systems:
Rule-based: where trading decisions are defined by the sets of rules which are programmed. Optimal parameters are found by optimization
Model-based: where trading decisions are defined by the model object. Model object is trained using open-source algorithms...
Hybrid: Trading decisions and filters are defined by combination of both rule and model based trading systems
Advantages:
Easy to interpret
Possible to backtest
Disadvantages:
Often requires a lot of time to manually maintain
Past performance could never guarantee future results...
goals of this sections are:
code structure of trading robot template
examples
How the robot is constructed:
Lecture explains how to get (fork) the code for the course
This lecture is aimed to get the reference to original course and code creator
Showing custom functions that allows to log trading results to file
Lecture explains how included functions were added enabling logging results of the trades
Show where to put your hands to modify strategy...
Video lecture
Developing and deploying bot for ranging market
Blindly deploying our robot to generate many trades
Lecture explains how to store your settings under Metatrader profiles
Explained motivation behind keeping content of profiles under Version Control
Down to practice - how to evaluate trading strategy?
Describe method of trading strategy simulation
Perform optimization and trades simulation
Summarize and analyse results
Simple trading robot implementation
* example of trading robot implemented on the FALCON template
Tasks for students that wish to practice to learn by experimenting:
Clone this repository and synchronize it to the Trading Terminal
Open this code in MetaEditor
Find common strategy parameters
Study how parameter MinPipLimit is used in the code to derive Buy decision
How price at StartHour are compared to Price_X ? How do we translate pips into price value?
Check in the code how user can block execution of Sell positions?
Check in the code how orders are closed using Timer. Which function is used for that?
Compile and use Strategy Tester to verify the following:
Time hold order is working see parameter TimeMaxHold
Setup 'Hard Stop' to be 500 pips, run strategy tester on pair EURUSD and verify that value
Repeat for JPY pairs target
Both Buy/Sell orders are opened use parameter Buy_True and Sell_True
Only Buy | Only Sell
Both Buy/Sell orders are blocked
Multi positions are possible
Perform 'Optimization' using Strategy Parameters and by selecting max 4-5 parameters. Which one do you choose?
What do you think should be the 'TimeMaxHold' parameter for this robot?
Example of Optimization Matrix.
Warning: very heavy and time consuming work!
Learning objectives:
Prepare systematic strategy test matrix
Document steps of robot optimization
Set basic parameters in Strategy Tester and parameters to optimize
Possible to try additional ideas:
increase time to hold position;
increase number of positions
increase volatility stop loss
Method of data collection - video demonstration
Based on the developers guideline, the idea is to automate robot's backtest or optimization
Demonstration
Options to be able to configure automatic optimization or even startup experts with specific settings
Deep dive review of the main script
Video demonstration of how the script for automatic optimization works
video demonstration of how the script for automatic backtest works
As there is no straightforward solution, and because there is no such feature in MT4, we will attempt to build such workflow in the next section of this course!
Review what we aim to achieve in this section
Review the workflow of this section...
p.s. sorry end of the video was cut short by the video recording software (have a great coding experience!)
Video demonstration how we log parameters of the MT4 robot during each trade performed during backtest
Lets repeat automatic optimization of the Trading Strategy. This time we should be able to also log parameters used at each trade of the optimization process...
Windows Environmental Variables are used to make code working without updating user paths
Using dedicated R script to analyze trading results along with the robot parameters as obtained during optimization
Illustrating slight discrepancy of the code at the latest github release from those shown in the videos of the section. Also check the resource link showing how R function was build
We proceed with the R code that will help us to join trading results with the corresponding robot parameters
Use 'dplyr verbs' to find the best parameter(s).
Overwrite file with the settings of the robot
Backtest using new parameters
Use R script opt_PerformBacktesting.R
Inspect backtest results
Calculate profit factor from last month backtest
We update part of the script to activate or disactivate Trading Robot (using csv files)
Discussion about how to change robot parameters:
folder profiles,
info in file chartxx.chr shall be changed
terminal shall be restarted
Demonstrating how automatic optimization, update parameter & backtest would work!
In this video, our goal will be to execute all code in R scripts including to execute batch scripts, perform analysis in R, write respective decisions.
This video aims to achieve the task automation - to execute all scripts at predefined schedule.
(this is an ultimate goal and phylosophy of this course :)
p.s. unfortunately we could not sort yet sort the problem of running MT4 platforms in the interactive mode during execution of the tasks. nevertheless we are able to complete the goal by restarting PC
A quick summary of this section
About this Course: Setting up and deploying Trading System
The second part of this series will cover setting up our Expert Advisor or Trading Robot. At the end of this course we will have complete and ready to be used Algorithmic Trading System integrated with our Decision Support System:
Programming environment
Setting up Version Control Project
Overview of robot functions
How to customize to target market inefficiency
Integrate robot with Decision Support System (start/stop trading system from external commands)
Customize and record trades results
Rolling Optimization, automatic robot backtest
The same robot template will be used in other courses of the Lazy Trading Series
About the Lazy Trading Courses:
This series of courses is designed to to combine fascinating experience of Algorithmic Trading and at the same time to learn Computer and Data Science! Particular focus is made on building foundation of Decision Support System that can help to automate a lot of boring processes related to Trading.
This project is containing several short courses focused to help you managing your Automated Trading Systems:
Set up your Home Trading Environment
Setting up and deploying Trading Systems
Set up your automated Trading Journal
Statistical Automated Trading Control
Reading News and Sentiment Analysis
Using Artificial Intelligence to detect market status
Building an AI trading system
Update: dedicated R package 'lazytrade' was created to facilitate code sharing among different courses
IMPORTANT: all courses will be short focusing to one specific topic. You will not get lost in various sections and deep theoretical explanations. These courses will help you to focus on developing strategies by automating boring but important processes for a trader.
What will you learn apart of trading:
While completing these courses you will learn much more rather than just trading by using provided examples:
Learn and practice to use Decision Support System
Be organized and systematic using Version Control and Automated Statistical Analysis
Learn using R to read, manipulate data and perform Machine Learning including Deep Learning
Learn and practice Data Visualization
Learn sentiment analysis and web scrapping
Learn Shiny to deploy any data project in hours
Get productivity hacks
Learn to automate your tasks and scheduling them
Get expandable examples of MQL4 and R code
What these courses are not:
These courses will not teach and explain specific programming concepts in details
These courses are not meant to teach basics of Data Science or Trading
There is no guarantee on bug free programming
Disclaimer:
Trading is a risk. This course must not be intended as a financial advice or service. Past results are not guaranteed for the future.