Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing price data in DrawingTools...

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

    Accessing price data in DrawingTools...

    I'm trying this example from the docs:

    Code:
    public override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    			// add your custom rendering logic here
    			GannFan gf = Draw.GannFan(this, "tag1", 0, Low[0]);
    			PriceLevel pLevel = new PriceLevel(99, Brushes.Black);
    			gf.PriceLevels[3] = pLevel;
    			
    }
    Code:
    The name 'Low' does not exist in the current context	CS0103

    #2
    Hi funk101,

    The overloads for the GannFan are not correct.
    There is no overload with 4 parameters.
    Try using:
    GannFan gf = Draw.GannFan(this, "tag1", true, 0, Low[0]);

    Also, may I confirm that you are testing this code in NinjaTrader 8?

    Attached is a test script with this code compiled within.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      NT 8. I'm trying to create just a 45 degree line and I was basing it off of GannFan. So, it's a "DrawingTool" not an Indicator. I still get the same error because I believe it is a DrawingTool and NOT an Indicator and I don't think the price data is available to a drawing tool, right?

      Comment


        #4
        Hi funk101,

        So with one custom drawing tool you are attempting to draw another drawing tool? I'm not certain you will be able to do this. You would need to supply the owner and the drawing tool script would not work as this.

        That said, to find the low you can use:
        chartControl.BarsArray[0].Bars.GetLow(int index)

        For example:
        Print(chartControl.BarsArray[0].Bars.GetLow(0));

        This would print the low of the first bar.

        To convert this to a y value use:
        chartScale.GetYByValue(double price)

        For example:
        Print( chartScale.GetYByValue( chartControl.BarsArray[0].Bars.GetLow(0) ));
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          That said, to find the low you can use:
          chartControl.BarsArray[0].Bars.GetLow(int index)
          Thank you for this useful info on how to access the BarsArray when there are multiple DataSeries.

          I have a DrawingTool and I'm wanting to access the tick data of the chart. I imagine I need to do this by adding an additional DataSeries (to access tick data) to the chart.

          It seems AddDataSeries() is not possible within a DrawingTool like it is in an indicator (perhaps I'm wrong?).

          Is there a way to add a DataSeries to the chart via a DrawingTool? Perhaps I need a companion indicator that adds an additional DataSeries to the chart that the DrawingTool can access? Am I thinking about this wrong?

          Any help is greatly appreciated!

          Comment


            #6
            You cannot add a data series through a drawing tool

            I would advise not adding a data series from a drawing tool as it would really hamper your performance for the tool itself.

            If you really need to have that tick data for that tool, then you should A. build an accompanying indicator that will load it or B. ensure that the user has to add tick data for the tool to work properly.

            Comment


              #7
              Hi neoikon,

              Calonious is correct. The data series cannot be added directly to the drawing tool.

              From the drawing tool, you can loop through the ChartControl Bars array.

              ChartControl.BarsArray[index].Bars.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Right, adding the dataseries to the drawing tool, obviously, is a poor direction. Instead I'm wanting to add it to the chart itself, if it doesn't already exist.

                Otherwise, is there a way to determine if an indicator is loaded to the chart, and if not, add it from the drawing tool? That way this helper indicator can load this second dataseries for the drawing tool?

                I'm hoping to not rely on the user to manually add these things.

                Comment


                  #9
                  I still advise against this but if you really want to you can check the Indicators Collection from the ChartControl and if the indicator exists continue with the tool otherwise you can add it in

                  Code:
                  if(chartControl.Indicators.Any(i => i.GetType() == typeof(Indicators.SMA)))
                  
                  // Add it here....Note, still kinda buggy as it is not a full adding and needs some work but should get you started
                  Indicator indi = new Indicators.Indicator();
                  Indicators.SMA sma = indi.SMA(14);
                  chartControl.Indicators.Add(sma);

                  Comment


                    #10
                    Drawing Tools only have the capability of what exists on the chart. If your drawing tool has requirements for other objects, there is not a reliable way or convenient method for adding these dependencies. The best case scenario is to display an error if these dependencies do not exist and prompt the end user to add them.

                    I am curious though, what type of drawing tool are you making that has a requirement for another data series to be included? Do you mean sharing the specifications of your project so we can have a fuller picture of the project requirements which cannot currently be met for you?
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Originally posted by NinjaTrader_Matthew View Post
                      I am curious though, what type of drawing tool are you making that has a requirement for another data series to be included?
                      Thank you for the replies. If I want access to the actual trades from NinjaScript (the information you can find from Tools > Historical Data, then drilling down to the tick data), I was told the only way to view this is to add another tick data series.

                      If the user is looking at a 5-minute chart, for example, then you only have 4 data points (OHLC) for an entire 5 minutes of trading. That's an eternity of data that's boiled down to just those 4 data points (excluding volume, I suppose). Now, 15min? 30m? More? Again, a tremendous amount of information that's hidden (or summarized).

                      However that "Historical Data" dialog box is scanning the data and presenting it, is what I was hoping to see in NT8. There wasn't a good way in NT7 and I was hoping for a nice object to access in NT8.

                      Originally posted by NinjaTrader_Matthew View Post
                      The best case scenario is to display an error if these dependencies do not exist and prompt the end user to add them.
                      Right, in general, this that is how I do things, except clicking "yes" would do it automatically and clicking "no" would do nothing. If I simply show an error and rely on the user to do it themselves, then it means fielding more emails, creating instructional videos, etc.
                      Last edited by neoikon; 11-05-2015, 09:03 AM.

                      Comment


                        #12
                        I'm very sorry but I still do not quite understand the requirements.

                        There are other ways in NinjaTrader 8 to access to tick data, but it ultimately depends on what you need to do with the data. You could add an OnMarketData handler to access real-time ticks, or you could create a BarsRequest and request a specific interval and 'bar data' in the drawing tool that way.

                        To be clear so I can assist, why does your drawing tool need tick data against a 5, 15, 30, more minute chart? Please be very specific in your product requirements and what you plan on doing with this information and I'll be happy to see how we can meet your needs.

                        Are you sure your project needs to be a drawing tool, and cannot be made from an indicator? Does it need to be a manually drawn line? There are ways to render in an indicator and access moues click points too, so for example, if you're just drawing a 45 degree line based on where a user clicks, that could be handled in OnRender() of an indicator and also give you the additional bar data needed.

                        If this is a private project that you do not wish to share details publically, feel free to send me a private message and we can see what we can do for you in the NT8 framework.
                        MatthewNinjaTrader Product Management

                        Comment


                          #13
                          Sure, my drawing tool will highlight a certain group of bars, then perform analysis on just the market activity during those bars (manually drawn tool, not drawn by an indicator).

                          I'm not interested in the bar type they are using, just the group of bars specified by the tool (which gives me a start time and end time) and then look at all the tick/trades that happened during that time period (independent of the actual chart interval/type).

                          Typically, this will not include the current bar (current incoming ticks), so I don't think OnMarketData() makes sense here.

                          However, BarsRequest looks very interesting. If I can specify a start and end time range and then return the tick data of the current chart's symbol that I can loop through, that's perfect! We'll see how well it performs as the tool is resized and I'm making request after request.



                          Does that make more sense? Does BarsRequest look like what I want?
                          Last edited by neoikon; 11-05-2015, 01:05 PM.

                          Comment


                            #14
                            I see! That's an useful idea for sure! Thanks for clarifying.

                            I think the the BarsRequest should meet your needs - since you can loop through the request and do what you need. Although I cannot speak on performance as I've never fully tested a BarsRequest on a Drawing Tool - but this concept as an advantage as you mentioned you can specify the exact start and end period for the request - which would be way less resource intensive than requesting the charts entire look back period for a tick bar per AddDataSeries()

                            I would recommend looking at the SuperDOM Column "Volume" around line 323 is when the bars request is first setup. The logic under Cbi.ErrorCode.NoError would be the loop used to calculate that which should help you get you started with this new concept.
                            MatthewNinjaTrader Product Management

                            Comment


                              #15
                              I don't seem to get the expected data. Below is some example code, where I give it a BeginTime and EndTime, then print out the first 5 results:

                              PHP Code:
                              BarsRequest barsRequest = new BarsRequest(chartControl.Instrument, BeginTime, EndTime);
                              barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Tick, Value = 1 };
                              barsRequest.TradingHours = TradingHours.Get("Default 24 x 7");                
                              
                              barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((theBars, errorCode, errorMessage) =>
                              {
                                  Print("BEGIN: " + BeginTime + "   END: " + EndTime);
                              
                                  for (int x = 0; x < 5; x++)
                                  {
                                      Print("  " + theBars.Bars.GetTime(x) + "  " + theBars.Bars.GetClose(x) + "  " + theBars.Bars.GetVolume(x));
                                  }
                              })); 
                              
                              The result is this, where you can see that the resulting data is not within the BEGIN and END times. (Good news is I get data and it's from the correct instrument!)

                              BEGIN: 11/5/2015 9:47:22 AM END: 11/5/2015 9:52:42 AM
                              11/4/2015 11:00:18 PM 4712 1
                              11/4/2015 11:00:18 PM 4712 1
                              11/4/2015 11:00:19 PM 4711.75 1
                              11/4/2015 11:00:19 PM 4711.75 1
                              11/4/2015 11:00:19 PM 4711.75 1

                              Is there something I'm missing or forgetting to set during the request?

                              EDIT: It seems that the data is there, I just have to loop through all the requested data and manually filter what's between my date ranges. In other words, it seems the Request is giving me a couple day's worth of data and not just what I specified. Perhaps I need to request it differently? Perhaps the filter only looks at the dates and not the time?
                              Last edited by neoikon; 11-06-2015, 09:45 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              672 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X