Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Values from volumetric bars don't match

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

    Values from volumetric bars don't match

    "Hello, I have a script that prints the MaxPositiveDelta and MaxNegativeDelta for the last closed volumetric candle, but the values don't match those shown in the bar statistics grid.
    Can you help me?"

    using System;
    using NinjaTrader.Cbi;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.Strategies;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript.BarsTypes;

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class SimpleDeltaLogger : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Log Maximum Positive/Negative Delta for Last Closed Bar";
    Name = "SimpleDeltaLogger";
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 1)
    return;

    VolumetricBarsType barsType = Bars.BarsSeries.BarsType as VolumetricBarsType;

    if (barsType == null)
    return;

    Print("Bar: " + (CurrentBar - 1));
    Print("Maximum Positive Delta: " + barsType.Volumes[CurrentBar - 1].GetMaximumPositiveDelta());
    Print("Maximum Negative Delta: " + barsType.Volumes[CurrentBar - 1].GetMaximumNegativeDelta());
    }
    }
    }


    #2
    Hello PedroNunes,

    The last closed candle would be only CurrentBar, you are currently using CurrentBar - 1 which would be the bar before the last closed bar. I can see on my end the values are matching the chart for the 3rd bar from the right which would be 1 bar before the last closed bar.

    Comment


      #3
      Thank you for your fast response. I am using volumetric volume bars and the values still don't match.

      Comment


        #4
        Hello PedroNunes,

        The value you are printing should not match the most recent closed bar, you are printing the 1 bars ago value. Do you also have delta mode enabled by changing the chart style to delta? By default the bars don't show the delta.

        Comment


          #5
          I am sorry, my mistake. What I want to include in my strategy is the max. delta and min. delta for the entire closed bar (the ones from bar statistics). Is it possible to print that?

          Comment


            #6
            Hello PedroNunes,

            That is what you are printing in the code you provided but you are printing the 1 bars ago value. To print the current bars value you would need to use CurrentBar in that syntax and not CurrentBar - 1. The - 1 is subtracting 1 from the CurrentBar variable giving you 1 BarsAgo data.

            As long as you have the chart style set to Delta you should be able to see that print match the chart bars.

            Code:
            Print("Maximum Positive Delta: " + barsType.Volumes[CurrentBar].GetMaximumPositiveDelta());
            Print("Maximum Negative Delta: " + barsType.Volumes[CurrentBar].GetMaximumNegativeDelta());

            Comment


              #7
              Hello, here is a screenshot of what I want in my strategy.
              Thank you
              Attached Files

              Comment


                #8
                Ok, I think this is it:
                Print("Max seen delta (bar): "+barsType.Volumes[CurrentBar].MaxSeenDelta);
                Print("Min seen delta (bar): "+barsType.Volumes[CurrentBar].MinSeenDelta);​

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                53 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                130 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                70 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                44 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X