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 sjsj2732, Yesterday, 04:31 AM
      0 responses
      35 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      287 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      286 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      133 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      95 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X