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 above or below bar using volumetric bars data order flow chart of NT8.

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

    #31
    Originally posted by NinjaTrader_ChrisL View Post
    Hi, thanks for your reply.

    You can convert the barDelta value to a string using this:

    Code:
    //in the using statements:
    using System.Globalization;
    
    //OnBarUpdate:
    
    barsType.Volumes[CurrentBar].BarDelta.ToString(CultureInfo.InvariantCulture)
    Please let me know if this does not resolve your inquiry.
    That worked great, thank you very much.

    Is it possible to count the number of occurrences within a volumetric bar where the value exceeds a certain threshold? I've created an illustration of this and attached it.

    If this is possible are you able to point me to some resources in the reference or examples or anything like that?
    Attached Files

    Comment


      #32
      Hi, thanks for your reply.

      Unfortunately, I do not have a specific example that shows how to do this. It would take specific logic in the script to set up a counter for the number of occurrences a cell went above a certain level. The counter can be an integer set up at the class level, then you would check each bid/ask level on every tick and increment the counter every time it goes at or above the threshold. The methods used to get volume at a price are GetAskVolumeForPrice(double price) and GetBidVolumeForPrice(double price).

      Kind regards,
      -ChrisL
      Chris L.NinjaTrader Customer Service

      Comment


        #33
        Originally posted by NinjaTrader_ChrisL View Post
        Hi, thanks for your reply.

        Unfortunately, I do not have a specific example that shows how to do this. It would take specific logic in the script to set up a counter for the number of occurrences a cell went above a certain level. The counter can be an integer set up at the class level, then you would check each bid/ask level on every tick and increment the counter every time it goes at or above the threshold. The methods used to get volume at a price are GetAskVolumeForPrice(double price) and GetBidVolumeForPrice(double price).

        Kind regards,
        -ChrisL
        If the illustration I drew represents range volumetric bars, maybe I could loop through each range bar from high to low, and have one variable for each cell. Sum the volume being applied to each variable and then count the number of times a variable exceeds a threshold input. Reset the variables when the next bar starts.

        So an example of a use case would be: the user inputs a value of 2 into the threshold value. Then bars like the one in the illustration would have some sort of plot drawn on the chart above/below the bar.

        Does this sounds like something that is feasible to do in ninjascript?

        Edit: btw changed my name to this so it's more respectful to the community. Was butt_toast before.
        Last edited by WalterSkinner; 07-26-2021, 02:40 PM.

        Comment


          #34
          Hi Walter, thanks for your reply.

          That is absolutely possible to do in NinjaScript. The language is C# based so really anything is possible to calculate given the correct algorithm.

          Kind regards,
          -ChrisL
          Chris L.NinjaTrader Customer Service

          Comment


            #35
            Originally posted by NinjaTrader_ChrisL View Post
            Hi Walter, thanks for your reply.

            That is absolutely possible to do in NinjaScript. The language is C# based so really anything is possible to calculate given the correct algorithm.

            Kind regards,
            -ChrisL
            Great are you aware of anything in the language reference or maybe default indicators where a loop like this is used? Just so I can see what it looks like and how it's used.

            Comment


              #36
              Hi Walter, thanks for your reply.

              You can do a loop through all of the ticks of a bar like so:

              for(double i = Low[0]; i <= High[0]; i += TickSize)
              {
              Print(GetAskVolumeForPrice(i));
              Print(GetAskVolumeForPrice(i));
              }

              Using volumetric bars there will be a volume value at every tick level.

              Kind regards,
              -ChrisL
              Chris L.NinjaTrader Customer Service

              Comment


                #37
                Originally posted by NinjaTrader_ChrisL View Post
                Hi Walter, thanks for your reply.

                You can do a loop through all of the ticks of a bar like so:

                for(double i = Low[0]; i <= High[0]; i += TickSize)
                {
                Print(GetAskVolumeForPrice(i));
                Print(GetAskVolumeForPrice(i));
                }

                Using volumetric bars there will be a volume value at every tick level.

                Kind regards,
                -ChrisL
                Thank you so much that's very kind of you!

                Comment


                  #38
                  Originally posted by NinjaTrader_ChrisL View Post
                  Hi Walter, thanks for your reply.

                  You can do a loop through all of the ticks of a bar like so:

                  for(double i = Low[0]; i <= High[0]; i += TickSize)
                  {
                  Print(GetAskVolumeForPrice(i));
                  Print(GetAskVolumeForPrice(i));
                  }

                  Using volumetric bars there will be a volume value at every tick level.

                  Kind regards,
                  -ChrisL
                  I can print these values but I can't refer to the values outside of the loop.

                  Sorry for all the questions I'm new and am not used to working with loops and arrays.

                  I don't know if an array is the correct way to do this. I picked it because yesterday I got this working without a loop by creating a variable for each price's bid/ask volume. This was okay, but I wanted the code to be able to work on any size range bars not just the ten ticks I was using for this exercise. Because of this I am trying to find a way to create variables for each price level's bid and ask volume that doesn't involve me hard-coding the variables.

                  Here's the code that I've got working along with a screenshot of the printout showing that it works.

                  Do you have any idea how to go about referring to these values elsewhere in the code?

                  Code:
                  //loop through bar from low to high and store bid/ask volume at each price level
                  for(double i = Low[0]; i <= High[0]; i += TickSize)
                  {
                       //create ask volume array
                       double[,] priceAndAskVolume = new double[,]
                       {
                            {i,barsType.Volumes[CurrentBar].GetAskVolumeForPrice(i)}
                       };
                       //create bid volume array
                       double[,] priceAndBidVolume = new double[,]
                       {
                            {i,barsType.Volumes[CurrentBar].GetBidVolumeForPrice(i)}
                       };
                       Print(Time[0]);
                       Print("Price|AskVolume|BidVolume" + " | " + i + " | " + priceAndBidVolume[0,1] + " | " + priceAndAskVolume[0,1]);
                  }//end of loop
                  Attached Files

                  Comment


                    #39
                    Hi Walter, thanks for your reply.

                    First, please read this publicly available guide on the scope of variables in C#:

                    A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.


                    In the sample code posted, you are declaring the double array priceAndAskVolume within the for loop, so the scope is limited to that for loop, you must define that array either outside of the loop or at the class level. E.g.

                    OnBarUpdate:
                    Code:
                    List<double> myList = new List<double>();
                    
                    for(double i = Low[0]; i <= High[0]; i += TickSize)
                    {
                        myList.Add(i);
                    }
                    
                    foreach(double item in myList)
                    {
                        Print(item);
                    }
                    Note the list will be gone after OnBarUpdate is complete. You would need to define the list as a member of the indicator class to survive each OnBarUpdate call.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #40
                      Originally posted by NinjaTrader_ChrisL View Post
                      Hi Walter, thanks for your reply.

                      First, please read this publicly available guide on the scope of variables in C#:

                      A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.


                      In the sample code posted, you are declaring the double array priceAndAskVolume within the for loop, so the scope is limited to that for loop, you must define that array either outside of the loop or at the class level. E.g.

                      OnBarUpdate:
                      Code:
                      List<double> myList = new List<double>();
                      
                      for(double i = Low[0]; i <= High[0]; i += TickSize)
                      {
                      myList.Add(i);
                      }
                      
                      foreach(double item in myList)
                      {
                      Print(item);
                      }
                      Note the list will be gone after OnBarUpdate is complete. You would need to define the list as a member of the indicator class to survive each OnBarUpdate call.
                      Thanks man

                      Comment


                        #41
                        Hi Paul,

                        Would you be able to tell me what Ninjascript to write to display the total volume on a 5 minute chart per each bar above seller bars,
                        and below buyer bars?

                        Like this? Thanks!

                        Click image for larger version

