Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add Volumetric data to a strategy

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

    Add Volumetric data to a strategy

    Hi all,

    Iam struggeling with adding volumetric data to a NT strategy. I used the AddVolumetric in state.configure, but somehow it doesnt get the data. I thing the issue is further below in the code where I call e.g. the MaxDelta with GetMaximumPositiveDelta.

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class DeltaEU : Strategy
    {
    private double DeltaBar {get;set;}
    private double MaxDelta {get;set;}
    private double MinDelta {get;set;}


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"DeltaEU";
    Name = "DeltaEU";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    AddVolumetric("FDAX 03-25", BarsPeriodType.Minute, 1, VolumetricDeltaType.BidAsk, 1);

    }

    else if (State == State.DataLoaded)
    {
    DeltaBar = BarDelta();
    MaxDelta = GetMaximumPositiveDelta();
    MinDelta = GetMaximumNegativeDelta();


    }
    }​

    #2
    I managed to resolve the above, but somehow it cannot apply indexing with I to an expression of type long.

    Code:
    private long BarDelta {get;set;}
    private long GetMaximumPositiveDelta {get;set;}
    private long GetMaximumNegativeDelta {get;set;}

    public long MaxDelta {get;set;}
    public long MinDelta {get;set;}

    ​if (BarDelta[0] > 0 && BarDelta[-1] > 0 && BarDelta[0] > BarDelta[-1] && BarDelta[0] > 0.5* MaxDelta[0])

    Comment


      #3
      Hello OrderflowTrading321,

      indexing or [0] only applies to items like collections or NinjaTrader series. Long is a single number not a series of numbers. You need to remove the [0] from those variables.

      Comment


        #4
        Originally posted by NinjaTrader_Jesse View Post
        Hello OrderflowTrading321,

        indexing or [0] only applies to items like collections or NinjaTrader series. Long is a single number not a series of numbers. You need to remove the [0] from those variables.
        Hi Jesse,

        I tried that, but I still get the same error. Might this be related to the Volumetric data? I added it under state.configure.

        Comment


          #5
          Helllo OrderflowTrading321,

          If you get the same error you are still using indexing on something that doesn't allow for it. You would have to simplify your code and find which specific part is having a problem.

          Comment


            #6
            I did some debugging and came up with the below, but somehow it shows me still the same error. I thing Iam missing some arrays to store the data, but Iam not 100% sure.

            Could you help?

            namespace NinjaTrader.NinjaScript.Strategies
            {
            public class DeltaEU : Strategy
            {


            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = @"DeltaEU";
            Name = "DeltaEU";
            Calculate = Calculate.OnBarClose;
            EntriesPerDirection = 1;
            EntryHandling = EntryHandling.AllEntries;
            IsExitOnSessionCloseStrategy = true;
            ExitOnSessionCloseSeconds = 30;
            IsFillLimitOnTouch = false;
            MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
            OrderFillResolution = OrderFillResolution.Standard;
            Slippage = 0;
            StartBehavior = StartBehavior.WaitUntilFlat;
            TimeInForce = TimeInForce.Gtc;
            TraceOrders = false;
            RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
            StopTargetHandling = StopTargetHandling.PerEntryExecution;
            BarsRequiredToTrade = 20;
            // Disable this property for performance gains in Strategy Analyzer optimizations
            // See the Help Guide for additional information
            IsInstantiatedOnEachOptimizationIteration = true;
            }
            else if (State == State.Configure)
            {
            AddVolumetric("FDAX 03-25", BarsPeriodType.Minute, 1, VolumetricDeltaType.BidAsk, 1);
            AddVolumetric("FDAX 03-25", BarsPeriodType.Tick, 1, VolumetricDeltaType.BidAsk, 1);
            }

            else if (State == State.DataLoaded)
            {



            }
            }

            protected override void OnBarUpdate()
            {
            NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;

            if (barsType == null)
            return;

            long Delta = barsType.Volumes[CurrentBar].BarDelta;
            long MaxDelta = barsType.Volumes[CurrentBar].GetMaximumPositiveDelta();
            long MinDelta = barsType.Volumes[CurrentBar].GetMaximumNegativeDelta();

            if (ToTime(Time[0]) >= 90500 && ToTime(Time[0]) < 110000);

            if (Delta > 0 && Delta[1] > 0 && Delta > Delta[1]​)
            Last edited by OrderflowTrading321; 02-27-2025, 08:56 AM.

            Comment


              #7
              Hello OrderflowTrading321,

              You are using CurrentBar and not CurrentBars, you need to specify the correct current bar for secondary series. You have two series so that would be CurrentBars[1] and CurrentBars[2]

              Comment


                #8
                Thanks for your quick reply, but Iam not sure if thats the issue. I removed the Tick dataseries so I only have the 1 Min data, but I get the same errors for the same line.

                if (Delta > 0 && Delta[1] > 0 && Delta > Delta[1]​)

                Do you might have another idea?

                Comment


                  #9
                  Hello OrderflowTrading321,

                  The code you had was not valid so that would be an issue still. CurrentBar singular with no s at the end refers to the series calling OnBarUpdate at that time, that's not the same as the secondary series. ou need to use CurrentBars[index] with an s at the end and indexing when using the multi series orderflow items.

                  Comment


                    #10
                    Hi Jesse,

                    Thanks! I understand, but might be there any example code on how to get the volumetric data into a strategy? I checked the NT guides a couple of times, but just cant find the solution on this.

                    Thanks in advance!

                    Comment


                      #11
                      Hello OrderflowTrading321,

                      You already found the sample you just need to use the right variables. If the primary series is a volumetric that is the only reason you use "CurrentBar" if you use the optional secondary series way of loading the data you need to use CurrentBars[indexOfSecondarySeries]" instead wherever CurrentBar was used.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NullPointStrategies, Today, 05:17 AM
                      0 responses
                      23 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      120 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      63 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      41 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      45 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X