NexusFi: Find Your Edge


Home Menu

 





Performance problem with DrawRectangle


Discussion in NinjaTrader

Updated
    1. trending_up 3,355 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 decs0057 
Munich, Germany
 
Experience: Intermediate
Platform: NinjaTrader, TWS
Broker: IB, NinjaTrader Brokerage
Trading: ES,NQ,6E
Posts: 73 since Feb 2010
Thanks Given: 15
Thanks Received: 25

I want to draw a zone arround horizontial lines (Pivot's)
and use following code

for (int i = 0; (i < base.Values.Length) && (base.Values[i].Count > 0); i++)
{
double value = base.Values[i][0];
double yH = value + zoneSize * TickSize;
double yL = value - zoneSize * TickSize;
Color colorZone = Plots[i].Pen.Color;
if( colorZone != Color.Transparent )
{
if( zoneShowAll )
{
DrawRectangle(
string.Format( "Zone{0}_{1}", i, CurrentBar ),
false,
Displacement+1,
yH,
Displacement,
yL,
Color.Transparent,
Plots[i].Pen.Color,
zoneOpacity );
}
else
{
DrawRectangle(
string.Format( "Zone{0}", i ),
false,
Displacement+width+1,
yH,
Displacement,
yL,
Color.Transparent,
Plots[i].Pen.Color,
zoneOpacity );
}
}
}
}

Problem is that load of indicator is very slow.

Any idea how to improve load time


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
What we know about Binances $6.3bn hack - BBC News
Cryptocurrency
Bitcoin’s 2022 low, 2025 high and 2026 low so far arou …
Cryptocurrency
[WTS] ATAS Lifetime ULTRA license – EU buyers only – …
Platforms and Indicators
Building a free browser DOM/SMC simulator - need some ad …
Platforms and Indicators
 
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,117


If you have lot of draw objects, this has indeed a negative impact on performance and the loading of the chart may take quite a long time. This does not only affect rectangles, but also applies to arrows, diamonds and other draw objects.

What I have done for some of my indicators, is that I entered a user-selectable lookback period, for example 15 days from now. I then check for that lookback period in OnBarUpdate and only plot those rectangle if the barTime is inside that lookback period.

This speeds up the indicator, as the rectangles are not plotted over the whole lookback period of the chart.

Another way of doing it - maybe more elegant:

-> Check ChartControl for null in OnStartUp (to avoid problems if your indicator is addressed by another indicator or strategy)
-> Determine the last bar painted on your current chart.
-> Plot rectangles only, if they are within a lookback period of 15 something days counted from the last bar painted.


Reply With Quote
Thanked by:




Last Updated on August 5, 2011


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts