Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 andrewtrades, Today, 04:57 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          3 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X