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

how to update/recalculate/display plots without OnBarUpdate()

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

    how to update/recalculate/display plots without OnBarUpdate()

    I'm writing an indicator and have a Series<double> that is plotted on a chart.
    I'm using either a left mouse click or hot keys to change the starting bar for the calculations of the Series<double>.
    This is working fine except that I'm using OnBarUpdate() for calculating the Series<double> which I think is normal procedure but a problem occurs when the market is closed and OnBarUpdate() isn't called. So, when the market is closed the plot doesn't get updated.
    I've tried ForceRefresh() but it doesn't trigger the OnBarUpdate().
    I'm using OnRender() to process the mouse clicks and I've tried to recalculate the Series<double> and update the display there without success.

    Do you have a way to force an OnBarUpdate() event or a different approach to updating my indicator plot so that calculations and display happen immediately instead of waiting for an OnBarUpdate()

    #2
    Hello dtl-saw,

    Thank you for the post.

    If the market is closed OnBarUpdate will no longer be called as there are no more bars to process. What is the need to do the calculation at this time? Is this to update the final plot value?

    There won't be a lot of options here if the logic needs to remain in OnBarUpdate, you may be able to recalculate the value in the button press event depending on what the calculation is. Button events have a different context so instead of using BarsAgo you would use the GetValueAt or would need to wrap the code in a TriggerCustomEvent.

    One other idea is to add and remove a drawing object, if the problem is that there is not any data to drive rendering that may be a solution. Removing an object will force a redraw.

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

    Comment


      #3
      Hello.
      I'm using ChartControl.MouseDownPoint to draw a Line on the chart.
      But only because I need a Price Marker to be drawn as well, I have to set it's value in OnBarUpdate method.
      So, my line and marker work correctly but with big delay. It depends on bar's updates.
      I'll attach this code. Could you please help me to improve it.
      I want it to change position immediately after mouse clicks.
      Thank you.

      MarkerByClick.zip


      Click image for larger version  Name:	MarkerByClick.png Views:	0 Size:	25.0 KB ID:	1131224

      Comment


        #4
        Hello rare312,

        ChartControl.MouseDownPoint is generally used with OnRender to do actions. You could use OnRender to draw the line which would be updated more frequently. There is a sample showing a print in the following page: https://ninjatrader.com/support/help...MouseDownPoint

        One way would be to always draw the line and reference the ChartControl.MouseDownPoint from OnRender. If that changes the line would be updated. You could also make logic surrounding whatever you have now that incorporates OnRender. Drawing from OnRender would be the solution to have it update faster or with the mouse event.

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

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello rare312,

          ChartControl.MouseDownPoint is generally used with OnRender to do actions. You could use OnRender to draw the line which would be updated more frequently. There is a sample showing a print in the following page: https://ninjatrader.com/support/help...MouseDownPoint

          One way would be to always draw the line and reference the ChartControl.MouseDownPoint from OnRender. If that changes the line would be updated. You could also make logic surrounding whatever you have now that incorporates OnRender. Drawing from OnRender would be the solution to have it update faster or with the mouse event.

          I look forward to being of further assistance.
          I know What are you talking about. It was previous step. Now I want the Price Marker to be drawn as well. Only that's why I had to use Plots and OnBarUpDate method. I thought I was clear enough in my previous post.
          So the question is how to add the price marker and to make possible the line and marker change their position at the same time and immediately after mouse click.
          Last edited by rare312; 12-08-2020, 04:58 PM.

          Comment


            #6
            Hello rare312,

            For the plot to be updated more quickly you would need to use OnEachTick processing, that would allow you to reset the plot to the new value more quickly from OnBarUpdate.

            I look forward to being of further assistance.

            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello rare312,

              For the plot to be updated more quickly you would need to use OnEachTick processing, that would allow you to reset the plot to the new value more quickly from OnBarUpdate.

              I look forward to being of further assistance.
              I did. Still not fast enough.
              More faster was to use OnMarketDepth rather than OnBarUpdate.
              I think I'm done with using Plots.
              Could you please help me to add a Paint Event Handler.
              I still can not add it to existing Windows.Controls
              I want to use PaintEventArgs for drawings in UserControlCollection

              Comment


                #8
                Hello rare312,

                The other way to draw would be to use DirectX which is the OnRender override. The UserControlCollection can be used to add WPF controls but that would not be a good rendering outlet over the existing chart, you could use the Chart to render.

                You can find a sample indicator that comes with NinjaTrader called SampleCustomRender that showcases a lot of rendering concepts.

                https://ninjatrader.com/support/help...htsub=onrender


                Please let me know if I may be of additional assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  It will be impossible to draw directly on the price panel in that case. Like default Price marker does.
                  Is it correct?

                  Comment


                    #10
                    Hello rare312,

                    Correct the only way to get a PriceMarker in the price scale is to use a plot. You can otherwise draw anywhere in price panel using OnRender.

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

                    Comment


                      #11
                      What I know for sure, that's not the only way.
                      They did use PaintEventArgs in NT7 for creating custom pricemarker.
                      This Custom Crosshair will allow you show the horizontal and/or vertical lines. You also have the option to change the colors of the lines and markers. Critical &#8211; Specifically for some indicators, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press &apos;No&apos; Update [&#8230;]

                      I'll try to do the same for NT8.

                      Comment


                        #12
                        Originally posted by NinjaTrader_Jesse View Post
                        Hello rare312,

                        Correct the only way to get a PriceMarker in the price scale is to use a plot. You can otherwise draw anywhere in price panel using OnRender.

                        I look forward to being of further assistance.

                        Hello Jesse.
                        As I mentioned before, we still have some ways.
                        One of them I want to share with the community. I found many questions for custom price marker with no solution examples.
                        I did use wpf control - label. added to UserControlCollection.
                        Double click creates a line with price marker.
                        F5 - removes it.
                        fill free to improve it for your needs.And share it here..)

                        MarkerByClick2.zip


                        Click image for larger version  Name:	MarkerByClick.png Views:	0 Size:	30.4 KB ID:	1132035
                        Last edited by NinjaTrader_ChelseaB; 11-09-2022, 04:09 PM.

                        Comment


                          #13
                          Hi guys.
                          My previous post is good for other development things. But it's not right way for such simple task as PriceMarker.
                          We can use OnRender method for this kind of drawing.
                          This tool will perfectly show you how to do it
                          https://ninjatraderecosystem.com/use...-drawing-tool/
                          Last edited by rare312; 12-20-2020, 11:46 AM.

                          Comment


                            #14
                            Originally posted by rare312 View Post
                            Hi guys.
                            My previous post is good for other development things. But it's not right way for such simple task as PriceMarker.
                            We can use OnRender method for this kind of drawing.
                            This tool will perfectly show you how to do it
                            https://ninjatraderecosystem.com/use...-drawing-tool/
                            Hello rare312, I would be interested if you have found a solution to draw a price marker in OnRender? If so, would you tell me your solution ?
                            sidlercom80
                            NinjaTrader Ecosystem Vendor - Sidi Trading

                            Comment


                              #15
                              Originally posted by sidlercom80 View Post

                              Hello rare312, I would be interested if you have found a solution to draw a price marker in OnRender? If so, would you tell me your solution ?
                              hello. Did you check those [Vertical Line All Panels Drawing Tool] I've linked to? You will find the code how to do it.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by XXtrader, Yesterday, 11:30 PM
                              2 responses
                              11 views
                              0 likes
                              Last Post XXtrader  
                              Started by Waxavi, Today, 02:10 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by TradeForge, Today, 02:09 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post TradeForge  
                              Started by Waxavi, Today, 02:00 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by elirion, Today, 01:36 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Working...
                              X