Any coding trick to reduce computer usage?

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Any coding trick to reduce computer usage?

Postby arjfca » 14 Jul 2012

Hello

I create some indicator that I use over my charts to display info of a bar, horizontal trend lines and vertical time line.

These seem to use a LOT of computer and graphic usage and PC really slowing down. While my PC is not the latest one, It show only these kind of problem with MC. I'm using the latest 32 bits. For the moment I can't use the 64 version because I got some DLL function that will need to be update to.

The slowing down is apparent over my charts driven by my video card
The indicators do use a lot of my available memory ( 6 gig install), so probably the cause of the slowing down. So my question is: Is there some coding trick that could reduce memory usage

Difficult to measure coding efficiency, but maybe, there is some trick I can use.

Any info or idea appreciated

Martin.

Note:
My PC is a
Quad 6600 Intel CPU @2400 mhz
6 gig memory
SSD hard drive
4 LCD
1 video card with 1gig ddr5 memory for 2 LCD
2 USB video card adapter for 2 LCD

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Any coding trick to reduce computer usage?

Postby JoshM » 14 Jul 2012

I create some indicator that I use over my charts to display info of a bar, horizontal trend lines and vertical time line.

(..)

These seem to use a LOT of computer and graphic usage and PC really slowing down.

(..)

The indicators do use a lot of my available memory ( 6 gig install), so probably the cause of the slowing down. So my question is: Is there some coding trick that could reduce memory usage

Difficult to measure coding efficiency, but maybe, there is some trick I can use.
Is the problem only the memory usage, or is the indicator also slow to calculate? If it's 'just' too much memory usage, have you tried using less trendlines but reusing the existing ones? (i.e. less use of TL_New_s and more of TL_SetBegin_s and TL_SetEnd_s). I found that my pc also uses an high amount of memory and is very slow to scroll through the chart if I had made too much drawing objects.

Also, I don't know how you display the info of a bar, but if you use multiple text objects for this per bar, try combining them all together in one text object. That should also give better memory performance.

Another tip is to check the drawings through right-click on the chart and then Format Drawings. Then check the start and end point of the drawings listed there. It happened to me more than once that I had made a coding error which placed drawings in the year 1900 - so I couldn't see them on the chart but they consumed memory and made MC sluggish nonetheless.

Otherwise I would suggest to comment out code segments from your indicator and then check the performance, then comment out another part and so on, to get to the cause of this.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Any coding trick to reduce computer usage?

Postby arjfca » 14 Jul 2012

[Otherwise I would suggest to comment out code segments from your indicator and then check the performance, then comment out another part and so on, to get to the cause of this.
Hello Josh and thanks

So, I was not alone with this kind of slowing down. Mouse over the chart is sometime slow, erratic and frustrating.

Actually,
- a new trend line is created for each new one. I will try code a given number and re-use them
- A new text character is created under / above each bar that opened with a gap.
- For the horizontal trend line, I use the actual time / date to start and extend each of them to right / left. Cant say if the extension use a lot of memory
- For vertical time line, I use 2 lines. Above and under the bars Like that it is cleaner, but use more memory. I display up to 8 periods per day.

An idea that I just got, but not tested. Maybe I could code to display these text and trend line only for the available time and price over the chart by using the GetAppInfo and
- aiLeftDispDateTime
- aiRightDispDateTime

The condition to be,
if the bar time is >= aiLeftDispDateTime (the time of the last left bar on the screen,
... then process the code
else
... Erase text info
end;

For the Vertical line, I will check for the GettAppInfo highest / lowest price displayed

Can't say if it is logic. But I do need to adjust something because I really don't like my MC when this slow down problem is occurring.

Maybe, MC team could came out with a good coding practice to advise and or prevent these kind of problem. Before knowing that my code was causing the problem, I did all sort of test on my PC, replace my video card and look for faster memory, etc.

Martin

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Any coding trick to reduce computer usage?

Postby TJ » 14 Jul 2012

It can be a common coding error.

Do this test:

Go to the chart and drag the trendline to another spot.

If you see another line sitting at exactly where you had the line before,
go drag that line away too.

If you see yet another line at the same spot, then this is caused by a coding error.

You have been drawing a new line EVERY TICK at the same spot, that's why you have multiple lines at the same spot. And the computer resources is quickly depleted.


If you dragged the line and do not see another one,
the problem could be something else.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Any coding trick to reduce computer usage?

Postby arjfca » 15 Jul 2012

It can be a common coding error.

Do this test:

Go to the chart and drag the trendline to another spot.

If you see another line sitting at exactly where you had the line before,
go drag that line away too.

If you see yet another line at the same spot, then this is caused by a coding error.

You have been drawing a new line EVERY TICK at the same spot, that's why you have multiple lines at the same spot. And the computer resources is quickly depleted.


If you dragged the line and do not see another one,
the problem could be something else.
Hello TJ

Good point, but not found in my case. Still, I will recheck all coding for any evident flaw.

Martin

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Any coding trick to reduce computer usage?

Postby TJ » 15 Jul 2012

next test:

right click on chart,

select Format Drawings.

you will see the ID numbers of your drawing objects.

Here's a screen capture from one of my charts. You can see my trendline alone is over 6,000. I also have texts and arrows on the same chart. And I have 8 of these charts. All running on a 4 yrs old Q6600 with 4 GB RAM with no problem.

Image



ps. if your chart is tick based, with long history, it will use a lot more computer resources.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Any coding trick to reduce computer usage?

Postby arjfca » 15 Jul 2012

next test:

right click on chart,

select Format Drawings.

you will see the ID numbers of your drawing objects.

Here's a screen capture from one of my charts. You can see my trendline alone is over 6,000. I also have texts and arrows on the same chart. And I have 8 of these charts. All running on a 4 yrs old Q6600 with 4 GB RAM with no problem.

Image



ps. if your chart is tick based, with long history, it will use a lot more computer resources.
Same Processor than me
Charts are 175 seconds, 15,30 minutes, 1,4 hours, day, week, month

I have stated to code for my specific indicator to start computing after the most left date & time bar. At the moment it work, but If I scroll back in time bars are not computed.

- I will reduce my # bars to a logical one. There is no need to display a full years of 3 minutes bars.

Time to return to mowing the grass ( legit one, not the smoking one)

Martin :)

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Any coding trick to reduce computer usage?

Postby TJ » 15 Jul 2012

it is very easy to test if you have a coding problem,
or resource problem (ie. too much history on the chart).


set up 2 charts with the same indicators,
one chart with the sub-minute resolution (ie tick, seconds, etc) and long history.
another chart with higher time frame (eg. 10 minute).

If you encounter the "slow" computer response, take these 2 steps:

1. Delete the long history chart. If the computer response improves, then the problem is in too much history. This will be especially apparent with the 32 bit version of MultiCharts.

second test:
2. Instead of deleting the long history chart, delete indicators one by one. The computer response will improve when you have deleted the rogue indicator.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Any coding trick to reduce computer usage?

Postby arjfca » 15 Jul 2012

it is very easy to test if you have a coding problem,
or resource problem (ie. too much history on the chart).


set up 2 charts with the same indicators,
one chart with the sub-minute resolution (ie tick, seconds, etc) and long history.
another chart with higher time frame (eg. 10 minute).

If you encounter the "slow" computer response, take these 2 steps:

1. Delete the long history chart. If the computer response improves, then the problem is in too much history. This will be especially apparent with the 32 bit version of MultiCharts.

second test:
2. Instead of deleting the long history chart, delete indicators one by one. The computer response will improve when you have deleted the rogue indicator.
OK
Understood. But it would be interesting to have a tool to measure memory usage. Since my problem is intermittent, it would be difficult to judge if the problem is resolve. I can't say why it is intermittent. Maybe that memory usage do buildup if I don't close down my PC ( rarely do it).

I did create a small function that return true if the actual bar is date & time is greater than the visible bar on the chart. I will test to implement the function to all susceptible indicator that could drain memory. The purpose is to show text and trend line to visible part of the screen.

Code: Select all

// Return true id the actual bar is a visible one
//This is to reduce memory allocation by computing indicator only to a seen bars

Var:
Intrabarpersist LeftTimeDate (0),
Intrabarpersist RightTime (0),
Intrabarpersist UpperPrice (0),
Intrabarpersist LowerPrice (0),
intrabarpersist ActualDateTime (0);

VisibleDate_Time_Bar = False;

LeftTimeDate = GetAppinfo(aiLeftDispDateTime);
UpperPrice = GetAppInfo(aiHighestDispValue );
LowerPrice = GetAppInfo(aiLowestDispValue );
ActualDateTime = eldatetodatetime(date) + eltimetodatetime_s(Time_S);


If ActualDatetime >= Lefttimedate then VisibleDate_Time_Bar = True;
Martin

P.S. Did you tried the 64 version? Any improvement?

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Any coding trick to reduce computer usage?

Postby TJ » 15 Jul 2012

...
P.S. Did you tried the 64 version? Any improvement?
64 bit version is the only way to go forward.

I have just installed it this week.


If you are reviewing old charts or backtesting, I can see the need for history.
If you are daytrading, there is little reason to have more than 3 month's history on intraday charts.




ps. my screen capture in previous post was done on 32 bit version.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Any coding trick to reduce computer usage?

Postby arjfca » 15 Jul 2012

...
P.S. Did you tried the 64 version? Any improvement?
64 bit version is the only way to go forward.

I have just installed it this week.

If you are reviewing old charts or backtesting, I can see the need for history.
If you are daytrading, there is little reason to have more than 3 month's history on intraday charts.

ps. my screen capture in previous post was done on 32 bit version.
OK: 64 bit is in my plan, but before,as mentioned in other post, I will need to buy newer version of specials dll that I'm using. This will come in time.

Martin

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Any coding trick to reduce computer usage?

Postby TJ » 15 Jul 2012

Are you using multiple instances of MultiCharts?
This will alleviate the 2GB bottleneck imposed by Microsoft Windows.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Any coding trick to reduce computer usage?

Postby arjfca » 15 Jul 2012

Are you using multiple instances of MultiCharts?
This will alleviate the 2GB bottleneck imposed by Microsoft Windows.
Sorry, I don't understand?

Martin :) ??

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Any coding trick to reduce computer usage?

Postby TJ » 15 Jul 2012

Under Microsoft's Windows Operating System,
a 32 bit software (eg. MultiCharts 32 bit version) can access 2 GB of data space.

e.g. if you have 6 wsp, each requires 500 MB of memory space, for a total of 3 GB. (over the 2 GB limit).
In order for MultiCharts to service all the wsp, Windows would swap out some of the less used data to disk, and recall them only when the program calls for them. This swapping (paging) of data causes degradation of performance and the program appears lagging to the users.
This is especially apparent when you scroll the chart back in time. (ie the program must swap out data from disk).

The solution:
You can run multiple instances of MultiCharts, each copy of MultiCharts can access 2 GB of data space. (assuming you have enough RAM in your computer).

e.g.
If you start 2 instances of MultiCharts, and let each MultiCharts run 3 wsp. That is, each MultiCharts is only required to handle 1.5 GB of data space. You are effectively accessing 3 GB of data space with a 32 bit software, and no data swapping required.

Hope the above helps.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Any coding trick to reduce computer usage?

Postby arjfca » 15 Jul 2012

Under Microsoft's Windows Operating System,
a 32 bit software (eg. MultiCharts 32 bit version) can access 2 GB of data space.

e.g. if you have 6 wsp, each requires 500 MB of memory space, for a total of 3 GB. (over the 2 GB limit).
In order for MultiCharts to service all the wsp, Windows would swap out some of the less used data to disk, and recall them only when the program calls for them. This swapping (paging) of data causes degradation of performance and the program appears lagging to the users.
This is especially apparent when you scroll the chart back in time. (ie the program must swap out data from disk).

The solution:
You can run multiple instances of MultiCharts, each copy of MultiCharts can access 2 GB of data space. (assuming you have enough RAM in your computer).

e.g.
If you start 2 instances of MultiCharts, and let each MultiCharts run 3 wsp. That is, each MultiCharts is only required to handle 1.5 GB of data space. You are effectively accessing 3 GB of data space with a 32 bit software, and no data swapping required.

Hope the above helps.
OK, Understood

Martin :)


Return to “MultiCharts”