How to work with events
How to work with events
20 Apr 2021, 12:16
Hi guys,
Sorry but it is really not clear to me how I am supposed to make something work with the events.
I keep trying, but ... now I have issues with the Positions.Closed and PendingOrders.Cancelled events.
Let's say I want to create a class that will raise an event when all Positions are closed.
Quoting the documentation:
- Positions.Closed event "occurs each time a position is closed"
- Positions.Count returns the total number of open positions
So I thought : Ok, I can listen to this event, check if Positions.Count == 0, then raise my event.
The thing is that I can't because even if the event has been raised, the Positions collection (which is supposed to contain only opened positions) still contains the Position that is passed in the PositionClosedEventArgs.
Sounds like a bug to me, but if there is something logic behind this, please explain it to me, because I can't think of any ways to work with the events.
Thanks !
Replies
JerryTrader
21 Apr 2021, 11:37
RE:
Ok, the problem is not the event themselves, it was in my code, my bad !
I thought the issue came from the Positions collection because while debugging step by step, the debugger gave me weird values.
And I already noticed that sometimes, the debugger jumps instructions, and sometimes, some values are wrong, or even not computed, ending with a message like :
Cannot obtain value of local or argument as it is not available at this instruction pointer, possibly because it has been optimized away.
I copied/pasted my class into the cBot project (and not my reusable DLL), and the debugger works fine, and helped to find what my issue was.
My guess is that when cTrader compiles the bot and its dependencies, it compiles it in Release mode, with optimization, which makes the step by step debugging almost impossible.
So, the real question of this thread is more :
How to debug with reusable DLLs ?
Is there a way to say to cTrader : do not optimize this DLL ?
I already tried setting my project properties and VS, like recommended in this post :
Is that supposed to work ? Is it because of the way cTrader compiles dependencies or am I missing some configuration ?
Thanks a lot for your help,
Cheers,
Jerry
@JerryTrader
PanagiotisCharalampous
20 Apr 2021, 12:44
Hi JerryTrader,
Can you please provide us with some code to reproduce this behavior?
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous