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

Drawing a Progressive Weekly Reference Line

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

    Drawing a Progressive Weekly Reference Line

    Dear Support,

    I need to draw a simple progressive horizontal line starting on the open (RTH) of the current market week and extending progressively into the close of the current market week and ends there. I do not want to use DateTime in Draw.Line() statement, if possible, since every Friday or Monday may not be a trading day.

    I could not find an example in Help section and looking for just the Draw.Line() code that would accomplish that. Any sample snippet or idea would be appreciated?

    Many Thanks

    #2
    Hello aligator,

    The line would like likely need to be updated on each new bar to extend to the current bar until the desired end date time is reached.

    Is the primary series using RTH as the Trading hours template?

    If so, are you wanting to draw a line from when Bars.IsFirstBarOfSession is true and the DayOfWeek is Sunday, up to the current bar until Friday?


    If not, are you adding a secondary series with a different trading hours template?

    Are you wanting to get the time of a session open from a SessionIterator?


    Is this an indicator?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      If I understand you right, you're saying the Y-value (aka price) of that
      line does not change for an entire week?

      Hmm, why not store the dates and Y-values in a file?

      The point is:
      Your 'drawing' indicator which draws the line can then consult this
      file, figure out which date to use, and then draw the line at the
      price found from this file.

      The task of updating this file, esp if maintained as a text file, is
      not that onerous if performed manually once at the start of each
      trading week.

      As a second phase, I'd recommend a separate indicator to update
      the file. Perhaps it could use a BarsRequest for minute data and
      wade through this data to get the RTH start time for the beginning
      of the week, then update the text file with this value.

      The point is:
      Separating them might get you started faster.

      I mean, write the first indicator to read from a file and get it
      up & running now so at least you have your weekly line drawn.

      Then work on the 2nd indicator to update this file based upon
      BarsRequest data, perhaps also merging the drawing code from
      the 1st indicator into this one.

      Just my 2˘.

      Comment


        #4
        This also might allow your drawing indicator to be pretty darn simple.

        I mean, it could probably just use a simple Plot to draw the line at the
        current known Y-value. [Oops, I mean it stores the current Y-value
        and the default Plot method draws your plot as a horizontal line, just
        like for any other plot where the plot value stays constant.]

        If you promise to manually update the date & Y-value at the start of
        each week, and if you promise to exit/restart NinjaTrader after you
        update this file, then the code to find the correct Y-value can run at
        State.DataLoaded, and everything works fine ... until next week,
        when you need to manually update the file again.

        The manual effort is small, and really doesn't sound all that bad.
        Last edited by bltdavid; 06-03-2020, 04:36 PM.

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello aligator,

          The line would like likely need to be updated on each new bar to extend to the current bar until the desired end date time is reached.

          Is the primary series using RTH as the Trading hours template?

          If so, are you wanting to draw a line from when Bars.IsFirstBarOfSession is true and the DayOfWeek is Sunday, up to the current bar until Friday?


          If not, are you adding a secondary series with a different trading hours template?

          Are you wanting to get the time of a session open from a SessionIterator?


          Is this an indicator?
          Thank you Chelsea.

          Simply, I am trying to use the PriorWeek's Close as a constant, and draw a line from the Open of the Monday RTH Session ending on the last bar of the current Friday RTH session close.

          I know I can do this similar to PriorWeekOHLC indicator, and I have already done it as a plot. However, when plotted as a solid line, the solid line unlike the Hash and Dash, does continue between session breaks like a zigzag(as is also the case with PriorWeekOHLC indicator).

          I want the prior week close plotted as a solid line separately (same as a Hash or Dash lines) for each week. That is why I want to use Draw.Line instead of a plot, if possible.

          Many thanks.




          Comment


            #6
            Originally posted by aligator View Post
            Simply, I am trying to use the PriorWeek's Close as a constant, and draw a line from the Open of the Monday RTH Session ending on the last bar of the current Friday RTH session close.

            I know I can do this similar to PriorWeekOHLC indicator, and I have already done it as a plot. However, when plotted as a solid line, the solid line unlike the Hash and Dash, does continue between session breaks like a zigzag(as is also the case with PriorWeekOHLC indicator).

            I want the prior week close plotted as a solid line separately (same as a Hash or Dash lines) for each week. That is why I want to use Draw.Line instead of a plot, if possible.
            I discovered a little known trick that worked well in NT7. I haven't
            tried it yet in NT8, but give it a shot, see if it works for your case.

            I believe if you call Reset on one plot value (say, the very first one of
            the new trading week) this 'invalid' value will cause the default Plot
            method to not connect the next plot value back to the previous one,
            since the previous one will be an unknown value.

            This should achieve the effect you're looking for. That is, I think
            you're wanting to remove the 'zig-zag' look created when the Plot
            method connects two adjacent (but different) plot values at your
            trading week boundary.



            Comment


              #7
              Hello aligator,

              Are you referring to the Prior Week Ohlc found on the Use App Share?
              This is a conversion of the NT7 indicator Prior Week OHLC Added option to turn off any particular plot (Prior weeks Open, High, Low or Close.) Please make sure you have enough data so that the indicator can calculate the OHLC of the previous week(s).


              This indicator calculates the new week with:
              newWeek = Time[0].Date.AddDays(7 - (int)Time[0].DayOfWeek);

              This is taking the time of the current bar and using 7 minus the day of the week as a number (starting with sunday) to add the number of days left until the next week to the current date. (Setting the time the next week starts).
              When the current date is now beyond that date, we know the next week has started.

              This can be used for deciding when to use a new tag name for new line if you want to use Draw.Line().


              For the startTime parameter to Draw.Line use the Time of the current bar minus the day of week (which should give you the most recent sunday) and the Time of the current bar as the endTime parameter.

              Time[0].AddDays(-(int)Time[0].DayOfWeek)




              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi aligator,

                If you still need help with this I have posted some useful base code and an indicator base to do this.
                Here is the post:
                Hi, I would like to change the "AddPlot" to "Draw.Line" because I don't like Dash, Line due to the noise every new open week, day, etc and I don't like Solid, Hash because there is much noise in the chart. I sent 2 pictures for examples and the indicator code in the CurrentWeekOHL.cs file. Especially I

                Look till the end of the post.

                I was searching exactly the same as you!!

                Click image for larger version

