Writing Faster Code

Questions about MultiCharts .NET and user contributed studies.
bdwg
Posts: 5
Joined: 27 Jan 2018
Has thanked: 2 times

Writing Faster Code

Postby bdwg » 07 Mar 2018

Hello everyone. I'm rather new to C#, but I tried changing something in my code to make it faster and it doubled my optimization time. Just wondering what tips you all might also have come across that could help everyone write faster code.

For me, I had my code outputting via Output.WriteLine so I could make sure my variables were calculating correctly. I left these in the code. Once I commented my outputs out, times got cut by more than half! Super easy.

Anything else work for you all, or things to avoid?

User avatar
Svetlana MultiCharts
Posts: 114
Joined: 19 Oct 2017
Been thanked: 30 times

Re: Writing Faster Code

Postby Svetlana MultiCharts » 23 Mar 2018

Hello, bdwg

General recommendations are the following:

You should get rid of all excessive calculations in your code.

As for the Output: it is used for debugging and can be helpful in some cases, but when the script works as expected printing to the Output is not necessary.

As for optimization speed: signals can create drawings (ICustomDraw). You don’t need drawings during optimization, therefore you can remove them in the code or make the use of drawings optional, e.g.:

if (!Environment.Optimizing) {
// drawing tools
}

If you need to use some indicator calculations by your signal and want to reduce the time of calculation – it’s better not to add the entire indicator in the script (which is easier in terms of script development), but to use separate functions of this indicator in the signal.

You can also perform code profiling, measure the time of calculation, find critical paths and optimize your strategy.
These users thanked the author Svetlana MultiCharts for the post (total 2):
bdwgEmmanuel

bdwg
Posts: 5
Joined: 27 Jan 2018
Has thanked: 2 times

Re: Writing Faster Code

Postby bdwg » 23 Mar 2018

Thank you! This is all very helpful information, particularly the code profiling. I will have to look into that more.


Return to “MultiCharts .NET”