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

NT7 / Drawline unexpected behavior

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

    NT7 / Drawline unexpected behavior

    Hi,

    I'm using NT7 and have a simple indicator that draws a line on a chart at a given level for the entire day. The basic logic is below.

    What is odd is that I can see the level on the chart starting just after midnight on the date used in the DrawLine function below. As I advance the chart, it the line scrolls out of view, and then reappears later when the price of the current bar overlaps the level of the line. However, the next time the line scrolls out of view, because no price bars overlap the level of the line, it remains out of view even when the entire range of prices on the chart would place the line somewhere in the middle. Then, it reappears about two hours later on the chart when again you would expect it to be there, leaving no explanation as to why there is an area where it doesn't appear but should.

    It's a mystery why the line is not visible even when it would theoretically be in the middle of the chart.

    DateTime lineStartDT = DateTime.Parse("3/15/2021 12:01:00 AM");
    DateTime lineEndDT = DateTime.Parse("3/15/2021 11:59:00 PM");

    double level = 1731.0
    DrawLine("myLevel", false, lineStartDT, level, lineEndDT, level, Color.Red, DashStyle.DashDot, 2);

    Does anyone see something I'm missing in how I'm drawing the line?

    Also, in real time charting, if you use a future date/time, would the line continue to extend until that date/time?

    Regards,

    Gordon

    #2
    Hello grose,

    With nt7 objects there is a situation where drawing a long line that spans past the edge of the chart it will be hidden. This is an expected way that the drawing objects work in nt7. To render a line that is always visible and has no stipulations of it being hidden would require using the Plot override to render it yourself. The platform comes with the indicator CustomPlotSample.

    Objects with greater than or equal to two anchor points can disappear while scrolling when either anchor point is far away from the display range. It is possible to have both anchors off the visible range, but still have the object and as you scroll a little bit then to have the line disappear despite both anchors still being outside the visible range.

    Future dates could be used however there is no accuracy with that as the bars into the future are currently unknown.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      Thank you. Could I work around this behavior by updating the end date line with each new bar? And is it possible to update the end date of lines you have drawn programmatically with DrawLine?

      Regards,

      Gordon

      Comment


        #4
        Hello grose,

        You could try that however I am not certain if that would work or not, we don't have any specific guidelines on that other than its an expected item in NT7. This is one thing that was addressed going forward in NT8 with drawing tools. For NT7 really the only solid suggestion I could make would be to use custom rendering with the Plot override, that would allow you to paint within the charts coordinates in any way and is not using anchors/drawing tools which have other stipulations.

        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse, thanks again. Do you happen to have a good example of overriding plot in NT7 in which you detect/respond to bars scrolling into and out of view on the chart, ideally including detecting the first visible bar and last visible bar? I poked around help but I didn't find anything that would really point me in the right direction. I'm thinking I'm going to need to custom-draw lines based on what the user has or hasn't scrolled into view on the chart.

          - Gordon

          Comment


            #6
            Hello grose,

            The only sample which we have of the plot override would be the CustomPlotSample indicator that comes with NinjaTrader. You can also view the existing indicators, some utilize that override like the zig zag and pivots. The zig zag shows how to use FirstBarIndexPainted and LastBarIndexPainted. You could loop between those indexes to know what the visible bars on the chart are currently. This area was never documented for NT7 so using existing scripts is really the only way to learn these topics. In NT8 this is replaced with the OnRender system which is documented well.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hi Jesse,

              Thanks again. Does NT8 have the same issues with lines drawn into the future disappearing when they should otherwise based on their value be visible on the chart?

              Regards,

              Gordon

              Comment


                #8
                Hello grose,

                No that had been addressed so it no longer has that stipulation on drawing objects.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Thanks, Jesse. Just to save myself some development and coding time, if you know the answer - in NT 7, if you update the ending y-axis level of a line with every new bar, rather than draw it into the future, will it appear into and disappear from view correctly, as you scroll a chart backwards and forwards in a chart? Or will it have the same issues that lines drawn into the future do - that they aren't visible at times when you expect them to be based on where price is and what the y-axis value of the line is?

                  Regards,

                  Gordon

                  Comment


                    #10
                    Hello grose,

                    Thank you for the reply.

                    While there is not a specific guideline defined for that use case I believe that it would still disappear based on the detail that we do have for the objects anchors. The details I have about this would be

                    Objects with greater than or equal to two anchor points can disappear while scrolling when either anchor point is far away from the display range.
                    Based on the "either anchor point" part if the start anchor is not on the chart its still going to be hidden based on that logic. Both anchors would need to be within the visible range to avoid that logic.

                    I believe the best way to fix this for NT7 would be to just avoid using drawing objects if possible, The Plot override would be more appropriate for the given use case. A drawing object still could be used in that situation for its anchor data but the Plot override would be needed to render when the object is not visible.


                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks, Jesse. So it looks like I would need to override Plot, which would likely make this the last question on this topic. That question is, can you use the DrawLine method in Plot, or, do you need to use the lower-level graphics object? I ask because I didn't see any examples of it in indicators such as ZigZag, where plot is overriden. If you can't use DrawLine, do you happen to have any clear examples of how to draw lines using various patterns and colors? I can tease out how to do that, but if you have any basic, spelled out examples (e.g. this is what a Pen is and why you need it, etc.), that would be great. Thanks.

                      Comment


                        #12
                        Hello grose,

                        The easiest way to get started with the plot override is to take a look at the CustomPlotSample indicator that comes with the platform. That shows the basics of using that for drawing, coordinates and Pens.

                        If you were to modify your existing script you can likely continue using DrawLine from where you have it now and just set its colors to transparent. You could add the Plot override and then the values from the anchors or other data you used for that line could be referenced from the plot override to draw it.



                        I look forward to being of further assistance.

                        JesseNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by AaronKoRn, Today, 09:49 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post AaronKoRn  
                        Started by carnitron, Today, 08:42 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post carnitron  
                        Started by strategist007, Today, 07:51 PM
                        0 responses
                        9 views
                        0 likes
                        Last Post strategist007  
                        Started by StockTrader88, 03-06-2021, 08:58 AM
                        44 responses
                        3,975 views
                        3 likes
                        Last Post jhudas88  
                        Started by rbeckmann05, Today, 06:48 PM
                        0 responses
                        9 views
                        0 likes
                        Last Post rbeckmann05  
                        Working...
                        X