Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawRectangle in main panel

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

    DrawRectangle in main panel

    Hi,

    I'm trying to draw a rectangle based on specific time and their corresponding high/low values.

    So far I came up with this:

    Code:
            protected override void OnBarUpdate()
            {
    			if (ToTime(Time[0]) >= 10000 && ToTime(Time[0]) <= 100000) {
    				DrawRectangle("Tokyo_" + Time[0].ToString("MM/dd/yyyy"), false, 2, High[2], 1, Low[2], Color.Transparent, Color.Cyan, 3);
    			}
    			if (ToTime(Time[0]) >= 90000 && ToTime(Time[0]) <= 180000) {
    				DrawRectangle("London_" + Time[0].ToString("MM/dd/yyyy"), false, 2, High[2], 1, Low[2], Color.Transparent, Color.Yellow, 3);
    			}
    			if (ToTime(Time[0]) >= 140000 && ToTime(Time[0]) <= 230000) {
    				DrawRectangle("NewYork_" + Time[0].ToString("MM/dd/yyyy"), false, 2, High[2], 1, Low[2], Color.Transparent, Color.Fuchsia, 3);
    			}
            }
    I know I have to replace the 2, High[2],1 Low[2] etc values for StartTime and EndTime values. But I need to know how to also lookup the highest and lowest barvalues for that timespan.

    Is there some function like FindHighByTime(time) to find the high price of the bar of the time I gave? And ofcourse also something like FindLowByTime.

    Or maybe something like NumberOfBarsSinceTime(time).. If I have the number of bars, the I can use Highest[<and use the value the last function gave me>]

    Looking forward to your suggestions.
    Last edited by siroki; 05-24-2014, 06:11 AM.

    #2
    Originally posted by siroki View Post
    Hi,

    I'm trying to draw a rectangle based on specific time and their corresponding high/low values.

    So far I came up with this:

    Code:
            protected override void OnBarUpdate()
            {
                if (ToTime(Time[0]) >= 10000 && ToTime(Time[0]) <= 100000) {
                    DrawRectangle("Tokyo_" + Time[0].ToString("MM/dd/yyyy"), false, 2, High[2], 1, Low[2], Color.Transparent, Color.Cyan, 3);
                }
                if (ToTime(Time[0]) >= 90000 && ToTime(Time[0]) <= 180000) {
                    DrawRectangle("London_" + Time[0].ToString("MM/dd/yyyy"), false, 2, High[2], 1, Low[2], Color.Transparent, Color.Yellow, 3);
                }
                if (ToTime(Time[0]) >= 140000 && ToTime(Time[0]) <= 230000) {
                    DrawRectangle("NewYork_" + Time[0].ToString("MM/dd/yyyy"), false, 2, High[2], 1, Low[2], Color.Transparent, Color.Fuchsia, 3);
                }
            }
    I know I have to replace the 2, High[2],1 Low[2] etc values for StartTime and EndTime values. But I need to know how to also lookup the highest and lowest barvalues for that timespan.

    Is there some function like FindHighByTime(time) to find the high price of the bar of the time I gave? And ofcourse also something like FindLowByTime.

    Or maybe something like NumberOfBarsSinceTime(time).. If I have the number of bars, the I can use Highest[<and use the value the last function gave me>]

    Looking forward to your suggestions.
    MAX(), MIN(), GetBar().

    Look them up in the NT Help, a very useful resource, but only if we use it.

    Comment


      #3
      Ah! I didnt know about GetBar().. Solves my problem. Thanks. Here is how I did it.

      It shows the overlapping period between two sessions. Rectacle updates along with the high/low of that overlapping period.

      Code:
              protected override void OnBarUpdate()
              {
      			int year 	= Convert.ToInt16(Time[0].ToString("yyyy"));
      			int month	= Convert.ToInt16(Time[0].ToString("MM"));
      			int day 	= Convert.ToInt16(Time[0].ToString("dd"));
      			
      			if (ToTime(Time[0]) >= 90000 && ToTime(Time[0]) <= 100000) {
      				int barsAgo = CurrentBar - Bars.GetBar(new DateTime(year, month, day, 9, 0, 0));
      				DrawRectangle("Tokyo_London" + Time[0].ToString("MM/dd/yyyy"), false, barsAgo, Highs[0][HighestBar(High, barsAgo)], 0, Lows[0][LowestBar(Low, barsAgo)], Color.Transparent, Color.Cyan, 6);
      			}
      			if (ToTime(Time[0]) >= 140000 && ToTime(Time[0]) <= 180000) {
      				int barsAgo = CurrentBar - Bars.GetBar(new DateTime(year, month, day, 14, 0, 0));
      				DrawRectangle("London_NewYork" + Time[0].ToString("MM/dd/yyyy"), false, barsAgo, Highs[0][HighestBar(High, barsAgo)], 0, Lows[0][LowestBar(Low, barsAgo)], Color.Transparent, Color.Yellow, 6);
      			}
              }
      Last edited by siroki; 05-24-2014, 08:25 AM.

      Comment


        #4
        Hello Siroki,

        Thank you for your post and update.

        Glad you were able to find your answer.

        Let us know if we can be of further assistance.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Finished up my indicator and put it up for general use. Enjoy.

          Comment

          Latest Posts

          Collapse

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