Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Have only one drawing object, not many

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

    Have only one drawing object, not many

    hi, I want to draw a dot on all occasions, not just last occurence. Currently with this code it only plots last occurence.
    if I add
    Draw.Dot(this, "ShortStopDz"+CurrentBar, false, 0, trapGoLongLevel, Brushes.GreenYellow) then it adds dot on all of the bars that are High0 < high1 and I want it only to plot once the very last occurence.
    How can i do this?



    else if (isShortEntry)
    {
    trapGoLongLevel = Math.Max(High[0], High[1])+(StopPlacement*TickSize);

    if(High[0] < High[1])
    {
    Draw.Dot(this, "ShortStopDz", false, 0, trapGoLongLevel, Brushes.GreenYellow);
    }​

    #2
    Hello tkaboris,

    Thank you for your post.

    I'm a bit confused by your post.

    First you state:

    Currently with this code it only plots last occurence. I want to draw a dot on all occasions, not just last occurence. Currently with this code it only plots last occurence.
    Then your very next sentence states:

    then it adds dot on all of the bars that are High0 < high1 and I want it only to plot once the very last occurence.
    These are two conflicting statements. Do you want the dot to be drawn for every occurrence of High[0] < High[1] (all occurrences), or only on the last occasion this event occurred?
    Last edited by NinjaTrader_Gaby; 06-27-2024, 12:10 PM.

    Comment


      #3
      Thank for clarifing. I wanted to plot dot on the chart in all occurences, and only once insde the condition high[0] < high[1]

      Ok I can modify it and it works.

      RemoveDrawObject("ShortStopDz");
      Draw.Dot(this, "ShortStopDz", false, 0, trapGoLongLevel, Brushes.GreenYellow);​

      However it only plots recent occurence on the chart and I want to plot it on all occurnce on the chart.
      If I add Current Bar, its not working as suppose, my guess is that CurrentBar is not unique in this case?
      RemoveDrawObject("ShortStopDz"+CurrentBar);
      Draw.Dot(this, "ShortStopDz"+CurrentBar, false, 0, trapGoLongLevel, Brushes.GreenYellow);​

      Comment


        #4
        Like I wanted only last green dot to show and remove previous 2
        Click image for larger version

Name:	image.png
Views:	125
Size:	23.8 KB
ID:	1308899

        Comment


          #5
          Hello tkaboris,

          Thank you for your response.

          I'm not sure what you mean by "only plot the dot in all occurrences, and only once inside the condition" - what do you mean by "inside the condition"? Are you seeing multiple dots drawn per bar? Your screenshot shows 1 dot drawn per bar.

          Can you clarify why you are calling RemoveDrawObject() before Draw.Dot()? What is the intended behavior?

          Your responses directly contradict themselves.

          I wanted to plot dot on the chart in all occurences
          I wanted only last green dot to show
          You are saying you want to plot the dot in all occurrences, but then your post with the screenshot says you only want the last green dot to show. Which one is the desired behavior? Do you want all occurrences or only the last occurrence?

          Code:
          if (High[0] < High[1])
          {
          //This will draw a red dot only on the most recent occurrence.
          Draw.Dot(this, "tag1", true, 0, Low[0] - TickSize, Brushes.Red);
          
          //This will draw a blue dot on every single occurrence.
          Draw.Dot(this, "tag1" + CurrentBar, true, 0, Low[0] - TickSize, Brushes.Blue);
          }
          ​CurrentBar is the current bar processing in OnBarUpdate, so it is unique per bar. Adding CurrentBar to the tag name would be the way to go if you want the dot to be drawn for every occurrence of the event.

          If you are not seeing the dot being drawn when expected, you'll need to debug the script using prints.

          https://support.ninjatrader.com/s/article/Developer-Guide-Debugging-using-Print-and-TraceOrders

          I am also attaching a sample script that draws a dot on every occurrence of High[0] < High[1] using the above code.
          It also includes commented-out code to demonstrate only drawing on the most recent occurrence, you can uncomment this portion to see the difference in behavior.
          Attached Files
          Last edited by NinjaTrader_Gaby; 06-27-2024, 01:41 PM.

          Comment


            #6
            hi. So to clarify. I want to be able to show green dots but only last occurence inside condition. For example at 11:56 I got the condition and dot prints, when next bar 11:57 prints i want green dot to show and previous dot to be removed, and so on, while inside the condition I only want to print last occurence. Samething on all previous conditions on the chart,

            Click image for larger version

Name:	image.png
Views:	123
Size:	261.6 KB
ID:	1308904​​
            Attached Files

            Comment


              #7
              NinjaTrader_Gaby

              Using your example above, I want to print dot only once as most recent last occurence inside condition high0 < high1 and I guess remove previous ones from same impulse. You can refer to post above what I mean. If I simply remove +CurrentBar tag, it will only show last ocurence in the chart but I want to display in all charts where this condition occurs. Can you please help?


              protected override void OnBarUpdate()
              {
              if (CurrentBar < 1) return;

              if (High[0] < High[1])
              {
              //This will draw a red dot only on the most recent occurrence
              //Draw.Dot(this, "tag1", true, 0, Low[0] - TickSize, Brushes.Red);

              //This will draw a blue dot on every single occurrence
              Draw.Dot(this, "tag1" + CurrentBar, true, 0, Low[0] - TickSize, Brushes.Blue);
              }
              }​

              Comment


                #8
                Hello tkaboris,

                Thank you for your response.

                If you only want the most recent occurrence, do not use CurrentBar. There is also no need to use RemoveDrawObject() to remove previous instances using this method.

                I want to print dot only once as most recent last occurence
                it will only show last ocurence in the chart but I want to display in all charts where this condition occurs. Can you please help?
                What exactly do you mean by you want to "display in all charts where this condition occurs"?

                Are you perhaps looking to create a global drawing object, so that the dot is drawn on all charts with the same instrument, and not just the chart your indicator is applied to?

                If this is the case, use the isGlobal overload set to true. ​

                Draw.Dot(NinjaScriptBase owner, string tag, bool isAutoScale, int barsAgo, double y, bool isGlobal, string templateName)


                If this isn't the case, can you please describe in more detail exactly what you mean by "in all charts where this condition occurs"?

                Comment


                  #9
                  If I remove CurrentBar then only last occurence of greendot will be shown (around 11:50 on the chart) and all the other ones that I marked with arrows will not be on the chart. I want them to show on the chart. But As you see when condition appears, i dont want many dots, only last occurence

                  Click image for larger version

Name:	image.png
Views:	127
Size:	338.8 KB
ID:	1309056

                  Comment


                    #10
                    Here is an example, on the right side it prints only one most recent time, where on the left side it starts printing from condition and prints many dots. I want like on right side

                    Click image for larger version

Name:	image.png
Views:	130
Size:	400.9 KB
ID:	1309058

                    Comment


                      #11
                      Hello tkaboris,

                      Respectfully, what you are saying isn't making logical sense.

                      all the other ones that I marked with arrows will not be on the chart. I want them to show on the chart.
                      I dont want many dots, only last occurence
                      You said you want them "all to show on the chart" then said "only the last occurrence". You can't simultaneously have all the dots on the chart and only the last occurrence. That's not possible.


                      What are the arrows pointing to exactly? Not all of the arrows are even pointing to bars drawn with dots on them.

                      What is the condition you want these drawings to be drawn under? Is it when (High[0] < High[1])?

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      557 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      324 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
                      545 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      547 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X