- Moving objects
- Assigning a character code to a label
- Creating objects
Objects and efficiency? This is a contradiction in terms, as all objects have to be redrawn with each new bar. Use structures and make a button that, when you click on it, draws the last ones as objects on the chart - and then deletes them again.
It depends on how your indicator works. For example, does your indicator create a fixed amount of objects? If so, you don't need to loop through all of them. Just create as many string variables as needed and store their names.
If your indicator creates an unknown number of objects, you can create a array and store every object name/info in that array. Then you won't need to loop through every object in the chart, but just through every object created by that indicator, which will certainly save some time.
Also, if you need to redraw, you can call ChartRedraw after every loop, not inside the loop.
If you are using if statements and two of them contradict each other, use an if else. This avoids the checking of the second if. For example:
int i = 0; if (i == 0) { Print("i equals 0"); // if "i == 0", then the next if statement is not checked, due to the else keyword. this is good, because i cannot be 1 anymore } else if (i == 1) { Print("i is not equal 0"); } // ---------------------------------------------- // if (i == 0) { Print("i equals 0"); // even if "i == 0", the next if statement will be checked, but it'll never be true. this makes your code, in theory, slower. } if (i == 1) { Print("i is not equal 0"); }
There're other stuff that may make your code faster, but it would depend on how it is structured.
Hey, Please, i coded and indicator and everything is okey and fine but it creates multiple objects and in the code i try to loop through them and it works fine. But if i load with other indicatos that themselves also creates multiple objects, the number of objects increase on the chart and when trying to modify them with by looping through them with the standard ObjectSetInteger() etc functions which are asynchronous, the objects then take time to refresh despite using ChartRedraw so for this issue where we have a large number of objects, what would be the best approach to modify them? Been looking for this on the forum but didn't found anything. Maybe I am wording it wrongly. Example of code of me looping throught the objects to modify them.
Do NOT place a ChartRedraw() in a loop.
Add it ONCE, after the loop.
It depends on how your indicator works. For example, does your indicator create a fixed amount of objects? If so, you don't need to loop through all of them. Just create as many string variables as needed and store their names.
If your indicator creates an unknown number of objects, you can create a array and store every object name/info in that array. Then you won't need to loop through every object in the chart, but just through every object created by that indicator, which will certainly save some time.
Also, if you need to redraw, you can call ChartRedraw after every loop, not inside the loop.
If you are using if statements and two of them contradict each other, use an if else. This avoids the checking of the second if. For example:
There're other stuff that may make your code faster, but it would depend on how it is structured.
thanks for your reply, added a kind of solution using this info and it's a bit faster

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use