Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with multiple instrument volumetric bars

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

    Help with multiple instrument volumetric bars

    Hi,

    I am trying to get values of delta on two different instruments using Volumetric bars - and the data seems to mismatch ( either its a bar behind - sometimes it repeats from the previous bar - and sometimes the number is completely different) attached is the code I am using :

    Code:
     else if (State == State.Configure)
    {
    if (Bars.BarsPeriod.BarsPeriodType == BarsPeriodType.Volumetric)
    {
    AddVolumetric(FirstInstrument,BarsPeriodType.Minut e,Bars.BarsPeriod.Value,VolumetricDeltaType.BidAsk ,1);
    AddVolumetric(SecondInstrument,BarsPeriodType.Minu te,Bars.BarsPeriod.Value,VolumetricDeltaType.BidAs k,1);
    }
    else
    {
    AddVolumetric(FirstInstrument,Bars.BarsPeriod.Bars PeriodType,Bars.BarsPeriod.Value,VolumetricDeltaTy pe.BidAsk,1);
    AddVolumetric(SecondInstrument,Bars.BarsPeriod.Bar sPeriodType,Bars.BarsPeriod.Value,VolumetricDeltaT ype.BidAsk,1);
    }
    }
    
    }
    
    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot || CurrentBars[2] <= BarsRequiredToPlot)
    return;
    
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType1 = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
    if (barsType1 == null) return;
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType2 = BarsArray[2].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
    if (barsType2 == null) return;
    
    double deltaMom1 = barsType1.Volumes[CurrentBars[1]].BarDelta;
    double deltaMom2 = barsType2.Volumes[CurrentBars[2]].BarDelta;
    
    if (BarsInProgress == 0 )
    {
    if (deltaMom2 >= 0 )
    {
    Draw.Text(this, "Delta1" + CurrentBar, true, deltaMom1.ToString() ,0, High[0] + 1 * TickSize ,0, Brushes.Orange,VolFont,TextAlignment.Center,Brushe s.Transparent,Brushes.Transparent,0);
    Draw.Text(this, "Delta2" + CurrentBar, true, deltaMom2.ToString() ,0, High[0] + 1.5 * TickSize ,0, Brushes.Orange,VolFont,TextAlignment.Center,Brushe s.Transparent,Brushes.Transparent,0);
    }
    if (deltaMom2 < 0)
    {
    Draw.Text(this, "Delta3" + CurrentBar, true, deltaMom1.ToString() ,0, Low[0] - 1 * TickSize ,0, Brushes.Orange,VolFont,TextAlignment.Center,Brushe s.Transparent,Brushes.Transparent,0);
    Draw.Text(this, "Delta4" + CurrentBar, true, deltaMom2.ToString() ,0, Low[0] - 1.5 * TickSize ,0, Brushes.Orange,VolFont,TextAlignment.Center,Brushe s.Transparent,Brushes.Transparent,0);
    }
    }
    }

    #2
    Hello pmallya.nt,

    Thank you for your post.

    Are you running this OnBarClose, OnPriceChange or OnEachTIck?

    I note you're not checking the values of the BarDeltas on the series that updates that particular instance of the indicator, so I would expect oddities for the second series. Is it just the secondary instrument series you see this behavior on?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Thanks Kate - I am running this OnBarClose - and having issues only with secondary instrument series.

      Comment


        #4
        Kate -

        What did you mean by "I note you're not checking the values of the BarDeltas on the series that updates that particular instance of the indicator,"
        How do I do that ?

        Regards

        Comment


          #5
          Hello pmallya.nt,

          Thank you for your reply.

          I've created a simple example script that illustrates. It's a little tricky with two different instruments, since the order in which they are processed will depend on which series gets a tick first, so if the second series updates first things get a little wonky.

          I'm seeing this print the correct values on each bar.

          Please let us know if we may be of further assistance to you.
          Attached Files

          Comment


            #6
            Kate,

            That's awesome !, Thanks for your help with this .

            Comment


              #7
              Kate -

              I noticed that if I put any conditions like the code snippet below the data goes out of synch again, can you please point me in the right direction.
              Thanks in advance.
              ​​​​​​​
              Code:
              else if (BarsInProgress == 2)
              {
              NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType2 = BarsArray[2].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
              if (barsType2 == null)
              return;
              
              deltaMom2 = barsType2.Volumes[CurrentBars[2]].BarDelta;
              //Print("Drawing for BIP 2 :" + deltaMom2 + " | CurrentBar: " + CurrentBar + " | Time: " + Times[2][0] + " | Primary time: " + Times[0][0]);
              if (Closes[0][0] > Opens[0][0] && deltaMom2 < 0)
              Draw.Text(this, "Delta4" + CurrentBars[2], true, deltaMom2.ToString(), Time[0], Highs[0][0] + 2.5 * TickSize, 0, Brushes.Cyan, ChartControl.Properties.LabelFont, TextAlignment.Center, Brushes.Gray, Brushes.Transparent, 0);
              if (Closes[0][0] < Opens[0][0] && deltaMom2 > 0)
              Draw.Text(this, "Delta4" + CurrentBars[2], true, deltaMom2.ToString(), Time[0], Lows[0][0] - 2.5 * TickSize, 0, Brushes.Cyan, ChartControl.Properties.LabelFont, TextAlignment.Center, Brushes.Gray, Brushes.Transparent, 0);
              
              }

              Comment


                #8
                Hello pmallya.nt,

                Thank you for your reply.

                This is occurring because in many cases, there may be a tick in the secondary series before there is a first tick of the new bar in the primary series you are referencing. If you uncomment that print statement you'll see that sometimes BIP 2 processes before BIP 0, which means it would use the values from the prior bar. There's not a guarantee of the order in which series of different instruments receive ticks will always be the primary series first, then the secondary series.

                Something you could do is to save the values returned to a variable on each bar, check that those variables are something other than 0, and when they all are > 0, then draw the text to the bar and reset the variables back to 0 - that would ensure all series have updated prior to drawing the text.

                Please let us know if we may be of further assistance to you.

                Comment

                Latest Posts

                Collapse

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