Please se below the piece of code which compiles succesfully but gives the error in the Topic name
CODE:
Please log in to see this code.
Apparently the problem is in the "LastPosition.NetProfit".
Strangely enough (for my understanding) if I change the BuyAtLimit order with BuyAtMarket(bar) the code runs with no problems...
Since my intention is to be able to extract the strategy returns would it be posible to help me overcome that problem and give me some insight with respect to its causes?
Size:
Color:
Tenth "Object reference not set to an instance of an object" forum thread :)
The problem is both in trying to exit a Position that
may not exist yet (i.e. BuyAtLimit didn't trigger):
CODE:
Please log in to see this code.
AND
in accessing a property of the Position that
has already been exited:
CODE:
Please log in to see this code.
This is why there is a default single-position strategy template that protects from most coding errors of this kind.
Size:
Color:
A Strategy isn't the proper to place to extract the Strategy returns like this. Please re-read the Remarks section of the QuickRef entry for Position Object > NetProfitPercent.
Size:
Color:
Eugene,
First of all many thanks for the instant reply.
As per your last post I am fully aware of the "issues" with extracting strategy returns from a Strategy (but thanks anyway for the "warning")
I think that the first comment in your first reply helped me solve the problem. I used the following code
CODE:
Please log in to see this code.
Don't you think this is a non - problematic solution?
As per your second comment I really don't see that creating any problem most probably since this is not the last active position but the last position.
Size:
Color:
QUOTE:
As per your second comment I really don't see that creating any problem most probably since this is not the last active position but the last position.
It's not about Position order. The thing is, you
were accessing an .NET object that could have already been disposed, causing unhandled exception. In your code that followed, this is not an issue.
Size:
Color:
I see your point.
Thanks
Size:
Color: