Drawing shapes
Drawing shapes
I need to draw vertical lines to shade areas with various shapes on my charts. I use the trend line commands to do this. The trouble is I end up having 10's of 1000's of these lines and it can takes several minutes to remove the study. It also chews up memory so much that I have to exit MC after a few re-runs to release it. Otherwise, all my physical memory is eventually consumed and the system starts to page like mad and everything grinds almost to a halt. The study takes about 30 seconds to run, which is OK for now. It's the removal process that causes me grief as it takes so long. I presume the reason for the delay is it's doing some sort of cleanup process (which appears to do a poor job of it since it doesn't release the memory as stated above). Is this because there are many attributes associated to each trend line, even if they are not used? If so, it would be nice of there was a cut down version of the trend line functions. All I need is to draw a line from one point to another on the chart, set the color, size and line style, nothing else. Is there something else I could do to speed things up? One idea is to use a combination of the plot and noplot functions but that would make my code even more complicated than it already is.
- TJ
- Posts: 7742
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
most likely you are asking the indicator to draw the same line repeatedly. this is a common programming error with trendlines.
you can check to see if this is the case by clicking on the trendline and dragging it away from its position. If you see another trendline sitting at the same place... drag that line away too... you will probably see yet another trendline sitting in the exact same place.
if that's the case... then it is a programming error.
if you post your code... I am sure I can help.
you can check to see if this is the case by clicking on the trendline and dragging it away from its position. If you see another trendline sitting at the same place... drag that line away too... you will probably see yet another trendline sitting in the exact same place.
if that's the case... then it is a programming error.
if you post your code... I am sure I can help.
Thanks for the advice. Unfortunately, that's not the issue. I've always made sure the study is executed only once per bar. I've just checked and it has drawn over 200,000 trend lines. Not sure why so many but I'll investigate. If indeed that's the right number I'm drawing then I suppose there's nothing I can do. I typically increase the horizontal spacing of the vertical lines to reduce the number and that helps a lot. I'll post a slimmed down version of the code for your interest later.
More info. There are about 2,800 shapes drawn, so 200,000 trend lines sounds about right. The lack of a proper memory cleanup is another issue and a general concern. As Andrew stated in another topic it may be a MS Windows issue perhaps specific to my PC (not surprising really). However, it should be looked at just in case. I posted a simple study to demonstrate that point in a small way.
- Andrew Kirillov
- Posts: 1589
- Joined: 28 Jul 2005
- Has thanked: 2 times
- Been thanked: 31 times
- Contact:
If you really draw 200,000 lines there is no charting software on this planet that can handle it! You do what is not supposed to be done with a program. There is not a memory leak; we just need to store the objects somewhere.
In my experience MultiCharts works fine with about 1000 trend line plotted. However you should know it is very cpu an memory intensive task to handle so many graphical objects and repaint it on each bar. We must know if each trendline is in the visible part of the screen and if answer is yes and the trendline is moving we must repaint a chart. It is much more intensive than just reload a last bar and shift a time series to the left. So it is problem from memory and performance point of view.
In my experience MultiCharts works fine with about 1000 trend line plotted. However you should know it is very cpu an memory intensive task to handle so many graphical objects and repaint it on each bar. We must know if each trendline is in the visible part of the screen and if answer is yes and the trendline is moving we must repaint a chart. It is much more intensive than just reload a last bar and shift a time series to the left. So it is problem from memory and performance point of view.
Hi Andrew
I also use a lot of trend Lines mainly to give the chart some visual aspect at particular occurrances
What I beleive we need is an alternative is being able to color background
P>MA color background red,or color background based on any programable occurrance,Signal sent to broker,color Background etc etc
Thanks
Milton
I also use a lot of trend Lines mainly to give the chart some visual aspect at particular occurrances
What I beleive we need is an alternative is being able to color background
P>MA color background red,or color background based on any programable occurrance,Signal sent to broker,color Background etc etc
Thanks
Milton
- TJ
- Posts: 7742
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Hi Andrew
I also use a lot of trend Lines mainly to give the chart some visual aspect at particular occurrances
What I beleive we need is an alternative is being able to color background
P>MA color background red,or color background based on any programable occurrance,Signal sent to broker,color Background etc etc
Thanks
Milton
here's how you cheat:
http://www.traderslaboratory.com/forums ... -5721.html
Andrew, once I realized how many trend lines I was drawing I knew straight away I'm stress testing MC probably to its limits. Actually, I was pleasantly surprised how well it handled that many, even the 5 or so minutes to remove the study. The only issue I have now is the lack of a complete memory cleanup when I do remove the study. But then I understand I'm doing something no one would normally do. However, it does prove there is a memory cleanup issue no matter how small it is normally.
I only turn on my shapes during my development phase so it won't be an issue once I've finished the coding. At the moment I'm working around it by plotting a vertical line every 10th bar - it copes well that way. It takes about 4-5 re-runs of the study before I run out of physical memory, and then I exit MC to release it.
.
I only turn on my shapes during my development phase so it won't be an issue once I've finished the coding. At the moment I'm working around it by plotting a vertical line every 10th bar - it copes well that way. It takes about 4-5 re-runs of the study before I run out of physical memory, and then I exit MC to release it.
.
Last edited by janus on 05 Jun 2009, edited 1 time in total.
- TJ
- Posts: 7742
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
TJ I don't think that cheat is any good to me. I need to draw shapes of different shapes, so if the cheat is to work, I would have to use two plot functions and have the background color shown only between the vertical distance between the two plots. For example, if one plots at 3000 and the other at 3100 then a colored region is shown between 300 and 3100, inclusive. Can this be achieved?
The other idea is to plot a normal bar chart instead of vertical trend lines. It amounts to the same thing. I can get almost the same effect by using a thick line so the open and close bars merge with the the vertical bar. It makes the coding more complex as I would need to keep tabs on how many shapes will be displayed at any given time as only up to 999 plots can be accommodated (minus the real ones already on display) and use the noplot function when the shape is no longer visible. I think I'll stay with the trend line method - as you say it's far easier.
An obvious new feature for MC would be a less resource rich object than the trend line - simply a line with these attributes: start date/time, end date/time, color, thickness and style. Not sure though if there would be much difference. Andrew would it work this way? Perhaps another restriction needs to be applied; not being able to change the start and end points - once drawn it's drawn. Still need to be able to delete it though.
Update: Turns out I can't use the plot function given the larger number of shapes I need to draw. Once I exceed 999 I need to re-use plot numbers no longer in use (ie, previous shape has been finalized). When I do this I see a line joining the two shapes despite the fact I'm using noplot in between the two. It appears I misunderstood the purpose of the noplot function. I can see how it's used in PlotPaintBar but that's not the way I'm using it. All it does for a single plot is it stops the display of values in the hint window. Oh well, back to using trend lines. I hope some thought is being given to introducing shape drawing in a future release.
The other idea is to plot a normal bar chart instead of vertical trend lines. It amounts to the same thing. I can get almost the same effect by using a thick line so the open and close bars merge with the the vertical bar. It makes the coding more complex as I would need to keep tabs on how many shapes will be displayed at any given time as only up to 999 plots can be accommodated (minus the real ones already on display) and use the noplot function when the shape is no longer visible. I think I'll stay with the trend line method - as you say it's far easier.
An obvious new feature for MC would be a less resource rich object than the trend line - simply a line with these attributes: start date/time, end date/time, color, thickness and style. Not sure though if there would be much difference. Andrew would it work this way? Perhaps another restriction needs to be applied; not being able to change the start and end points - once drawn it's drawn. Still need to be able to delete it though.
Update: Turns out I can't use the plot function given the larger number of shapes I need to draw. Once I exceed 999 I need to re-use plot numbers no longer in use (ie, previous shape has been finalized). When I do this I see a line joining the two shapes despite the fact I'm using noplot in between the two. It appears I misunderstood the purpose of the noplot function. I can see how it's used in PlotPaintBar but that's not the way I'm using it. All it does for a single plot is it stops the display of values in the hint window. Oh well, back to using trend lines. I hope some thought is being given to introducing shape drawing in a future release.
Last edited by janus on 07 Jun 2009, edited 2 times in total.
- TJ
- Posts: 7742
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times