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

GetMinMaxValues​​

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

    GetMinMaxValues​​

    What is the purpose of GetMinMaxValues method​​?
    There are a lot of indicators that use this method but i do not understand what their role.
    As far i can see the parameters: (max, min) their values ​​are infinite, unlike the method "Plot" to get the visible price range on screen.

    On the other hand also gets the object "chartcontrol" But this object is accessible to anywhere using ChartControl directly.
    Can anyone explain what advantages you have or when to use GetMinMaxValues​​?
    Code:
    public override void GetMinMaxValues(ChartControl chartControl, ref double min, ref double max)
            {
                sMinGMMV=min.String;
                sMaxGMMV=max.String;
            }
    public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
            {
               sMinPlot = min.String;
               sMaxPlot= max.Plot;
            }
    When you draw those strings..:

    thanks
    Attached Files

    #2
    Hi Ramon, you could use this method to override the per default set min max value range of the scale method NT uses - however using it would not be supported nor documented by us unfortunately but for illustration sakes I've attached a simple script you could experiment on your end with.
    Attached Files
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Indeed, it works.
      The maximum and minimum values ​​differ with respect to those obtained in "Plot" method , I guess it has to do with rounding and conversions of pixels at prices

      The difference between getting good and bad values lies in the fact of defining and using a "plot" . SMA.in your case.

      Must I use a Plot to get good (max/min) values ?.
      Attached Files

      Comment


        #4
        Using base.GetMinMaxValues

        I'm writing an indicator and need to get the values of the min and max prices painted.

        Essentially I have established a list of support and resistance levels and during OnBarUpdate() I want to check whether each S or R level is currently on screen at this instant and if so, to draw a horizontal line to display it.

        Just checking around on the net to find the best method to obtain min and max prices, I discovered base.GetMinMaxValues() but also discovered it's not supported.

        I'm trying to use it like this:

        Code:
                protected override void Initialize()
                {
                    Add(PeriodType.Minute, 60);
                    Overlay = true;
                }
        
                protected override void OnBarUpdate()
                {
                    // Checks to ensure Bars objects contain enough bars before beginning
                    if (CurrentBars[0] <= BarsRequired 
                        || CurrentBars[1] <= 3)
                        return;
                    if (BarsInProgress == 1) // 60mins
                    {
                        if (Low[2] < Low[0] && Low[2] < Low[1]
                            && Low[2] < Low[3] && Low[3] < Low[4])
                        {
                            support.Add(Time[2]);
                        }
                        return;
                    }
                    double min = 0.0;
                    double max = 0.0;
                    try
                    {
                        base.GetMinMaxValues(this.ChartControl, ref min, ref max);
                    }
                    catch (Exception exception) 
                    { 
                        if (!done) Alert("1", Priority.High, exception.Message,
                            "Alert1.wav", 10, Color.Black, Color.Yellow);
                        done = true;
                    }
                    foreach (DateTime when in support)
                    {
                        int bar60mX = BarsArray[1].GetBar(when);
                        int lowBarsAgo = CurrentBars[1] - bar60mX;
                        double swingLow = Lows[1][lowBarsAgo];
                        if (swingLow < max && swingLow > min)
                        {
                            int barPrimaryX = BarsArray[0].GetBar(when);
                            lowBarsAgo = CurrentBars[0] - barPrimaryX;
                            DrawLine("S" + bar60mX, lowBarsAgo, swingLow, 0, swingLow, Color.DarkBlue);
                        }
                    }
                }
        However this is crashing NT7. It just dies, no exception,nothing in the logs. Just gone.

        Can anyone see what I'm doing wrong?

        Thanks

        Comment


          #5
          Just override Plot().

          Store the min and max provided within Plot() in some variables and then reference the stored values from OnBarUpdate or where ever you want.

          Comment


            #6
            Originally posted by BigWaveDave View Post
            Just override Plot().

            Store the min and max provided within Plot() in some variables and then reference the stored values from OnBarUpdate or where ever you want.
            adamus :: "I'm writing an indicator and need to get the values of the min and max prices painted."



            Wouldn't high[0] and low[0] work? or am I missing something?

            Comment


              #7
              Now that is a solution and a half. Thanks.

              Just to verify this is all it takes:

              Code:
              double currentMin;
              double currentMax;
              
                  public override void Plot(Graphics graphics, Rectangle bounds, 
                          double min, double max)
                      {
                          base.Plot(graphics, bounds, min, max);
                          currentMin = min;
                          currentMax = max;
                      }
              Last edited by adamus; 02-14-2013, 05:32 AM.

              Comment


                #8
                Looks right.

                Just to clarify... you are looking for the upper and lower bounds of the chart in terms of price, correct? In other words, the extremes of the price scale (y-axis). In order to determine if you want to paint something or not, I assume.

                Not just the high and low price of the currently displayed bars on the chart....
                Last edited by BigWaveDave; 02-14-2013, 06:51 AM.

                Comment


                  #9
                  Originally posted by BigWaveDave View Post
                  Looks right.

                  Just to clarify... you are looking for the upper and lower bounds of the chart in terms of price, correct? In other words, the extremes of the price scale (y-axis). In order to determine if you want to paint something or not, I assume.

                  Not just the high and low price of the currently displayed bars on the chart....
                  You're probably right as to adamus's intentions.

                  Comment


                    #10
                    Hi Dave,
                    your assumption is correct - I just ignored Sledge's post because I couldn't make immediate sense of his question or better said, what he was thinking when he asked it.

                    I need the high and low of the bars currently on the chart.

                    It's tough that there's no documentation on the Plot() method and how to craft the overriding method you/I want - all the examples I have looked at want to do something else so I was confused by it and was slowly experimenting to see what happens when I do different things in Plot().

                    The first thing I wasn't sure about was how often it is called. Do you know?

                    I assume it is called every time there is a new tick when live, and also every time I change the axes manually - either scrolling backwards and forwards or shrinking / expanding the range displayed, on both x and y axes.

                    I also assume but I haven't got to the point where it would make any difference, I assume when using CalculateOnBarClose=false, that the OnBarUpdate() event would fire on a new tick before the Plot() event. Is that what you assumed?

                    Comment


                      #11
                      It still sounds like there is confusion.

                      The Min, Max provided in the Plot() override have nothing to do with any price data in the chart. They describe the 'physical' upper and lower bounds of the chart in price. In other words, they describe the extent of the y-axis in price.

                      Plot is updated when the y-axis is scaled or transformed. The min and max values can be used to determine the vertical pixel offset within the chartpanel of a specific price because we not only know the price extent of the y-axis but we also know the bounds (in pixels) of the chartpanel.

                      Min and Max are valid even if there isn't a dataseries in the chart.'


                      There may be an easy way to the high and low of the visible bars. I dunno. My first though would be to determine what the first and last bar visible on the chart are, then iterate through the dataseries tracking the highest high and lowest low as you go. It should be an easy routine to write. You would want to process the routine on each OnBarUpdate().
                      Last edited by BigWaveDave; 02-14-2013, 07:53 AM.

                      Comment


                        #12
                        Alright, I'm with you. I was thinking what you said but I wasn't differentiating it from what I said but of course it's the top and bottom of the y axis, not the max high and min low of the data series, especially considering that I might have a fixed scale on the chart as opposed to the auto-scale.

                        It was just a lazy assumption I had made based on auto-scaling that there was a direct relationship between the y-axis and the max high and min low.

                        Thanks for pointing it out. I wouldn't need to know what the actual price max and min were.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Christopher_R, Today, 12:29 AM
                        0 responses
                        9 views
                        0 likes
                        Last Post Christopher_R  
                        Started by sidlercom80, 10-28-2023, 08:49 AM
                        166 responses
                        2,235 views
                        0 likes
                        Last Post sidlercom80  
                        Started by thread, Yesterday, 11:58 PM
                        0 responses
                        3 views
                        0 likes
                        Last Post thread
                        by thread
                         
                        Started by jclose, Yesterday, 09:37 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post jclose
                        by jclose
                         
                        Started by WeyldFalcon, 08-07-2020, 06:13 AM
                        10 responses
                        1,415 views
                        0 likes
                        Last Post Traderontheroad  
                        Working...
                        X