![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Only 2 ways : to check the code or to add one by one indicator to a clean chart (and keep only one indicator at a time on a chart) and to watch when is it going to slow down significantly.
Thanks Mladen, it's gonna take me a while
.
...
Only 2 ways : to check the code or to add one by one indicator to a clean chart (and keep only one indicator at a time on a chart) and to watch when is it going to slow down significantly (you can use windows task manager for that purpose too : that way you can see the CPU percentages used).
Hello guys, I've got a question, don't where to post it elsewhere. I've got an indicator that's eating my CPU, my computer is really slow. As I have a lot of charts and different templates opened, I don't know which one it is. Is there a way to know that ? an indi to attach to tell me the usage of CPU of my indis ? or anything else ? I don't want to take away all indis one by one. Thanks.
Indicator Optimizations
One thing I've seen in a lot of indicators is poor coding techniques that can be improved for efficiency and reduce cpu usage. If you are running 4-6 charts and using the same indicator twice on a chart, improving its efficiency can probably improve the cpu usage; not by a lot but by some level. Think about it. 20 calculations eliminated times 2 per chart times 6 charts times a tick every 5 seconds. Optimization will not make MT4 blazing fast but it will help.
Loop Recalculations.
if you are seeing a lot of i+1's in the main limit loop use the following
int previous=i+1; and substitute previous for the i+1's
Loop invariate
if you have a calculation that does not involve the loop variable either directly or indirectly such as 10.*MATHLOG(period), move it out to before the loop or better yet, move it into the init() routine if possible.
double periodlog10=10.*MATHLOG(period); and then replace
Obsolete code
A surprising number of indicators have been modified by several people and sometimes they have left useless, non functional code in the indicator. A variable has to be declared, and used on BOTH the left side of the assignment as well as the right side.
int x;
x=10.*MathLog(period);
y=period + x; If you don't find a right side of the assignment statement like this, then the variable x and its assignment are useless and should be removed.
Dashboards
A lot of the dashboards involve printing constant text to the screen, "Current Bid =" BID.
Print "Current Bid ' " in the Init() routine and only print BID in the Start() routine.
The best way to optimize is to make a copy of the original source so you can continually compare your results and back track if something really goes wrong. Keep making a backup copy as you go along.
Also another trick is to change the indicator width to a large number
#property indicator_width1 10
and then use a small width, 3, and a different contrasting color. Then put the original indicator on the screen first followed by the one you are optimizing. In this way, the optimized code will be superimposed on the original and you can see at a glance if you mess up. This technique is also very good when converting a single color indicator to multicolor.
Hope this helps
Tzuman
Tzuman
Good advices
But in two cases they can not be applied : when somebody does not have the source, and when somebody is not a coder. Hence the simplest solution in those cases is a simple try-and-see (and pray
)
One thing I've seen in a lot of indicators is poor coding techniques that can be improved for efficiency and reduce cpu usage. If you are running 4-6 charts and using the same indicator twice on a chart, improving its efficiency can probably improve the cpu usage; not by a lot but by some level. Think about it. 20 calculations eliminated times 2 per chart times 6 charts times a tick every 5 seconds. Optimization will not make MT4 blazing fast but it will help.
Loop Recalculations.
if you are seeing a lot of i+1's in the main limit loop use the following
int previous=i+1; and substitute previous for the i+1's
Loop invariate
if you have a calculation that does not involve the loop variable either directly or indirectly such as 10.*MATHLOG(period), move it out to before the loop or better yet, move it into the init() routine if possible.
double periodlog10=10.*MATHLOG(period); and then replace
Obsolete code
A surprising number of indicators have been modified by several people and sometimes they have left useless, non functional code in the indicator. A variable has to be declared, and used on BOTH the left side of the assignment as well as the right side.
int x;
x=10.*MathLog(period);
y=period + x; If you don't find a right side of the assignment statement like this, then the variable x and its assignment are useless and should be removed.
Dashboards
A lot of the dashboards involve printing constant text to the screen, "Current Bid =" BID.
Print "Current Bid ' " in the Init() routine and only print BID in the Start() routine.
The best way to optimize is to make a copy of the original source so you can continually compare your results and back track if something really goes wrong. Keep making a backup copy as you go along.
Also another trick is to change the indicator width to a large number
#property indicator_width1 10
and then use a small width, 3, and a different contrasting color. Then put the original indicator on the screen first followed by the one you are optimizing. In this way, the optimized code will be superimposed on the original and you can see at a glance if you mess up. This technique is also very good when converting a single color indicator to multicolor.
Hope this helps
Tzuman