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 basic example

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

    Draw Rectangle basic example

    I just created a new Indicator with everything set to Default. Then I pasted in the two examples of Draw.Rectangle shown in the doc's:
    Code:
    		protected override void OnBarUpdate()
    		{
    			Draw.Rectangle(this, "tag1", 10, Low[10] - TickSize, 5, High[5] + TickSize, Brushes.Blue);
    			Draw.Rectangle(this, "tag2", false, 10, Low[10] - TickSize, 5, High[5] + TickSize, Brushes.PaleGreen, Brushes.PaleGreen, 2);
    }

    These examples don't work. Can you tell me what I might be doing wrong?

    #2
    Hello swcooke,

    Thanks for your post.

    The sample in the help guide requires 10 bars before being called. You will see an error in the log tab of the Control Center explaining why the indicator has aborted.

    Please see the "Making sure you have enough bars in the data series you are accessing" page of the help guide for more details - https://ninjatrader.com/support/help...nough_bars.htm

    If have any additional questions, please don't hesitate to ask.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello swcooke,

      Editted post: We saw your reply, but it looks like you have resolved your inquiry.

      Please let us know if this is not the case.
      Last edited by NinjaTrader_Jim; 05-31-2018, 11:53 AM.
      JimNinjaTrader Customer Service

      Comment


        #4
        I was trying to draw shapes on the bars as an indicator. It appears this creates a shape that looks more like a drawing tool. What part of the API should I be using if I want to draw shapes on each bar as an Indicator?

        Comment


          #5
          Hello swcooke,

          Drawing Tools (which also get exposed for NinjaScript use) will be the easiest way to draw on a chart. You can use Drawing Tools like Draw.Diamond, Draw.Dot, Draw.Square and Draw.ArrowUp to place a single drawing object on one bar slot instead of using a Drawing Tool that spans multiple slots.

          More complex shapes can be created with custom rendering.

          For the thread's reference, each Drawing Tool's NinjaScript method can be referenced here - https://ninjatrader.com/support/help...us/drawing.htm

          Please let us know if you have any additional questions.
          JimNinjaTrader Customer Service

          Comment


            #6
            I am trying to draw a dot on every bar in the chart. Here is my code:

            Code:
            Draw.Dot(this, "tag1", true, CurrentBar, Low[CurrentBar] - TickSize, Brushes.Red);
            What am I doing wrong?

            Comment


              #7
              Hello swcooke,

              You are specifying a BarIndex in a BarsAgo index. With each new bar, CurrentBar increases and you use this value in the Drawing Tool's BarsAgo parameter and the BarAgo index for the Low price series. You are essentially drawing the dot on the first bar over and over at the first bar's low.

              A BarsAgo of 0 will always represent the current bar/bar that has just been closed. CurrentBar gives the bar index of the current bar. Thus, using CurrentBar in a BarsAgo reference will always point to the first bar.

              Also, if you reuse a tag for a drawing tool, you will update that drawing object to a new location rather than creating a new drawing object. To create unique drawing objects, you can add CurrentBar to your tag string.

              Please refer to the documentation below for working with Price Series to get a better understanding on BarsAgo references.

              Working with Price Series - https://ninjatrader.com/support/help...ice_series.htm

              The example code below will draw at each bar.
              Code:
              Draw.Dot(this, "tag"+CurrentBar, true, 0, Low[0] - TickSize, Brushes.Red);
              Please let me know if we can be of further assistance.
              JimNinjaTrader Customer Service

              Comment


                #8
                Just remember the more graphics on the chart the more memoryusage pluse 2^16 graphics allowed

                Comment


                  #9
                  If you really need to do this - and for the world of me I cannot understand why you'd need to do this on every bar - then you have two options:
                  1. Create another Plot which will plot your results on every bar, or
                  2. Use OnRender() to plot efficiently

                  Using OnRender() is more difficult and may be overkill for what you need. I therefore suggest option 1, creating another plot. It is efficient.

                  By the way, using Drawing Tools such as DrawDot() etc. on many charts will grind NT to a halt. I have first hand experience of this.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by mattbsea, Today, 05:44 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post mattbsea  
                  Started by RideMe, 04-07-2024, 04:54 PM
                  6 responses
                  31 views
                  0 likes
                  Last Post RideMe
                  by RideMe
                   
                  Started by tkaboris, Today, 05:13 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post tkaboris  
                  Started by GussJ, 03-04-2020, 03:11 PM
                  16 responses
                  3,282 views
                  0 likes
                  Last Post Leafcutter  
                  Started by WHICKED, Today, 12:45 PM
                  2 responses
                  20 views
                  0 likes
                  Last Post WHICKED
                  by WHICKED
                   
                  Working...
                  X