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

Need to know when the last bar painted changes (i.e. when the chart is scrolled)

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

    Need to know when the last bar painted changes (i.e. when the chart is scrolled)

    Is there any way that my indicator can know when the last bar painted changes?

    If not, please add that to your Request For Enhancement list.

    Here's why I care.

    I am setting up a new indicator that will handle displaced moving averages. The crucial part is that most platforms leave blank bars for the amount of a negative displacement. My indicator is filling them in algorithmically. The net result is that the indicator value for a given day depends on how far back in the displacement it is. In other words, it is not constant until it is further back than the displacement. As is:
    • If you set the chart back a ways and give F5 all is current and correct
    • If you then scroll to the right, all gets updated properly. Fun to watch the last <displacement> days wave around as you scroll.
    • If you scroll back (to the left) though, NT just displays the previously calculated data -- which for my indicator is the wrong data.

    I know that this need is unusual, but please provide a way for my indicator to know when the last bar painted changes, so that it can keep the chart correct.

    (By "correct" I mean that the chart should look the same as it looked when the right-most bar was the last bar. A refresh should not change the chart appearance.)

    Thanks,
    EV

    #2
    Ev, there's unfortunately no supported method for this task - you can take a look at the VolumeZones and how they handle this using the ChartControls.

    Thanks for the suggestion.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Ev, there's unfortunately no supported method for this task - you can take a look at the VolumeZones and how they handle this using the ChartControls.

      Thanks for the suggestion.
      I figured there is no supported way. It is an unusual, but real, need.

      Thanks for the suggestion -- I shall look at it right away.

      --EV

      Comment


        #4
        Bertrand,

        Thanks for the reminder.

        It was a "Why didn't I think of that?" moment -- I forgot that Plot() is called when anything changes. That should be enough to get me going.

        Thanks again,
        EV

        Comment


          #5
          You're welcome - glad to hear you got it going...
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Well, I do have it going now. It was a bit tricky, and took me a bit over 4 hours to do.

            Works really nicely now and is not **too** unsupported. Just use of Plot(), LastBarIndexPainted, and calling OnBarUpdate myself ( followed by base.Plot() ).

            It would have been **so** much easier if I could have just gotten a call from NT, with CurrentBar set to the edge of the chart, when the chart was scrolled left !

            I think that you will agree there is no supported way to do this task. Most indicators do not care, but for those that do it would be quite useful. My suggestion, which should be pretty easy to implement, is:
            • A method or property to tell NT that the service is wanted

            • If the service is wanted, then when the last bar on the right of the chart is changed for any reason, call OnBarUpdate() with CurrentBar set to the rightmost bar on the chart.

            Thanks for reminding me that Plot() is called at pretty much any excuse, and could be used for this purpose. I had to be bit thoughtful about filtering for only the times that calling OnBarUpdate() was needed, but that was not too bad.

            --EV

            Comment


              #7
              >> and calling OnBarUpdate myself
              A word of warning: This is not supported (true for any attempt to explicitly call any NS method) and may lead to unexpected results.

              Thanks

              Comment


                #8
                Originally posted by NinjaTrader_Dierk View Post
                >> and calling OnBarUpdate myself
                A word of warning: This is not supported (true for any attempt to explicitly call any NS method) and may lead to unexpected results.

                Thanks
                Dierk,

                I know that it is unsupported, and I even said so in my message, gently poking fun at myself about that. I do not use unsupported methods lightly. I only do so when I know of no supported way to get the job done. In fact, that was the original question in this thread -- looking for a supported way to handle it.

                Honestly, it was a lot more work than it needed to be if NT supported something like my request -- letting me know when the chart scrolls left (backwards) so I can update the values. I'll change the code to a more supported way once I am aware of one.

                If you have a safer way to get the job done, please let me know.

                --EV

                Comment


                  #9
                  Unfortuantely I would not have any info for you, since this is beyond the area where we provide support for. Thanks

                  Comment


                    #10
                    Originally posted by NinjaTrader_Dierk View Post
                    Unfortuantely I would not have any info for you, since this is beyond the area where we provide support for. Thanks
                    Understood. There is no supported way to d the job, and you folks very reasonably (and by definition) are not in the business of providing support for unsupported things.

                    --EV

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by wzgy0920, 04-20-2024, 06:09 PM
                    2 responses
                    26 views
                    0 likes
                    Last Post wzgy0920  
                    Started by wzgy0920, 02-22-2024, 01:11 AM
                    5 responses
                    32 views
                    0 likes
                    Last Post wzgy0920  
                    Started by wzgy0920, Yesterday, 09:53 PM
                    2 responses
                    49 views
                    0 likes
                    Last Post wzgy0920  
                    Started by Kensonprib, 04-28-2021, 10:11 AM
                    5 responses
                    191 views
                    0 likes
                    Last Post Hasadafa  
                    Started by GussJ, 03-04-2020, 03:11 PM
                    11 responses
                    3,231 views
                    0 likes
                    Last Post xiinteractive  
                    Working...
                    X