Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Which is more preferable? DrawRegion Or DrawRectangle?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Which is more preferable? DrawRegion Or DrawRectangle?

    Hi,
    (1) Assuming I do 20 DrawObjects at constant intervals ( N1 and N2 ) on chart. Which of the following methods is more preferable in terms of CPU and RAM intensive?

    int N1 = 4;
    int N2 = 20;
    double p1 = { do something here};

    [Method1 ] :

    // will be from x01 to x40
    x01.Set = (p1);
    x02.Set = (x01[0]+TickSize*N1);
    x03.Set = (x02[0]+TickSize*N2);
    x04.Set = (x03[0]+TickSize*N1);
    .
    .
    x39.Set = (x38[0]+TickSize*N2);
    x40.Set = (x39[0]+TickSize*N1);

    DrawRegion("a01", startBarsAgo, endBarsAgo, x01, x02, Color.Transparent, Color.Blue, 10);
    DrawRegion("a02", startBarsAgo, endBarsAgo, x03, x04, Color.Transparent, Color.Blue, 10);
    DrawRegion("a20", startBarsAgo, endBarsAgo, x39, x40, Color.Transparent, Color.Blue, 10);


    [Method 2] :

    // will be from x1 to x40
    double x01 = (p1);
    double x02 = (x01+TickSize*N1);
    double x03 = (x02+TickSize*N2);
    double x04 = (x03+TickSize*N1);
    .
    .
    double x39 = (x38+TickSize*N2);
    double x40 = (x39+TickSize*N1);

    DrawRectangle("b01", false, startBarsAgo, x01, endBarsAgo, x02, Color.Transparent, Color.Blue, 10);
    DrawRectangle("b02", false, startBarsAgo, x03, endBarsAgo, x04, Color.Transparent, Color.Blue, 10);
    DrawRectangle("b20", false, startBarsAgo, x39, endBarsAgo, x40, Color.Transparent, Color.Blue, 10);


    [Method 3] :

    DrawRectangle("c01", false, startBarsAgo, p1, endBarsAgo, p1+TickSize*4 , Color.Transparent, Color.Blue, 10);
    DrawRectangle("c02", false, startBarsAgo, p1+TickSize*24, endBarsAgo, p1+TickSize*28 , Color.Transparent, Color.Blue, 10);
    DrawRectangle("c20", false, startBarsAgo, p1+TickSize*340, endBarsAgo, p1+TickSize*344, Color.Transparent, Color.Blue, 10);

    #2
    Hello,

    Thanks for your forum post.

    Method 1 is the most data intensive. Method 2 and Method 3 is a tossup. As either way will work about the same. Method 3 might be a little better since your not declaring variables. But were talking an unnoticeable difference here most likely.

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    651 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    370 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    577 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X