New article Parallel Particle Swarm Optimization has been published:
The article describes a method of fast optimization using the particle swarm algorithm. It also presents the method implementation in MQL, which is ready for use both in single-threaded mode inside an Expert Advisor and in a parallel multi-threaded mode as an add-on that runs on local tester agents.
From an algorithmic point of view, the PSO method is relatively simple. The main idea is to generate a set of virtual "particles" in the space of the Expert Advisor's input parameters. The particles then move and change their speed depending on the EA's trading metrics at the corresponding points in space. The process is repeated many times until the performance stops improving. The pseudo-code of the algorithm is shown below:
Particle Swarm Optimization Pseudo-Code
According to this code, each particle has a current position, speed and memory of its "best" point in the past. Here, the "best" point means the point (a set of EA input parameters), where the highest value of the objective function for this particle was achieved. Let us describe this in a class.
double position; // current point
double best; // best point known to the particle
double velocity; // current speed
double positionValue; // EA performance in current point
double bestValue; // EA performance in the best point
Particle(const int params)
bestValue = -DBL_MAX;
group = -1;
The size of all arrays is equal to the dimension of the optimization space, so it is equal to the number of the Expert Advisor parameters being optimized (passed to the constructor). By default, the larger the objective function value, the better the optimization. Therefore, initialize the bestValue field with the minimum possible -DBL_MAX number. One of the trading metrics is usually used as a criterion for evaluating an EA, such as profit, profitability, Sharpe ratio, etc. If optimization is performed by the parameter whose lower values are considered better, such as for example drawdown, appropriate transformations can be made to maximize opposite values.
Arrays and variables are made public to simplify access and their recalculation code. Strict adherence to the OOP principles would require hiding them using the 'private' modifier and describing read and modify methods.
Author: Stanislav Korotky
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
Обсуждение статьи "Параллельная оптимизация методом роя частиц (Particle Swarm Optimization)"
Stanislav Korotky, 2020.08.24 10:45
Stanislav Korotky, 2020.08.24 10:48
Hey, great topic, unfortunately when trying to connect all the pieces, compiler still throws errors:
It looks as if due to some update it is not possible now? If you could look into it, that would be nice.
The vector and the position compilation error belong together since position is an array of the dimensions (degrees of freedom/inputs) I guess which could be inserted into the calculate method, but due to some update it is not possible now? And then the positions array can't be casted into a positionValue... if you could look into it, that would be nice.
Then there are things about worker functor where I have no clue what seems to be the problem.
I hope there is an easy way to fix this. If there isn't I would totally understand if you would prefer not to.
Just make a context substitution of "vector" to "_vector" in ParticleSwarmParallel.mqh or/and ParticleSwarmEmbed.mqh.
MQL5 has introduced vector type since the publication, this broke many sources codes where the identifier vector has been used already.
MT4Orders and Virtual are 3-rd party libraries. You should check for latest versions on their pages in the codebase.
I downloaded the lasted MT4Orders and it compiled. However now it gives me this error after I load the PSO set files. There is no error for standard optimize mode. Is it possible to change the dates to optimize to the last bar instead of the last day?
If you're asking about "incorrect input parameters" error, you can double click optimization table on the pass which gives the error, and get the single pass log for detailed description what goes wrong. Also you did not provide info about which EA and with what settings you've tried to run.
I have already told you that the last-day-out limitation is imposed by the tester itself.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.