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

Nasty bug trying to add() to a Dictionary...

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

    Nasty bug trying to add() to a Dictionary...

    Fellas, I need another set of eyeballs on this. I'm getting an "index out of range". I've checked for nulls where ever possible.

    The error says:
    "Error on triggering custom event for indicator AuctionGrid5: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

    This is somewhat intermittent.
    This for loop, this is where the exception get's thrown:

    foreach (double item in list)
    {
    string type = string.Empty;
    string thisVol = string.Empty;
    // --
    try
    {
    if (dList[item].price == GetCurrentBid())
    type = "Bid";
    else if (dList[item].price == GetCurrentAsk())
    type = "Ask";

    if (dList[item].price == Close[0])
    thisVol = dList[item].vol.ToString();

    }
    catch (Exception ex)
    {
    MyExceptionHandler(ex, "TheApp() - Trying to retrieve type.");
    }

    // EXCEPTION THROWN HERE...
    try
    {
    auctionRow = new String [] {
    dList[item].time.ToString(),
    dList[item].price.ToString(),
    type,
    thisVol,
    dList[item].cumVol.ToString(),
    dList[item].bidVol.ToString(),
    dList[item].askVol.ToString(),
    dList[item].totalVol.ToString()
    };
    if (aGrid.dg.Rows.Count > -1)
    idx = aGrid.dg.Rows.Add(auctionRow);
    //Print ("here "+idx.ToString());
    }
    catch (Exception ex)
    {
    MyExceptionHandler(ex, "TheApp() - adding row, returning idx.");
    }

    // NEED 'idx' FOR THIS CODE
    if (Close[0] == dList[item].price)
    {
    try
    {
    dgvr_auction = aGrid.dg.Rows[idx];
    dgvr_auction.DefaultCellStyle.BackColor = thisColor;
    dgvr_auction.DefaultCellStyle.Font = currentRowFont;
    dgvr_auction.DefaultCellStyle.ForeColor = Color.White;
    }
    catch (Exception ex)
    {
    MyExceptionHandler(ex, "TheApp() - trying to set current row color.");
    }

    }

    // remove blue hilite from first row/cell
    aGrid.dg.Rows[0].Cells[0].Selected = false;
    }
    Attached Files

    #2
    Try checking that dList[item] exists right before you start accessing those values.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I gotz

      Thanks Josh, it was in the dList[item] -> one of the values was not getting in and it was throwing that nasty, nasty error. That was brutal man!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by geotrades1, Today, 10:02 AM
      2 responses
      5 views
      0 likes
      Last Post geotrades1  
      Started by ender_wiggum, Today, 09:50 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by rajendrasubedi2023, Today, 09:50 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by bmartz, Today, 09:30 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by geddyisodin, Today, 05:20 AM
      4 responses
      28 views
      0 likes
      Last Post geddyisodin  
      Working...
      X