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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    152 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    89 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    131 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    127 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    107 views
    0 likes
    Last Post CarlTrading  
    Working...
    X