A common object-oriented programming error is not checking for null references on your object variables This will cause an “Object reference not set to an instance of an object” error.
You create a variable that holds an IOrder object
But in the OnBarUpdate() method you do not check if this variable as been assigned an IOrder object thus when trying to access object properties it fails and yields the “Object reference not set…” error since the variable is null.
This will generate an error because you cannot access the object or any of its properties yet. You must always check if an object variable is null before attempting to access the object.