Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple historical drawing objects, but drawn once.

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

    Multiple historical drawing objects, but drawn once.

    Good Evening,

    If I wanted to draw something simple, say a line, at a specific time and price each day, but using drawing objects and not a plot, I could do this with ("Name" + CurrentBar).

    However, this draws over the object multiple times when done through OnBarUpdate based on what calculate is set to.

    How can I draw historical drawing objects, but only once as to not overload the number of drawing objects?

    #2
    Take away the + CurrentBar part and they'll all be tagged just "Name" - when the second one is drawn it will REPLACE the first one rather than adding a new one.

    If you want it to only draw once per bar but you have Calculate set to OnEachTick or OnPriceChange, consider waiting until the end of the bar and then draw the newly completed bar's drawing object, one bar back. That would only draw it once per bar, even if it's "Name" + CurrentBar.

    You can use .IsFirstTIckOfBar to detect if it's a new bar, and then draw the newly completed one using Time[1] for the DateTime or 1 for the bar index back depending on how you are drawing.
    Last edited by QuantKey_Bruce; 04-24-2023, 05:01 AM.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Originally posted by QuantKey_Bruce View Post
      Take away the + CurrentBar part and they'll all be tagged just "Name" - when the second one is drawn it will REPLACE the first one rather than adding a new one.

      If you want it to only draw once per bar but you have Calculate set to OnEachTick or OnPriceChange, consider waiting until the end of the bar and then draw the newly completed bar's drawing object, one bar back. That would only draw it once per bar, even if it's "Name" + CurrentBar.

      You can use .IsFirstTIckOfBar to detect if it's a new bar, and then draw the newly completed one using Time[1] for the DateTime or 1 for the bar index back depending on how you are drawing.
      Removing + CurrentBar will make the drawing object "update" vice "replicate". I want a new line added each day at the appropriate time/price, I just dont want it drawn every bar making additional drawing objects. I think I'm missing something simple, just dont know what it is.

      Comment


        #4
        Only draw it when there is a new one. Don't just keep redrawing it every time OnBarUpdate runs.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Originally posted by QuantKey_Bruce View Post
          Only draw it when there is a new one. Don't just keep redrawing it every time OnBarUpdate runs.
          That is the part I am trying to figure out and the nature of this post. Here is a snippet below:

          Code:
          mTime = 000000 + (BarsPeriod.Value*100);
          
          if (ToTime(Time[0]) == mTime)
          {
          mPrice = Open[0];
          mBar = CurrentBar;
          }
          
          Draw.Line(this, "Midnight", true, CurrentBar - mBar, mPrice, -1, mPrice, newMidnightColor, DashStyleHelper.Dash, 1, true);
          In the above, I am grabbing the price of the midnight bar open. I want to than draw a line of that price until the value changes (aka new midnight price forms next day). The above code draws it once. When adding + CurrentBar to the tag, it draws it every bar. which leads to numerous overlapping drawing objects. Im unsure how to wrap the Draw.Line to make it only draw once per updated value but also extend to current bar until a new value updates as this would require redrawing each bar wouldnt it?
          Last edited by ChrisR; 04-24-2023, 07:31 AM.

          Comment


            #6
            Move the Draw.Line inside the "if" condition so it only does it on the bar that is in question if that is what you are trying to do, and instead of using the bar number for the time from and to, use the DateTime. So, for instance, you might use Time[0].Date for the start and Time[0].Date.AddDays(1) or Time[0].Date.AddDays(-1) for the end of the line. You can also do AddMinutes or AddHours or whatever.
            Bruce DeVault
            QuantKey Trading Vendor Services
            NinjaTrader Ecosystem Vendor - QuantKey

            Comment


              #7
              Hello ChrisR,

              You might find these indicators helpful:
              Current Day Open-High-Low: https://ninjatrader.com/support/help...nt_day_ohl.htm
              Prior Day Open-High-Low-Close: https://ninjatrader.com/support/help...r_day_ohlc.htm

              What you're specifically asking for is Current Day Open: CurrentDayOHL().CurrentOpen[0];

              Hope that helps!
              Matt

              Comment


                #8
                Originally posted by StealthM93 View Post
                Hello ChrisR,

                You might find these indicators helpful:
                Current Day Open-High-Low: https://ninjatrader.com/support/help...nt_day_ohl.htm
                Prior Day Open-High-Low-Close: https://ninjatrader.com/support/help...r_day_ohlc.htm

                What you're specifically asking for is Current Day Open: CurrentDayOHL().CurrentOpen[0];

                Hope that helps!
                Matt
                Thanks, but Im not specifically looking for a data point that can be provided by an existing function, Im looking to understand how to draw multiple drawing objects without duplicating them every bar.

                Comment


                  #9
                  Originally posted by QuantKey_Bruce View Post
                  Move the Draw.Line inside the "if" condition so it only does it on the bar that is in question if that is what you are trying to do, and instead of using the bar number for the time from and to, use the DateTime. So, for instance, you might use Time[0].Date for the start and Time[0].Date.AddDays(1) or Time[0].Date.AddDays(-1) for the end of the line. You can also do AddMinutes or AddHours or whatever.
                  Will give this a shot, thanks!

                  Comment


                    #10
                    Originally posted by QuantKey_Bruce View Post
                    Move the Draw.Line inside the "if" condition so it only does it on the bar that is in question if that is what you are trying to do, and instead of using the bar number for the time from and to, use the DateTime. So, for instance, you might use Time[0].Date for the start and Time[0].Date.AddDays(1) or Time[0].Date.AddDays(-1) for the end of the line. You can also do AddMinutes or AddHours or whatever.
                    Code:
                    double MidMin = BarsPeriod.Value;
                    DateTime startM = new DateTime(Time[0].Year,Time[0].Month,Time[0].Day,00,00,00);
                    DateTime startM1 = startM.AddMinutes(MidMin);
                    DateTime endM = new DateTime(Time[0].Year,Time[0].Month,Time[0].Day,23,00,00);
                    
                    if (ToTime(Time[0]) == 000000 + (BarsPeriod.Value*100))
                    Draw.Line(this, "Midnight"+CurrentBar, true, startM1, mPrice, endM, mPrice, newMidnightColor, DashStyleHelper.Dash, 1, true);
                    Thanks for the help, was able to get it draw historical midnight open price lines without duplicating every bar using the above. Do you see anywhere to make this more efficient?​​
                    Last edited by ChrisR; 04-24-2023, 09:13 AM.

                    Comment


                      #11
                      Well, startM could be Time[0].Date;
                      endM could be startM.AddHours(23);

                      there are little things like that you could do to simplify and clarify.

                      If you're running Calculate.OnBarClose this is enough - if you're running intrabar like OnPriceChange or OnEachTick you'll want to make sure you're not doing this multiple times per bar.
                      Bruce DeVault
                      QuantKey Trading Vendor Services
                      NinjaTrader Ecosystem Vendor - QuantKey

                      Comment


                        #12
                        Originally posted by QuantKey_Bruce View Post
                        Well, startM could be Time[0].Date;
                        endM could be startM.AddHours(23);

                        there are little things like that you could do to simplify and clarify.

                        If you're running Calculate.OnBarClose this is enough - if you're running intrabar like OnPriceChange or OnEachTick you'll want to make sure you're not doing this multiple times per bar.
                        Makes sense, thanks again.

                        Comment


                          #13
                          When applying the above, I noticed the drawing object wont draw past 1700(5pm est) the day prior despite what the DateTime is set to.

                          For example:
                          Code:
                          DateTime Start1 = new DateTime(Time[0].Year,Time[0].Month,Time[0].Day-1,14,00,00);
                          DateTime End1 = new DateTime(Time[0].Year,Time[0].Month,Time[0].Day-1,20,00,00);
                          
                          Draw.Line(this, "Test", true, Start1, TestPrice, End1, TestPrice, LineColor, DashStyleHelper.Dash, 1, true);
                          In the above I am trying to draw a line between 1400 and 2000 the day prior hence the Time[0].Day-1. However, once drawn, the start of the line begins at 1700 not 1400. This is on an NQ chart, which has a session break time of 1700, so not sure if that has to do with it.​

                          Comment


                            #14
                            You can't just do Day-1 - what if Time[0] was April 1? Would that go to April 0? Try using something more like DateTime Start1 = Time[0].Day.AddDays(-1).AddHours(14) because that will work properly for these situations. That may not be the only problem but that is a problem.
                            Bruce DeVault
                            QuantKey Trading Vendor Services
                            NinjaTrader Ecosystem Vendor - QuantKey

                            Comment


                              #15
                              Didn't think of that, thanks for that, would of definitely caused issues in the future. Made that adjustment but still getting the line starting at 1700 for some reason. There are no conditional restrictions for the drawing object, so the only thing I can think of is the session time for the asset causing some type of manipulation on the object.

                              Code:
                              DateTime Start1 = Time[0].Date.AddDays(-1).AddHours(14).AddMinutes(BarVal);
                              DateTime End1 = Time[0].Date.AddDays(-1).AddHours(20);​
                              
                              Draw.Line(this, "Test", true, Start1, TestPrice, End1, TestPrice, LineColor, DashStyleHelper.Dash, 1, true);

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              671 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X