The article is curious and very useful for me. However, I have a question: how correct is comparison of real numbers in this piece of code?
double AnnealingMethod::FindValue(double val,double step) { double buf=0; if(val==step) return val; if(step==1) return round(val);
Images\AnnealingMethod\back.bmp Images\AnnealingMethod\pause.bmp Images\AnnealingMethod\play.bmp Images\AnnealingMethod\stop.bmp Images\AnnealingMethod\forward.bmp
Thanks for the message, corrected
| AnnealingMethod.zip | Zip-файл с картинками для создания интерфейса плеера. Файлы нужно разместить в папке MQL5/Images/AnnealingMethod |
This was a good article. Thank you to the author!
I'm still a little bit confused, but I'd like to say something about it
Несмотря на значительные преимущества, алгоритм метода отжига имеет следующие недостатки реализации:
- impossibility to run the algorithm in cloud testing;
- the complexity of connecting to the Expert Advisor and the need to select parameters to get the best results.
I propose to slightly adjust the article so that you can connect any Expert Advisor with small movements.
For example, you can connect the standard Moving Average.mq5 to the presented implementation of the annealing method as follows
//+------------------------------------------------------------------+ //|Moving Averages.mq5 | //| Copyright 2009-2017, MetaQuotes Software Corp. | | //|http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2009-2017, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #include <Trade\Trade.mqh> input double MaximumRisk = 0.02; // Maximum Risk in percentage input double DecreaseFactor = 3; // Descrease factor. input int MovingPeriod = 12; // Moving Average period input int MovingShift = 6; // Moving Average shift // Insert after all inputs #include <AddAnnealingMethod.mqh> #define MaximumRisk Inputs[0] #define DecreaseFactor Inputs[1] #define MovingPeriod (int)Inputs[2] #define MovingShift (int)Inputs[3] //--- int ExtHandle=0; bool ExtHedging=false; CTrade ExtTrade; #define MA_MAGIC 1234501
And that's all! No more manipulations are required. To make it work, we had to slightly change one function
//function for setting optimisation parameters uint AnnealingMethod::RunOptimization(string &InputParams[],int count,double F0,double T) { Input Mass[]; ArrayResize(Mass, ArraySize(InputParams)); ResetLastError(); bool Enable=false; double Start= 0; double Stop = 0; double Step = 0; double Value= 0; int j=0; Alg.HQRndRandomize(&state);//initialisation for(int i=0;i<ArraySize(InputParams);i++) { if(!ParameterGetRange(InputParams[i],Enable,Value,Start,Step,Stop)) return GetLastError(); // if(Enable) { // ArrayResize(Mass,ArraySize(Mass)+1); Mass[j].num=i; // Mass[j].Value=UniformValue(Start,Stop,Step); Mass[j].Value=Enable ? UniformValue(Start,Stop,Step) : Value; Mass[j].BestValue=Mass[j].Value; Mass[j].Start=Start; Mass[j].Stop=Stop; Mass[j].Step=Step; Mass[j].Temp=T*Distance(Start,Stop); j++; // if(!ParameterSetRange(InputParams[i],false,Value,Start,Stop,count)) if(Enable && !ParameterSetRange(InputParams[i],false,Value,Start,Step,Stop)) return GetLastError(); } // else // InputParams[i]="""; } if(j!=0) { if(!ParameterSetRange("iteration",true,1,1,1,count)) return GetLastError(); else return WriteData(Mass,F0,1); } return 0; }
And hide a decent piece of code in AddAnnealingMethod.mqh.
Таким образом, алгоритм сверхбыстрого отжига — достойный конкурент ГА и при правильных настройках может показать лучший результат.
at what "correct" settings?
the point of an optimisation algorithm is to reduce the search space. if a search is in progress, it means that the FF formula is not known (otherwise extrema could be calculated using the FF-based formula), and therefore there are no "correct settings".
the algorithm either looks for better all else being equal or worse, it is impossible to be a little bit pregnant.
There were real attempts to compare the regular GA and other AOs on various tests. the gods said - there will be no fighting and amen to that.
ZY. 1, 2 optimisable parameters? it's just ugh..... try to optimise several hundreds, thousands of parameters with your annealing..... your eyes will be opened.
tester_file is read only if it existed (content is not important) at the time of compilation.
If mq5 was compiled when there was no corresponding file, even its further existence will not be perceived in EX5.
Therefore, if you generate a file for tester_file in OnTesterInit, make sure that you compile the EA when there is at least an empty passed file.
@Renat Fatkhullin is somewhat mistaken in his statement
Forum on trading, automated trading systems and testing trading strategies
Can an EA without DLL functions send data somewhere?
Renat Fatkhullin, 2017.06.21 11:12 AM
I haven't checked, but I assume this file can be generated directly in OnTesterInit.
No, it will not go into the calculated data packet in the pass itself.
The Article shows that OnTesterInit perfectly generates the data to be sent to the Agents as a file. It is clear that this data can be of personal nature...
The author has done a great job. Very interesting article.
Thank you.
There have been real attempts to compare the regular GA and other AOs on various tests. the gods have said - there will be no unicycling and amen to that.
ZY. 1, 2 optimisable parameters? it's just ugh..... try to optimise several hundreds, thousands of parameters with your annealing..... your eyes will be opened.
The article is valuable not because of the Optimisation algorithm (although it is more than interesting), but because of the implementation built into the standard Optimizer. The implementation is very non-standard at the moment and even contradicts some statements of the developers. But to understand it you need to read the source code, which does not concern the annealing algorithm itself.
Nothing prevents you from similarly embedding your own algorithm and showing its pros/cons directly on Expert Advisors, as the author did.
The article is curious and very useful for me. However, I have a question: how correct is comparison of real numbers in this piece of code?
Yes, you are right, it is impossible to compare like this. The MQL5 Help suggests using the following function:
bool CompareDoubles(double number1,double number2) { if(NormalizeDouble(number1-number2,8)==0) return(true); else return(false); }
But even if the comparison is performed incorrectly, the FindValue function will produce the correct result
The article is valuable not for the Optimisation algorithm (although it is more than interesting), but for the implementation built into the standard Optimiser. The implementation is very non-standard at the moment and even contradicts some statements of the developers. But to understand it you need to read the sources, which do not concern the annealing algorithm itself.
Nothing prevents you from similarly embedding your own algorithm and showing its pros/cons directly on Expert Advisors, as the author did.
It is clear that the article is valuable in the implementation of optimisation management, but the author makes a comparison with the standard algorithm for some reason, and even with a negligible number of parameters - this is what I tried to emphasise in my post, that it is useless to compete with the standard optimiser in the search space range (number of parameters and their step) sufficient for practical purposes of algotraders.
And if custom optimisation is to be used, it is definitely not in this way, because the "bottleneck" in speed is the tester itself, not the AO, and the quality has already been mentioned - the standard one is already good enough.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Controlled optimization: Simulated annealing has been published:
The Strategy Tester in the MetaTrader 5 trading platform provides only two optimization options: complete search of parameters and genetic algorithm. This article proposes a new method for optimizing trading strategies — Simulated annealing. The method's algorithm, its implementation and integration into any Expert Advisor are considered. The developed algorithm is tested on the Moving Average EA.
Implementation of the algorithm will require two new classes, which should be included in the optimized Expert Advisor:
Also, operation of the algorithm requires additional code to be included in the OnInit function and adding the functions OnTester, OnTesterInit, OnTesterDeInit, OnTesterPass to the EA code. The process of integrating the algorithm into an expert is shown in Fig. 2.
Fig. 2. Including the algorithm in the Expert Advisor
Author: Aleksey Zinovik