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 LawrenHom, Today, 10:45 PM
      0 responses
      3 views
      0 likes
      Last Post LawrenHom  
      Started by love2code2trade, Yesterday, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Started by funk10101, Today, 09:43 PM
      0 responses
      7 views
      0 likes
      Last Post funk10101  
      Started by pkefal, 04-11-2024, 07:39 AM
      11 responses
      37 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Yesterday, 08:51 AM
      8 responses
      44 views
      0 likes
      Last Post bill2023  
      Working...
      X