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

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 PaulMohn, Today, 09:12 AM
        2 responses
        8 views
        0 likes
        Last Post PaulMohn  
        Started by ETFVoyageur, Today, 05:50 AM
        5 responses
        36 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by thumper57, 05-11-2024, 04:30 PM
        13 responses
        39 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by llanqui, Yesterday, 10:29 AM
        2 responses
        15 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by llanqui, Yesterday, 11:10 AM
        2 responses
        22 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Working...
        X