Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting value from OrderFlowCumulativeDelta

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

    Getting value from OrderFlowCumulativeDelta

    Hi I'm trying to get the 15second Delta value. I have the following code:

    HTML Code:
            else if (State == State.Configure)
            {
                    Calculate = Calculate.OnBarClose;
                    AddDataSeries("YM 03-23", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
                    AddDataSeries("YM 03-23", Data.BarsPeriodType.Second, 15, Data.MarketDataType.Last);
                    AddDataSeries("YM 03-23", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
                    AddDataSeries("YM 03-23", Data.BarsPeriodType.Volume, 1, Data.MarketDataType.Last);
            }
            else if (State == State.DataLoaded)
            {                
                    CumDelta1m = OrderFlowCumulativeDelta(BarsArray[1], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0);
                    CumDelta15s = OrderFlowCumulativeDelta(BarsArray[2], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0);
            }
    
            protected override void OnBarUpdate()
            {    ​
    
                            // obtain current 1m bar timestamp
                            DateTime currentBarTime = Bars.GetTime(Bars.Count-2);
    
                            if (delta > 100 || delta < -100){
    
                                // check if current candle's volume is greather than 3 previous candles
                                if(Volume[0] > Volume[1] && Volume[0] > Volume[2] && Volume[0] > Volume[3]){
    
                                    double maxPrice = double.MinValue;
                                    double minPrice = double.MaxValue;                    
                                    DateTime futureTime = currentBarTime;
                                    DateTime correctTime = futureTime;
    
                                    int count = 3;
                                    bool  found = false;
    
                                    for (int i = 0; i < 4; i++){
    
    
                                        // we only take the first delta of 15s chart
                                        if(!found){
                                            double delta15s = CumDelta15s.DeltaClose[0];
    
                                            if (delta15s > 60 || delta15s < -60){
                                                double highPrice = Highs[2][count];
                                                double lowPrice = Lows[2][count];
    
                                                // Update max and min price if necessary
                                                if (highPrice > maxPrice)
                                                    maxPrice = highPrice;
                                                    futureTime = futureTime.AddSeconds(15);
                                                    // we save at correctTime variable the candle timestamp where the max is located
                                                    correctTime = futureTime;
                                                if (lowPrice < minPrice)
                                                    minPrice = lowPrice;
                                                    //futureTime = futureTime.AddSeconds(15);
                                                    correctTime = futureTime;
    
                                                found = true;
                                            }
    
                                            count--;
                                            //futureTime = futureTime.AddSeconds(15);
                                        }
                                    }
    
                                    // If a 15s candle with delta > 60 or delta < -60 was found, we save the variables on an array
                                    if (maxPrice != double.MinValue && minPrice != double.MaxValue){
                                        // Save values to an array
                                        priceRange = new double[] { maxPrice, minPrice, -1};
                                        Print(string.Format("{0} --> MAX price: {1}, MIN price: {2}", correctTime, priceRange[0], priceRange[1]));
                                        myCurrentBar = CurrentBar;
    
                                        // Tells when we have detected a new range
                                        just_after = true;
                                    }
    
                                    else{
                                        // If no 15 seconds candles with delta > 60 or delta < -60 was found, we save the MAX and MIN value of the 1 min array
                                        double highPrice = BarsArray[1].GetHigh(0); // Get highest price of 1 min candle
                                        double lowPrice = BarsArray[1].GetLow(0); // Get lowest price of 1 min candle
    
                                        // Save LOW and High values into an array
                                        priceRange = new double[] {highPrice, lowPrice, -1};
                                        Print(string.Format("{0} --> MAX price: {1}, MIN price: {2}", correctTime, priceRange[0], priceRange[1]));
                                        myCurrentBar = CurrentBar;
                                        just_after = true;
                                    }
                                }
                            }​
    
    ​
    So the thing is that when a Delta bigger than 100 or lower than -100 is found. I want to check th 4 15sec candles inside this 1m candle and check for their Delta value. Then I want to save on a variable , the high and low range of the first 15sec candle that its delta is bigger than 60 or lower than -60.

    How can that be implemented following my code?

    Thanks

    #2
    Hello speedytrade02,

    Using BarsArray[2] for the input series is correct.

    You will also need to call .Update() during BarsInProgress 3 for each tick as demonstrated in the sample code in the help guide.


    That said, are you certain you want the logic in OnBarUpdate() to update for every series? (There is check for BarsInProgress in your code)
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    633 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    567 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X