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

Extract data from volumetric bars.

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

    Extract data from volumetric bars.

    Hello ninjatrader team

    I have looked at all the documentation published about it and I can not find a solution.
    My intention is to extract a series of data from the volumetric bars to make comparisons with custom values, using a script or indicator
    These are the three lower cells on the left side, when they represent a value, be compared with custom values or parameters, as well as with the three upper cells on the right side in a volumetric bar.
    indicated in the attached image.

    I have taken references in





    and also searches in the forum, and I have not found any way to extract the data.
    My question is: is there an example or some more specific documentation that says how to extract data from the volumetric bars to form a script or indicator oriented to this objective?

    thank you.

    #2
    Hello franki,

    While this information is not provided from the Volumetric bars themselves, you could build this in an indicator or strategy.

    The script is doing the equivalent of adding a 1 tick series and then using BarsArray[1].GetAsk() / .GetBid() to get the ask and bid that are stamped with the last data.

    I have an example named TnSVolume that does something similar and you may be able use this as a guide.
    http://ninjatrader.com/support/forum...265#post503265
    Last edited by NinjaTrader_ChelseaB; 11-28-2018, 01:45 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello again, I managed to get the data I needed through a script, now I try to mark sequences with this code
      Code:
          protected override void OnBarUpdate()
              {
      
                  if (BarsInProgress != 0)
      
      
                    if (Bars == null)
                            return;
                      NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = Bars.BarsSeries.BarsType as     
                      NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
                    if (barsType == null)
                      return;
      
                   if (  Open[1] > Close[1]
                                 && Position.MarketPosition == MarketPosition.Flat
                      && barsType.Volumes[CurrentBar].BarDelta > -250
                      && barsType.Volumes[CurrentBar].MinSeenDelta > -250
                      && barsType.Volumes[CurrentBar].MaxSeenDelta == -10
                      ||Open[2] > Close[2]
                              && Position.MarketPosition == MarketPosition.Flat
                      && barsType.Volumes[CurrentBar].BarDelta > -250
                      && barsType.Volumes[CurrentBar].MinSeenDelta > -250
                      && barsType.Volumes[CurrentBar].MaxSeenDelta == -10
                      ||Open[1] > Close[1]
                                && Position.MarketPosition == MarketPosition.Flat
                      && barsType.Volumes[CurrentBar].BarDelta > -250
                      && barsType.Volumes[CurrentBar].MinSeenDelta > -250
                      && barsType.Volumes[CurrentBar].MaxSeenDelta == -25
                      ||Open[2] > Close[2]
                              && Position.MarketPosition == MarketPosition.Flat
                      && barsType.Volumes[CurrentBar].BarDelta > -250
                      && barsType.Volumes[CurrentBar].MinSeenDelta > -250
                      && barsType.Volumes[CurrentBar].MaxSeenDelta == -25
                      || Open[1] > Close[1]
                              && Position.MarketPosition == MarketPosition.Flat
                      && barsType.Volumes[CurrentBar].BarDelta  == barsType.Volumes[CurrentBar].MinSeenDelta
                      && barsType.Volumes[CurrentBar].MaxSeenDelta == -10
                      || Open[2] > Close[2]
                              && Position.MarketPosition == MarketPosition.Flat
                      && barsType.Volumes[CurrentBar].BarDelta  == barsType.Volumes[CurrentBar].BarDelta 
                      && barsType.Volumes[CurrentBar].MaxSeenDelta == -10
                      ||Open[1] > Close[1]
                              && Position.MarketPosition == MarketPosition.Flat
                      && barsType.Volumes[CurrentBar].BarDelta  == barsType.Volumes[CurrentBar].MaxSeenDelta 
                      && barsType.Volumes[CurrentBar].MaxSeenDelta == -25
                      || Open[2] > Close[2]
                              && Position.MarketPosition == MarketPosition.Flat
                      && barsType.Volumes[CurrentBar].BarDelta  == barsType.Volumes[CurrentBar].MinSeenDelta
                      && barsType.Volumes[CurrentBar].MaxSeenDelta == -25)
                      {
      
                      if ( Open[0] < Close[0]
                          && Position.MarketPosition == MarketPosition.Flat
                          && barsType.Volumes[CurrentBar].BarDelta > 250
                          && barsType.Volumes[CurrentBar].MaxSeenDelta > 250
                          && barsType.Volumes[CurrentBar].MinSeenDelta == 10
                          || Open[0] < Close[0]
                          && Position.MarketPosition == MarketPosition.Flat
                          && barsType.Volumes[CurrentBar].BarDelta > 250
                          && barsType.Volumes[CurrentBar].MaxSeenDelta > 250
                          && barsType.Volumes[CurrentBar].MinSeenDelta == 25
                          || Open[0] < Close[0]
                          && Position.MarketPosition == MarketPosition.Flat
                          && barsType.Volumes[CurrentBar].BarDelta == barsType.Volumes[CurrentBar].GetMaximumPositiveDelta() 
                          && barsType.Volumes[CurrentBar].MinSeenDelta == 10
                          || Open[0] < Close[0]
                          && Position.MarketPosition == MarketPosition.Flat
                          && barsType.Volumes[CurrentBar].BarDelta ==  barsType.Volumes[CurrentBar].GetMaximumNegativeDelta() 
                          && barsType.Volumes[CurrentBar].MinSeenDelta == 25)
                          {
                              Draw.Ellipse(this, "MyEllipse" + CurrentBar, 1, Low[0] -3 * TickSize, -1, High[0] +3 * TickSize, Brushes.Green);
                          }
                      }
      it compiles well, but the script does not get enabled

      What am I doing wrong?
      Thank you!

      Comment


        #4
        Hello franki,

        Is the script an indicator or strategy?

        To confirm, when checking the Enabled checkbox for the strategy it immediately becomes disabled?

        Are there errors appearing in the Log tab of the Control Center?
        If so, what do these say.


        These are very specific conditions in the logic.

        Have you used prints to print all values for all variables and determined that the condition will evaluate as true?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello franki,

          Is the script an indicator or strategy?
          Hello ChelseaB
          It is a modified and functional strategy has been taken as a template in this forum. (Unmanaged template)

          Originally posted by NinjaTrader_ChelseaB View Post
          To confirm, when checking the Enabled checkbox for the strategy it immediately becomes disabled?
          just a couple of seconds, it goes from calculating .... to "disable" when pressing the button to apply
          Originally posted by NinjaTrader_ChelseaB View Post
          Are there errors appearing in the Log tab of the Control Center?
          If so, what do these say.

          These are very specific conditions in the logic.

          Have you used prints to print all values for all variables and determined that the condition will evaluate as true?
          http://ninjatrader.com/support/forum...979#post510979
          The code thrown by log and by the window ninjascript Output is as follows

          Code:
          Strategy 'VolumetricTracked': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index 
          with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a 
          value of 5 when there are only 4 bars on the chart
          Attached photograph of before adding bar code close [0]

          Sincerely I have no idea why this happens, I would greatly appreciate a solution as an example or reference documentation.
          Thank you.

          Comment


            #6
            Hello franki,

            With the error:
            "Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart"

            This message indicates an invalid index was used.

            As one example, calling Close[1] when CurrentBar is 0 (the very first bar) will cause this error.

            The reason for this is because there will not be a bar ago, essentially there is not enough data at bar 0 to calculate to look a bar ago.

            The script will start from the far left of the chart at the very beginning where the CurrentBar will equal 0 and then start working to the right, calling each bar for OnBarUpdate();

            In this specific example, it would be needed to wait for the second bar to be built (from all series if there are multiple series added), to ensure that you have enough data to call a index 1 bar ago.

            This is especially important when multiple series are added to a single script as the data for all series may not start at the same time.

            Below are public links to the help guide on CurrentBar and CurrentBars.
            http://ninjatrader.com/support/helpG...currentbar.htm
            https://ninjatrader.com/support/help...urrentbars.htm


            Also, below is a link to a 3rd party educational site on C# as a reference.
            See an IndexOutOfRangeException. An array element access that is not in range causes this.

            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CortexZenUSA, Today, 12:53 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Started by CortexZenUSA, Today, 12:46 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Started by usazencortex, Today, 12:43 AM
            0 responses
            5 views
            0 likes
            Last Post usazencortex  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            168 responses
            2,265 views
            0 likes
            Last Post sidlercom80  
            Started by Barry Milan, Yesterday, 10:35 PM
            3 responses
            12 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X