Course Content
In this first section we look at our starting point, which is the expert advisor that was built in the course "Algorithmic Trading in MQL5: Code Robots & Free Up Your Time", the Simple Moving Average EA. In this section we review that expert strategy, code and performance to have a common ground moving forward.
Introduction to OOP, Classes and Objects
In this section, we will explore the basic concepts of object-oriented programming (OOP) in MQL5. OOP offers advantages over traditional top-down programming, such as structured and modular code, making it easier to organize and avoid repetition. Problem-solving becomes faster as code is divided into classes. OOP allows for code reusability by creating objects of a class. Most modern software development, including MQL5 applications, follows an OOP approach. Although learning OOP may seem challenging, it is a more intuitive and efficient method for developing expert advisors. Join us to master OOP and enhance your programming skills.
CTrade Class
This section focuses on restructuring an expert advisor using object-oriented programming. The advisor will be improved by creating four include files, each hosting different classes. The first include file, named "trade," will contain a trade class for sending orders. The second include file, "position management," will hold a PM class for managing positions. The third include file, "bar data," will have a bar data class for working with bar information. Lastly, the "indicator" include file will contain classes for creating and working with indicators. The instructor demonstrates how to create these include files in a new folder.
CPM Class (Position Management)
In this section, we start creating the Position Management class. We add a comment section and declare the class with variables and methods for stop loss, take profit, trailing stop loss, and break even. We also create objects for sending orders and declare a constructor to initialize memory. We define functions for calculating stop loss and take profit, as well as trailing stop loss and break even for hedging and netting accounts. We differentiate the methods with comments. Finally, we implement the constructor.
CBar Class
In this section, we start coding the CBar class to retrieve bar data. We add a comment section and declare the class. We create a public access object of the mqlRates structure, which will store the rates of the bars. We set this array as a series array in the constructor. We then create a refresh method to retrieve bar data, which calls the copy rates function. This function copies the rates to our var object array.
CIndicator Class
In this section, we begin coding the classes for our indicators. We will have a base class and derived classes for each indicator, such as moving average and bollinger bands. The base class, named CIndicator, will have variables and methods. The main array will store values copied by the main buffer. The constructor sets the main array as a series array. We declare a virtual init method, which will be implemented differently in each derived class. The init function sets the handle for the indicator. We also have a refreshMain function to update the values in the main array. In the next lectures, we will implement these methods.
Pending Orders in MQL5
In this section, we will be improving our expert advisor by implementing different types of pending orders in MT5. We will review these order types and add methods to our citrate class to place, find, modify, specify expiration time, and delete these orders. This missing piece will make our expert advisor capable of sending any type of order, which is exciting. So, let's dive in and make these improvements to our advisor.
Additional and Final
In this final section of the course, we will cover strategy test errors in backtesting, new concepts and framework updates, and virtual private servers. The lectures on VPS, which were also covered in the previous course on "Algorithmic trading in MQL5: code robots and free up your time", will be included here for those who missed that course.
Algorithmic Trading in MQL5: OOP & PO
Join the conversation
0% Complete