Name:	volume.png
Views:	117
Size:	17.4 KB
ID:	1212922


                        Originally posted by NinjaTrader_PaulH View Post
                        Hello avrege,

                        Thanks for your reply.

                        As previously advised in post #2 you can print the bar statistics on the chart where you wish using Draw.Text().

                        Regarding plots of those values, you can create an indicator that reads the Volumetric bar statistics through ninjascript as previously linked in post #2 and plot using the addPlot(): https://ninjatrader.com/support/help...8/?addplot.htm

                        I've created an example script of both using draw.text and plotting the min/max seen delta, using a volumetric chart as the input:


                        Click image for larger version

Name:	avrege-1.PNG
Views:	1392
Size:	185.7 KB
ID:	1088215

                        Comment


                          #42
                          Hello Bob-Habanai,

                          Thanks for your note.

                          You could create a variable named something like 'myVolume' and save the current value of the VOL[0] (volume) indicator to that variable.

                          The Draw.Text() method could be used to draw the value of that variable above or below a bar.

                          For example, the code might look something like this:

                          Code:
                          //class level variable
                          private double myVolume;
                          
                          //OnBarUpdate
                          protected override void OnBarUpdate()
                          {
                              myVolume = VOL()[0];
                          
                              //if green bar, draw text 5 ticks above bar
                              if (Close[0] > Open[0])
                                  Draw.Text(this, "vol up bar" + CurrentBar, myVolume.ToString(), 0, High[0] + 5 * TickSize, Brushes.White);
                          
                              //if red bar, draw text 5 ticks below bar
                              if (Close[0] < Open[0])
                                  Draw.Text(this, "vol down bar" + CurrentBar, myVolume.ToString(), 0, Low[0] - 5 * TickSize, Brushes.White);
                          }
                          See the help guide documentation below for more information and sample code.

                          VOL: https://ninjatrader.com/support/help...nt8/volume.htm
                          Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm
                          PriceSeries: https://ninjatrader.com/support/help...riceseries.htm
                          TickSize: https://ninjatrader.com/support/help...t_ticksize.htm

                          Let me know if I may assist further.
                          Last edited by NinjaTrader_BrandonH; 08-24-2022, 07:42 AM.
                          Brandon H.NinjaTrader Customer Service

                          Comment


                            #43
                            Hi Brandon,

                            Thank you for your reply. It's much appreciated. I created a new indicator using Ninjascript editor and it generated this:

                            Code:
                            //This namespace holds Indicators in this folder and is required. Do not change it.
                            namespace NinjaTrader.NinjaScript.Indicators
                            {
                            public class Atest : Indicator
                            {
                            protected override void OnStateChange()
                            {
                            if (State == State.SetDefaults)
                            {
                            Description = @"Enter the description for your new custom Indicator here.";
                            Name = "Atest";
                            Calculate = Calculate.OnEachTick;
                            IsOverlay = false;
                            DisplayInDataBox = true;
                            DrawOnPricePanel = false;
                            DrawHorizontalGridLines = true;
                            DrawVerticalGridLines = true;
                            PaintPriceMarkers = false;
                            ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                            //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                            //See Help Guide for additional information.
                            IsSuspendedWhileInactive = true;
                            }
                            else if (State == State.Configure)
                            {
                            }
                            }
                            
                            protected override void OnBarUpdate()
                            {
                            //Add your custom indicator logic here.
                            }
                            }
                            }
                            I placed your code into the //Add your custom indicator logic here and got this:

                            Click image for larger version

