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

Data box data script

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

    Data box data script

    Hello

    Is it possible to use the number of bars ago in data box.
    Lets say i have 200 bars ago and i would like to divide that number by 2 and see the result in the data box.
    Is it possible?

    Thank you

    #2
    Hello frankduc,

    Thank you for your post.

    I wanted to get a better idea of the overall result you are asking to see here. Are you trying to make an indicator which plots the bars ago based on some fixed value, or are you referring to the charts bars to load? What is the 200 bars ago based from, would this be the mouse's position or a fixed point on the chart?

    Can you provide more detail on the specifics of what you need here?

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

    Comment


      #3
      Yes the mouse position using the cross hair tool. As you can see on the image there is 812 bars ago. I want to be able to divide or multiply by any numbers and get the result just under 812 bars in the data box. Than i want the result to appear in the chart in a form of a vertical line. Say the answer is 900 bars ago. 900 will appear under 812 and a vertical line will appear in the chart at the bar 900.
      ty
      Attached Files

      Comment


        #4
        Hello frankduc,

        Thank you for your reply.

        I reviewed this case further but at the moment I can't see a good way to relay this information to the data box specifically. This would be possible to just render the number directly to the chart, for example clicking a bar you could render text on the chart for the /2 bars ago value. It would be much more difficult / not possible to update a plot value for this bar being clicked to relay the information to the data box specifically.

        Would your plan be able to accommodate clicking the chart instead of using the databox specifically?

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

        Comment


          #5
          Why not! But i still dont know how i could render the result into the chart. I suppose you need to use count https://ninjatrader.com/support/help...bars_count.htm , than add the division /2 and input somewhere the result into the chart. Is anyone has tried to use math /,*,+,- using the bars ? any exemple i could copy and modified?
          ty

          Comment


            #6
            Hello frankduc,

            In that case, you can use OnRender for collecting this data and also displaying it. You could use the attached sample as a reference for one way to access/calculate this information.
            Plotting this would be difficult as you are dealing with an interactive element, the mouse, which is not tied to how plots are set however OnRender can fairly easily output this kind of input value.

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

            Comment


              #7
              You put me exactly on the path to make my indicator. TY
              I got it now i can enter and modify formulas in the code you sent me.
              I got another favor. Is there a way i can create a marker.
              Lets say half return 200 from 400 bars.
              I want at the bar 200 some marker like a vertical line or anything else that is showing me where is exactly bar 200. I have more than one formulas i entered and it makes a lot of bars to track with the data box barsago visually.
              Thank you
              Last edited by frankduc; 02-25-2019, 01:44 PM.

              Comment


                #8
                Hello frankduc,

                I think in this case you just missed the () at the end of ToString:
                • (bar / 2.62).ToString
                it may be easier to use String.Format for this so you don't need the plus signs as well, the previous string was just a simple example I often find string.format to be cleaner however this depends on your personal preference.

                Heres another sample using string.format:

                Code:
                string textString = string.Format("BarsAgo: {0}\n Half: {1}\n Even More: {2}", bar.ToString(),(bar / 2.0).ToString(), (bar / 2.5).ToString());
                String format works by replacing predefined parts of the string with your variable, or {0} gets replaced with bar.ToString() {1} with (bar / 2.0).ToString(), and so on.

                Converts the value of objects to strings based on the formats specified and inserts them into another string. If you are new to the String.Format method, see Get started with the String.Format method for a quick overview.


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

                Comment


                  #9
                  i see ….interesting.
                  Can you answer my previous question about
                  I got another favor. Is there a way i can create a marker.
                  Lets say half return 200 from 400 bars.
                  I want at the bar 200 some marker like a vertical line or anything else that is showing me where is exactly bar 200. I have more than one formulas i entered and it makes a lot of bars to track with the data box barsago visually.
                  Thank you
                  (you were right i forgot the ()) when i deleted that post you already answered it.

                  Comment


                    #10
                    Hello frankduc,

                    Yes with that example that demonstrates the ways to access data based off of the mouse position so you could really craft that into whatever you wanted from that point. I would suggest taking a look into the SampleCustomRender indicator for some examples of how to render various items with SharpDX. As far as the half way question you had, it sounds like you are asking how to show halfway between 400 is that right? If so, you could solve this with some basic math and the values currently established.

                    Right now you can get the index of the clicked bar minus the count giving you a difference in BarsAgo:
                    Code:
                    int bar = Math.Abs(ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex);
                    To find the halfway point between the found BarsAgo and CurrentBar, you could add the difference previously calculated and divide that by two, this gives half the BarsAgo. You can then take the Half number of BarsAgo and subtract from the ToIndex to get the actual bar index. Using the bars index you can get the X which is used to render with the RenderTarget. Here is a simple example of half the other X value:

                    Code:
                    int cursorPointX2  = ChartControl.GetXByBarIndex(ChartBars, Math.Abs(ChartBars.ToIndex - (bar /2)));

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

                    Comment


                      #11
                      By using SharpDX and take
                      SampleCustomRender indicator as an example i can reproduce whats in the png attach file? In my chart exemple 2.62 = 226.56 and a blue line is shown at bar 226.
                      Honestly i dont really understand what is the purpose of the SampleCustomRender indicator and what can i pick in the code of the indicator to produce my vertical line.
                      I have to admit my coding skills are very basic.
                      Im not sure how this is helping me
                      int bar = Math.Abs(ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex);

                      Also i am wondering if its possible to use the volume in the bar to calculate so the indicator works also with a minute chart instead of a volume chart.
                      Value[0] = Volume[0] + (CurrentBar > 0 ? Value[1] : 0) - (CurrentBar >= Period ? Volume[Period] : 0); maybe?

                      thank you
                      Attached Files
                      Last edited by frankduc; 02-26-2019, 08:07 AM.

                      Comment


                        #12
                        Hello frankduc ,

                        Thank you for your reply.

                        By using SharpDX and take
                        SampleCustomRender indicator as an example i can reproduce whats in the png attach file ?

                        Honestly i don't really understand what is the purpose of the SampleCustomRender indicator and what can i pick in the code of the indicator to produce my vertical line.
                        What I had intended was for you to use the SampleCustomRender to review the various rendering concepts like drawing a line with OnRender. If you take a look at line 160 in the file, it shows how to draw a line. This is different than a drawing tool because you would use X and Y points to draw instead of BarsAgo and PRices directly. This is why the other methods to convert the mouse point to bars and prices is required to output the text in BarsAgo, however, the X and Y values used to calculate that text could be used directly to position a line in the chart panel.


                        Code:
                         In my chart example 2.62 = 226.56 and a blue line is shown at bar 226.
                        What was your question surrounding this statement? Are you asking how 226 was reached from 226.56?


                        Im not sure how this is helping me
                        int bar = Math.Abs(ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex);
                        This is what is required to calculate the BarsAgo. This takes the cursors X value and gets the bars Index then subtracts that from the bars count. This gives a difference in BarsAgo.


                        Also i am wondering if its possible to use the volume in the bar to calculate so the indicator works also with a minute chart instead of a volume chart. Value[0] = Volume[0] + (CurrentBar > 0 ? Value[1] : 0) - (CurrentBar >= Period ? Volume[Period] : 0); maybe?
                        You could access any of the series as you need based on the bars index or BarsAgo using the existing logic that has been shown. The GetValueAt method can be used with the index, or you could use Volume[BarsAgo] to access volume for a number of bars ago. If you wanted to incorporate this into the previous OnRender syntax you would need to use GetValueAt or


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

                        Comment


                          #13
                          In int bar = Math.Abs(ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex); why cant we just modify bar to define it as volume? I dont get it this language is terribly complicated. I tried bar.
                          Volume[BarsAgo] it wont work. I tried many things. I get that bar is define by numbers of bars from the cursor to the end of the right chart. You simply should be able to select under bar if you want it to be volume, low, high, etc. Stupid language!

                          For the chart exemple 2.62 = bar 226 i want the vertical blue line to appear automatically at bar 226 or the value it return everytime i click on the chart.
                          this is line 160
                          RenderTarget.DrawLine(startPoint, endPoint, areaBrushDx, 4); if it was just to replace Drawline by Verticalline and replace in () value at " \n 2.62: " it would be so simple but no im sure it must be another of those c# puzzle.
                          Thank you
                          Last edited by frankduc; 02-27-2019, 09:33 AM.

                          Comment


                            #14
                            Hello frankduc ,

                            Thank you for your reply.

                            In this situation what you are asking is not a simple concept like the drawing objects, the internals of the chart do similar tasks when using the databox to locate information. For your task, this has not been done by an internal method that is exposed for NinjaScript so you would need to use higher level NinjaScript and math to accomplish the goal.

                            In int bar = Math.Abs(ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex); why cant we just modify bar to define it as volume? I dont get it this language is terribly complicated. I tried bar.
                            I am not certain what you are asking here, could you further explain this question? Are you trying to get the volume from a certain bar?
                            The sample I provided addresses getting X/Y values for the cursor and picking bars based on X/Y values. This is then used to calculate the result in a BarsAgo value. You already have the index of the picked bar so you could use the GetValueAt function of any series like Volume to retrieve volume for a specific bar if that is what you are asking.


                            For the chart exemple 2.62 = bar 226 i want the vertical blue line to appear automatically at bar 226 or the value it return everytime i click on the chart.
                            this is line 160
                            RenderTarget.DrawLine(startPoint, endPoint, areaBrushDx, 4); if it was just to replace Drawline by Verticalline and replace in () value at " \n 2.62: " it would be so simple but no im sure it must be another of those c# puzzle.
                            I am also not certain on this comment, are you asking how to do this or you are seeing a problem with something you are currently doing? For the other line values you want, you would need to use similar logic to calculate those values, unfortunately, it is not as simple as just filling in the 2.26 as demonstrated with the code to find the clicked bar.


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

                            Comment


                              #15
                              int bar = Math.Abs(ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex)
                              I use a volume chart 400 period. The calculation is automatic and formulas return the answer as a Bar.
                              On minute chart Bar wont return in volume, it return in numbers of bars. I want it to return in volume on a minute chart. IB dont backfill overnight data. So i get tick data only when i start NT in the morning. I need a way so in a minute chart the answer return is in volume not in number of bars. In my chart exemple 2.62 = 226 bars but in a minute chart 226 dont equal the same in volume.
                              What do i need to change to make it return in volume.

                              The problem is i dont understand how to introduce
                              GetValueAt .
                              I cannot give a new identity to bar ill get an error message.
                              according to help guide that would be something like:
                              For (
                              int bar = Math.Abs(ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex)
                              )

                              double value =
                              (volume.GetValueAt)); ???


                              That is what i am asking. What is the method to use to link the return of my formulas and the creation of the line.
                              In
                              RenderTarget.DrawLine(startPoint, endPoint, areaBrushDx, 4);
                              could it be
                              RenderTarget.VerticalLine(............?); What code do we use? you just cant plug in (
                              bar.ToString() + " \n 2.62
                              ) and a vertical line appear at bar 226

                              If i understand you must teach with a method how to find bar 226 in the chart. Its specific position x, y and than it can draw a vertical line.
                              Is there only a positioning for the bar? A code that tells you where is bar 226 and than you use rendertarget to draw the line?
                              Last edited by frankduc; 02-28-2019, 02:10 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              18 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Javierw.ok  
                              Started by timmbbo, Today, 08:59 AM
                              2 responses
                              10 views
                              0 likes
                              Last Post bltdavid  
                              Working...
                              X