Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      152 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      89 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      131 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      127 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X