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

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 carnitron, Today, 08:42 PM
    0 responses
    5 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    7 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,974 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    8 views
    0 likes
    Last Post rbeckmann05  
    Started by rhyminkevin, Today, 04:58 PM
    4 responses
    58 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Working...
    X