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

Draw rectangle

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

    Draw rectangle

    Hi Guys, I'm trying to draw a rectangle at the same time slot each day. The chart may go back 30 days so needs to draw a rectangle for each day. I'm using the code in this thread.



    The problem with this code is it only draws the rectangle on the current day so would like to know how to draw the rectangle for each day on the chart.

    Thanks in advance
    DJ

    #2
    Hello djkiwi,

    Using the following code:

    Code:
    DrawRectangle("ColorCloseRange", false, startDateTime, 1000, endDateTime, 1200, Color.Red, Color.Yellow,10);
    With the tag being the same name it will override if it is called again. So if you would like to keep the old drawing objects you may want to do something like:

    Code:
    DrawRectangle("ColorCloseRange"+CurrentBar, false, startDateTime, 1000, endDateTime, 1200, Color.Red, Color.Yellow,10);
    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hello, experienced guys.

      I would like to do , showed in attached picture below.
      How to draw the rectangle starts from right side of the chart?

      I don't need to draw on history. Would like to redraw on every bar update.

      Thanks in advance !
      Attached Files
      Last edited by akushyn; 12-17-2013, 10:29 PM.

      Comment


        #4
        Originally posted by akushyn View Post
        Hello, experienced guys.

        I would like to do , showed in attached picture below.
        How to draw the rectangle starts from right side of the chart?

        I don't need to draw on history. Would like to redraw on every bar update.

        Thanks in advance !

        On a chart with equidistant bars you can use negative values for startBarsAgo and endBarsAgo. You can also code a custom plot and directly draw on the chart panel.
        Attached Files

        Comment


          #5
          Hello akushyn,

          Drawing object in the future can get a bit complicated but if it is a time based series and equidistant bars it should work mostly like you would expect but it is not something that we can really support since you are accessing values on a chart that are not present yet.

          Negative values as Harry suggested will work and you may also add time to the DateTime series as well that you may try for example:

          Code:
          if(!Historical)
          	DrawRectangle("ColorCloseRange", false, Time[0], Low[0], Time[0].AddMinutes(5), High[0], Color.Red, Color.Yellow,10);
          JCNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_JC View Post
            Hello akushyn,

            Drawing object in the future can get a bit complicated but if it is a time based series and equidistant bars it should work mostly like you would expect but it is not something that we can really support since you are accessing values on a chart that are not present yet.

            Negative values as Harry suggested will work and you may also add time to the DateTime series as well that you may try for example:

            Code:
            if(!Historical)
            	DrawRectangle("ColorCloseRange", false, Time[0], Low[0], Time[0].AddMinutes(5), High[0], Color.Red, Color.Yellow,10);
            Thank you for your answer.
            Have another related question...

            Would like to start draw rectangle for the current day starts from start of the day 00:01 time to the last bar.
            How to get the bar time of the beginning of the current day for specified time frame ?

            The same issue is for HorizontalLine
            Last edited by akushyn; 06-28-2014, 06:57 AM.

            Comment


              #7
              akushyn,

              You would need to use Bars.GetBar(DateTime time) to get the bars at 00:01 and the end bar.

              However, you won't want to use the Horizontal line as this will draw a line continuously. You would want to use DrawLine().

              http://www.ninjatrader.com/support/h...tml?getbar.htm

              Let me know if I can be of further assistance.
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Thanks for DrawLine().

                I used :
                Code:
                DateTime startDateTime;
                DateTime endDateTime;
                Bars.Session.GetNextBeginEnd(Bars, 0, out startDateTime, out endDateTime);
                
                ...
                
                DrawLine("mavVolPrice", false, startDateTime, maxVolumeOfPrevDay, endDateTime, maxVolumeOfPrevDay, Color.Red, DashStyle.Dash, 2);
                Now I have what I wish first ))
                Further, how is it possible to see such rectangles also on history, cause I see only the last day ?
                Attached Files
                Last edited by akushyn; 06-28-2014, 11:29 PM.

                Comment


                  #9
                  Hello akushyn,

                  Thank you for your response.

                  You can use the example provided by JC for both the DrawLine() and DrawRectangle():
                  Originally posted by NinjaTrader_JC View Post
                  Code:
                  DrawRectangle("ColorCloseRange"+CurrentBar, false, startDateTime, 1000, endDateTime, 1200, Color.Red, Color.Yellow,10);
                  This uses CurrentBar in the tag to allow it to draw multiples of the object. However, we would need to include some way to limit the drawing to once a day rather than drawing multiple objects for each bar of the day. So essentially one tag per day. This can be achieved by setting the tag only on the FirstBarOfSession:
                  Code:
                  if(Bars.FirstBarOfSession)
                  {
                  sessionTag = CurrentBar;
                  }
                  An example of using this for the DrawLine would be the following:
                  Code:
                  DrawLine("mavVolPrice" + sessionTag, false, startDateTime, maxVolumeOfPrevDay, endDateTime, maxVolumeOfPrevDay, Color.Red, DashStyle.Dash, 2);

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by samish18, 04-17-2024, 08:57 AM
                  16 responses
                  55 views
                  0 likes
                  Last Post samish18  
                  Started by arvidvanstaey, Today, 02:19 PM
                  3 responses
                  9 views
                  0 likes
                  Last Post NinjaTrader_Zachary  
                  Started by jordanq2, Today, 03:10 PM
                  2 responses
                  8 views
                  0 likes
                  Last Post jordanq2  
                  Started by traderqz, Today, 12:06 AM
                  10 responses
                  18 views
                  0 likes
                  Last Post traderqz  
                  Started by algospoke, 04-17-2024, 06:40 PM
                  5 responses
                  47 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X