• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error using barsRequest.Request()

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

    Error using barsRequest.Request()

    I'm having trouble geting this code to work. The error says a null reference in the red line. But I can't seem to find what I'm missing. I'll explain what I'm doing in case that what I'm doing is also incorrect. I'm trying to get the past day info and then check for max and min values to define supports and resistances. I'm doing that with the request method from BarsRequest and then iterating the bars requested.

    Code:
    void limites(){
    
                //definir suelo i techo
                barsRequest = new BarsRequest(Cbi.Instrument.GetInstrument("ES 6-20"), DateTime.Now.AddDays(-1), DateTime.Now);
                // Parametrize your request.
                 barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 };
                  barsRequest.TradingHours = TradingHours.Get("Default 24 x 7");
                //debbug
                if(barsRequest==null){Print("no esta bien hecha la request de vars pasadas");}
                //request
    barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((bars, errorCode, errorMessage) =>
                {
                    Print("no hay error aqui");
                    if (errorCode != ErrorCode.NoError)
                    {
                        // Handle any errors in requesting bars here
                        NinjaTrader.Code.Output.Process(string.Format("Error on requesting bars: {0}, {1}",
                                                        errorCode, errorMessage), PrintTo.OutputTab1);
                        return;
                    }
                    //debbug
                     //Print("bars: " + bars.Bars.Count);
                    for (int i = 0; i < bars.Bars.Count; i++)
                    {    
                            if(bars.Bars.GetHigh(i)>techo){ //calculo techo con RANGO=X
                                techo=bars.Bars.GetHigh(i);
                            }
                            if(bars.Bars.GetLow(i)<suelo){  //calculo suelo con RANGO=X
                                suelo=bars.Bars.GetLow(i);
                            }
                    }
                }));
    
                Print("Techo definido en: " + techo + ", suelo definido en: " + suelo);
    
            }
    I'm also attaching a photo from the debbuger.

    #2
    Hello juanram,

    Below are links to working examples of BarsRequest you can use as a starting point.
    https://ninjatrader.com/support/foru...518#post742518
    https://ninjatrader.com/support/foru...208#post786208

    Is the barsRequest object null?

    Does the print you have added appear in the output window?
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Seeker of Alpha, 07-03-2020, 06:17 PM
    2 responses
    25 views
    0 likes
    Last Post NinjaTrader_EricB  
    Started by VCtrader, Today, 01:57 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by sdauteuil, Today, 12:16 PM
    0 responses
    5 views
    0 likes
    Last Post sdauteuil  
    Started by Dan_D_Trader, Yesterday, 03:29 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by asmmbillah, Today, 12:06 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X