Name:	code.png
Views:	107
Size:	645.1 KB
ID:	1213003

                            Any further advice would be helpful.

                            Thanks again!

                            Originally posted by NinjaTrader_BrandonH View Post
                            Hello Bob-Habanai,

                            Thanks for your note.

                            You could create a variable named something like 'myVolume' and save the current value of the VOL[0] (volume) indicator to that variable.

                            The Draw.Text() method could be used to draw the value of that variable above or below a bar.

                            For example, the code might look something like this:

                            Code:
                            //class level variable
                            private double myVolume;
                            
                            //OnBarUpdate
                            protected override void OnBarUpdate()
                            {
                            myVolume = VOL[0];
                            
                            //if green bar, draw text 5 ticks above bar
                            if (Close[0] > Open[0])
                            Draw.Text(this, "vol up bar" + CurrentBar, myVolume.ToString(), 0, High[0] + 5 * TickSize, Brushes.White);
                            
                            //if red bar, draw text 5 ticks below bar
                            if (Close[0] < Open[0])
                            Draw.Text(this, "vol down bar" + CurrentBar, myVolume.ToString(), 0, Low[0] - 5 * TickSize, Brushes.White);
                            }
                            See the help guide documentation below for more information and sample code.

                            VOL: https://ninjatrader.com/support/help...nt8/volume.htm
                            Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm
                            PriceSeries: https://ninjatrader.com/support/help...riceseries.htm
                            TickSize: https://ninjatrader.com/support/help...t_ticksize.htm

                            Let me know if I may assist further.

                            Comment


                              #44
                              Hello Bob-Habanai,

                              Thanks for your note.

                              I see that you copied and pasted the sample code I shared directly into the OnBarUpdate() method of a script. This sample code is simply an example of how to assign a value to a variable and draw that variable's value on a chart. It is not intended to be a copy and paste solution.

                              The 'myVolume' variable in the sample code I shared is a class-level variable. This means that it would need to be created at the class level and not within the OnBarUpdate() method.

                              //class level variable
                              private double myVolume;


                              Class-level variables are created after the public class <Indicator name> : Indicator method. They are not created in the OnBarUpdate() method.

                              Then I noted which part of the sample code does go into the OnBarUpdate() method.

                              //OnBarUpdate
                              protected override void OnBarUpdate()
                              {
                              ...insert OnBarUpdate() code here.

                              myVolume = VOL()[0];

                              //if green bar, draw text 5 ticks above bar if Close > Open
                              Draw.Text(this, "vol up bar" + CurrentBar, myVolume.ToString(), 0, High[0] + 5 * TickSize, Brushes.White);

                              ...more code here.
                              }


                              See the help guide documentation below for more information and sample code.

                              VOL: https://ninjatrader.com/support/help...nt8/volume.htm
                              Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm
                              PriceSeries: https://ninjatrader.com/support/help...riceseries.htm
                              TickSize: https://ninjatrader.com/support/help...t_ticksize.htm

                              Also, see the attached example script which demonstrates drawing the Volume above the up bars (green bars) on a chart. You could study this example script and program the rest of the script to draw the volume below down bars.

                              Let me know if I may assist further.
                              Attached Files
                              Brandon H.NinjaTrader Customer Service

                              Comment


                                #45
                                Thanks so much for that Brandon!

                                I was able to do the rest thanks to your help. I'm actually starting to understand much better now.
                                I did have a question. In "Draw.Text(this, "vol up bar" + CurrentBar, myVolume.ToString(), 0, High[0] + 5 * TickSize, Brushes.White);"

                                What if I wanted to add the previous bar's volume to the current bar. I tried
                                "Draw.Text(this, "vol up bar" + CurrentBar + PreviousBar, myVolume.ToString(), 0, High[0] + 5 * TickSize, Brushes.White);"

                                But I obviously haven't learnt the right way to write it yet.

                                Thank you very much for all your help!

                                Originally posted by NinjaTrader_BrandonH View Post
                                Hello Bob-Habanai,

                                Thanks for your note.

                                I see that you copied and pasted the sample code I shared directly into the OnBarUpdate() method of a script. This sample code is simply an example of how to assign a value to a variable and draw that variable's value on a chart. It is not intended to be a copy and paste solution.

                                The 'myVolume' variable in the sample code I shared is a class-level variable. This means that it would need to be created at the class level and not within the OnBarUpdate() method.

                                //class level variable
                                private double myVolume;


                                Class-level variables are created after the public class <Indicator name> : Indicator method. They are not created in the OnBarUpdate() method.

                                Then I noted which part of the sample code does go into the OnBarUpdate() method.

                                //OnBarUpdate
                                protected override void OnBarUpdate()
                                {
                                ...insert OnBarUpdate() code here.

                                myVolume = VOL()[0];

                                //if green bar, draw text 5 ticks above bar if Close > Open
                                Draw.Text(this, "vol up bar" + CurrentBar, myVolume.ToString(), 0, High[0] + 5 * TickSize, Brushes.White);

                                ...more code here.
                                }


                                See the help guide documentation below for more information and sample code.

                                VOL: https://ninjatrader.com/support/help...nt8/volume.htm
                                Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm
                                PriceSeries: https://ninjatrader.com/support/help...riceseries.htm
                                TickSize: https://ninjatrader.com/support/help...t_ticksize.htm

                                Also, see the attached example script which demonstrates drawing the Volume above the up bars (green bars) on a chart. You could study this example script and program the rest of the script to draw the volume below down bars.

                                Let me know if I may assist further.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by cocoescala, 10-12-2018, 11:02 PM
                                6 responses
                                939 views
                                0 likes
                                Last Post Jquiroz1975  
                                Started by gbourque, Today, 06:39 AM
                                1 response
                                4 views
                                0 likes
                                Last Post NinjaTrader_Erick  
                                Started by cmtjoancolmenero, Yesterday, 03:58 PM
                                1 response
                                17 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Started by benmarkal, Yesterday, 12:52 PM
                                3 responses
                                23 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Started by helpwanted, Today, 03:06 AM
                                1 response
                                20 views
                                0 likes
                                Last Post sarafuenonly123  
                                Working...
                                X