Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object Reference Exception

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

    Object Reference Exception

    I am relatively new to C#/NT - would someone be kind enough to explain to me why this code runs fine:

    if (ioLEntryOrder != null && ioLEntryOrder.Token == execution.Order.Token)

    ioLStopLoss = ExitLongStop(0, true, 100, ioLEntryOrder.AvgFillPrice - 2 * dEntryATR, "StopLoss", "LongEntry");


    if (ioLEntryOrder != null && ioLEntryOrder.Token == execution.Order.Token)

    ioLEntryOrder2 = EnterLongStop(0, true, 100, ioLEntryOrder.AvgFillPrice + .5 * dEntryATR, "Entry2");


    but this code

    if (ioLEntryOrder != null && ioLEntryOrder.Token == execution.Order.Token)
    {
    ioLStopLoss = ExitLongStop(0, true, 100, ioLEntryOrder.AvgFillPrice - 2 * dEntryATR, "StopLoss", "LongEntry");

    ioLEntryOrder2 = EnterLongStop(0, true, 100, ioLEntryOrder.AvgFillPrice + .5 * dEntryATR, "Entry2");
    }

    generates "Error in calling the 'OnExecution' method for strategy "strat1": Object reference not set to an instance of an object. aren't these pieces of code really the same thing?

    Regards,

    Ben
    Last edited by Space123; 11-12-2009, 09:16 AM.

    #2
    Hi Ben, yes it looks like the needed '!= null' check is included in both cases, you would need to add prints to check which part exactly throws you the error in your code.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by sjsj2732, Yesterday, 04:31 AM
    0 responses
    33 views
    0 likes
    Last Post sjsj2732  
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    286 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    284 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
    91 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Working...
    X