Name:	fetch?id=1180965&d=1638984003.png
Views:	309
Size:	48.8 KB
ID:	1180970

                Comment


                  #9
                  Originally posted by joselube001 View Post
                  Hi aligator,

                  If you still need help with this I have posted some useful base code and an indicator base to do this.
                  Here is the post:
                  https://ninjatrader.com/support/foru...into-draw-line
                  Look till the end of the post.

                  I was searching exactly the same as you!!

                  Click image for larger version  Name:	fetch?id=1180965&d=1638984003.png Views:	0 Size:	48.8 KB ID:	1180970
                  Thanks. I did kind of get it to work at least for my objective, which was to plot the Expected Move projected for the current week based on the last week's close. Black is the last week close and red and green are the expected move for the current week.

                  As you see I had to use Hash instead of solid line to avoid a solid continuous line. Also, there is an indicator, CurrentDayOHL.cs, on NT that will essentially do the same (can make H&L transparent and show only the Open). However the use of session iterator is the key.

                  Cheers!
                  Attached Files
                  Last edited by aligator; 12-09-2021, 12:24 AM.

                  Comment


                    #10
                    Originally posted by aligator View Post

                    Thanks. I did kind of get it to work at least for my objective, which was to plot the Expected Move projected for the current week based on the last week's close. Black is the last week close and red and green are the expected move for the current week.

                    As you see I had to use Hash instead of solid line to avoid a solid continuous line. Also, there is an indicator, CurrentDayOHL.cs, on NT that will essentially do the same (can make H&L transparent and show only the Open). However the use of session iterator is the key.

                    Cheers!
                    Hi!

                    Your indicator works nicely!! almost all months is touching the upper or lower line. Excellent!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by adeelshahzad, Today, 03:54 AM
                    5 responses
                    32 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by stafe, 04-15-2024, 08:34 PM
                    7 responses
                    32 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by merzo, 06-25-2023, 02:19 AM
                    10 responses
                    823 views
                    1 like
                    Last Post NinjaTrader_ChristopherJ  
                    Started by frankthearm, Today, 09:08 AM
                    5 responses
                    21 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    43 views
                    0 likes
                    Last Post jeronymite  
                    Working...
                    X