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

ChartPanel and OnCalculateMinMax not scaling small

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

    ChartPanel and OnCalculateMinMax not scaling small

    Having an issue with ChartPanel scale. It’s set to AutoScale and the default scaling works alright in most cases but I find that when the displayed data series min and max values become small the scale does not adjust to be small enough to show the detail.

    I’ve tried overriding OnCalculateMinMax with a standard algo to supply the MinValue and MaxValue properties with the lowest and highest values in my data series but the results are the same as the NT default implementation.

    This appears to be a bug to me. There’s some minimum scale that NT will not go below.
    Users can scale the panel through the UI, however.

    I attached a screenshot to show an example.
    Attached Files

    #2
    Hello Brillo,

    Thank you for the post.

    I am going to do some testing and will be back with a reply shortly.

    Looking forward to assisting further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello Brillo,

      Thank you for your patience.

      I ran a test where I multiplied the Close[0] by 0.001 to make it < 0.1 and added that value to a plot, then I overrode OnCalculateMinMax(). The plot in its own panel was scaling just fine. I have attached my test script to this post. Please test it and see if you have the same issue with my test script.

      Please let us know if we may be of any further assistance.
      Attached Files
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        Thanks Chris. I'm going to work on reducing the size and complexity of my indicator to a minimum and see if the problem continues. If it does I'll post it back here later.

        Comment


          #5
          Example NinjaScript

          Chris,

          I leaned out the indicator that I have problem with and it still has the scaling problem. See attached ATS.Pairs.lean.cs.

          Add this to a ES 03-17 1440 min ETH and put on Market Replay 1/26/2017. Around 8:54:57 AM the plot looks wrong. Many other times does it as well, this is just one example. Also if you scroll left/right and use the reset scroll button it will trigger it to happen or trigger it to look correct.

          The problem happens on both of my computers. Let me know if it happens on yours.
          Thanks.
          Attached Files

          Comment


            #6
            Hello Brillo,

            Thank you for your patience on this.

            I looked at the input of your code and while the indicator is applied to the ES, it produces a value around 0.003. So I overrode the OnCalculateMinMax() the trivial way and set the max to 0.004 and min to 0.003. The indicator was scaled to those values exactly. Could you please share your attempt at overriding the OnCalculateMinMax() function?

            I look forward to your reply.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi Chris,
              Thank you for looking.
              My version OnCalculateMinMax is below. It did not help to fix the problem but it does help you use it and then look in the output window. I put a Print statement in there to verify that there are no data points that come in that could explain why the scale is being scaled much larger than the highest value in the data set ( which is the root of the problem ).

              Code:
                    public override void OnCalculateMinMax()
                    {
                       base.OnCalculateMinMax();
              
                       // exit if ChartBars has not yet been initialized
                       if (ChartBars == null)
                          return;
              
                       // int barLowPrice and barHighPrice to min and max double vals
                       double barLowPrice = double.MaxValue;
                       double barHighPrice = double.MinValue;
              
                       // loop through the bars visable on the chart
                       for (int index = ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)
                       {
                          double barClosePrice;
                          if (bPairDiff)
                             barClosePrice = dsPairDiff.GetValueAt(index);
                          else
                             barClosePrice = NaturalLogReturns.GetValueAt(index);
              
                          // get min/max of bar high/low values
                          barLowPrice = Math.Min(barLowPrice, barClosePrice);// Low.GetValueAt(index));
                          barHighPrice = Math.Max(barHighPrice, barClosePrice);// High.GetValueAt(index));
                          Print(Time.GetValueAt(index) + " bar: " + CurrentBar + " barHighPrice: " + barHighPrice);
                       }
              
                       // calc min and max chart prices
                       MinValue = barLowPrice;// - (ticksNeeded * TickSize);
                       MaxValue = barHighPrice;// + (ticksNeeded * TickSize);
                    }

              Comment


                #8
                Hello Brillo,

                Thank you for that snippet.

                I added the code you provided to the indicator and it is scaling properly.

                Are you only getting this in Market Replay or does it occur in real time as well?

                I have included your script with the code that you posted earlier, please test this out on a live connection or on the Playback connection.

                I look forward to hearing of your results.
                Attached Files
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chris,
                  I'm assuming you have reproduced the problem with my original code and instructions. Is that correct?

                  For me, the OnCalculateMinMax implementation I sent you has no effect on the results and I'm not surprised by that. It looks to me that it's doing the same thing that a sensible default implementation would do: find the highest and lowest values in the data series to be plotted and set the scale to those values. Probably the NinjaTrader core implements it this way, no?

                  I had thought maybe I have data that's not showing on the plot that's got a higher value which would explain the scale. But I verified that this is not the case with the Print statements in the OnCalculateMinMax. EDIT and so it's a mystery as to why the scale would be so much higher than the highest value printed in the log.

                  The problem happens once in a while and I have not seen it happen on live data because I'm not running it there. This is an experimental indicator and I don't want to have a problem with my live trading due to a possible crash. Consequently I'm only running it on a Market Replay connection where it happens very frequently.

                  Comment


                    #10
                    Hello Brillo,

                    Thank you for the reply.

                    I was not able to reproduce the error you are having. This is either due to market replay, or an anomaly in the calculation. Please let me know if this happens on your live data feed.

                    Also, as a test, instead of printing every output value, print the value if it is greater than 0.1, which is the value that is messing up the scaling.

                    If there is anything else I may assist with please let me know.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      It's happening right now on a live connection.

                      However the problem remains intermittent. I saved the workspace and when I restored it, at first it was plotting fine. I configured a 2nd chart the same way. The 2nd chart started out plotting fine but when I looked over at the 1st one, the one that was restored, it again is plotting incorrectly. I attached a screen shot of this. The one on the left is incorrect.

                      I attached a workspace that configures a single chart of ES 12-17 1440 min bars ETH 180 days. I changed the suffix name on the workspace to .txt so that I could upload it to the forum. Delete that suffix so it ends in .xml.

                      I also attached screen shots of the configuration in case you can't get the workspace to work. You may have to configure a 2nd chart yourself to make it happen.
                      Attached Files

                      Comment


                        #12
                        Hello Brillo,

                        Thanks for the information.

                        I will continue to look into this and follow up tomorrow.

                        Thank you for your patience no this.
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Brillo,

                          Thank you for your patience.

                          There is undeniably some kind of data that is output while the indicator is applied to a large timeframe. If you look at your chart screenshot, the chart on the left has plotted a value that is indeed skewing the data that normally comes in. Please try to identify this anomaly and the indicator should scale properly.

                          If questions come up or if we may be of any further assistance, please let us know.
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Chris,
                            The charts in the last post I sent both have two instances of the indicator loaded. One is plotting the current value on the right axis and the other on the left axis. For the chart on the left and the instance plotting on the left axis I see no high value to explain why the scale on the left would be what it is. It so happens that the scale looks like it's fitting the plot history from the other indicator, the one that plots it's current value on the right axis, but that is just a coincidence.

                            I sent another screen shot earlier in this thread that shows a single instance plotting on the right hand side. That example was taken using market replay. You wanted to see it happening on live data and I provided that in the more recent example but I chose to load multiple indicators in order to help get the plotting problem to expose itself more quickly.

                            Comment


                              #15
                              Hello Brillo,

                              Thank you for your patience.

                              We are testing further on our end and will update this thread when we have any additional information.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Gerik, Today, 09:40 AM
                              2 responses
                              7 views
                              0 likes
                              Last Post Gerik
                              by Gerik
                               
                              Started by RookieTrader, Today, 09:37 AM
                              2 responses
                              11 views
                              0 likes
                              Last Post RookieTrader  
                              Started by alifarahani, Today, 09:40 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by KennyK, 05-29-2017, 02:02 AM
                              3 responses
                              1,285 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              11 responses
                              186 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X