Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating ATR under State == State.Configure Block

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

    Calculating ATR under State == State.Configure Block

    Hi,

    1. I need to get ATR value on or before First call to OnBarUpdate

    For the same purpose i tried to use the BarsRequest, but is it not returning as expected. It always returns Null Bars.

    Please help how to get ATR even before or on first call of BarsRequest.

    2. Moreover wish to make a BarsType, and needs to take Value starting from 0 (Zero), but it is not allowed might be minimum range is set to 1. How can i modify that attribute?


    Code:
                        BarsRequest barsRequest = new BarsRequest(bars.Instrument, DateTime.Now.AddDays(-4), DateTime.Now.AddDays(-1));
                        barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 };
                        barsRequest.TradingHours = NinjaTrader.Data.TradingHours.Get("Default 24 x 7");
    
                        barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((retBars, errorCode, errorMessage) =>
                        {
                            Print("Error: " + errorCode.ToString());
    
                            if (errorCode != ErrorCode.NoError)
                                // Handle any errors in requesting bars here
                                return;
    
                            if(retBars.Bars == null)
                                Print("Null Bars");
                            else
                                Print("Bars are there");
    
                            Print(retBars.Bars.Count);
    
                            for (int i = 0; i < retBars.Bars.Count; i++)
                            {
                                // Output the bars
                                NinjaTrader.Code.Output.Process(string.Format("Time: {0} Open: {1} High: {2} Low: {3} Close: {4} Volume: {5}",
                                                                retBars.Bars.GetTime(i),
                                                                retBars.Bars.GetOpen(i),
                                                                retBars.Bars.GetHigh(i),
                                                                retBars.Bars.GetLow(i),
                                                                retBars.Bars.GetClose(i),
                                                                retBars.Bars.GetVolume(i)), PrintTo.OutputTab1);
                            }
    
                            Series<double> cls = new Series<double>(retBars.Bars, MaximumBarsLookBack.Infinite);
                            Indicators.ATR t = new Indicators.ATR();
                            double atrVal = t.ATR(cls, 100)[0];
    
                            Print("ATR: " + atrVal);
    
                        }));
    
                        barsRequest.Dispose();

    #2
    Hello raaxus,

    Unfortunately, supplying a bar series from a BarsRequest to an indicator as the input series is not supported. Any calculations with that data would have to be done in that script.

    Below are links to examples of BarsRequests.
    https://ninjatrader.com/support/foru...518#post742518
    https://ninjatrader.com/support/foru...208#post786208


    Also, below is a link to an example custom bar type.
    https://ninjatraderecosystem.com/use...nko-bartype-8/


    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      Is there any way to calculate the ATR on or before first call of OnBarUpdate?

      Please suggest.

      Thanks,

      Comment


        #4
        Hello raaxus,

        This could be achieved with a BarsRequest in State.DataLoaded / State.Historical but would require that you calculate the ATR in the script using custom logic without calling the ATR() indicator.
        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
        577 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X