I am backtesting on 1min historic data, with CalculateOnBarClose = true.
My strategy generates multiple signals which I store in an ArrayList of IOrder objects.
All of my signals are of the type EnterLongStop() or EnterShortStop().
They all have a unique name (timestamp).
Each entry is preceded by a SetStopLoss() for the same unique name order name.
With this logic, my orders get filled and my stop-losses work just fine.
I cancel any OrderState = "Working" or OrderState = "Accepted" orders if they remain unfilled for more than three hours. This sets their OrderState to "Cancelled".
I'm stuck trying to identify the remaining orders that are not stopped out. The OrderState shows "Filled" regardless of whether the order is stopped out or not.
I thought about changing my logic to use ExitLongStop() and ExitShortStop() methods instead of SetStopLoss() and also pushing the returned IOrder objects into my ArrayList.
But then I have to program around waiting for the orders to be filled (might not be on the next 1min bar) before I can apply stops to them.
I would need to keep track of which stop price to apply to which entry order and then iterate over the ArrayList twice and try to join up the Stops with the Entries, which feels messy.
I'm pretty sure I'm making this more complicated than it needs to be.
Can anyone point me in the right direction?
Summary:
1. Backtesting OnBarClose
2. Multiple uniquely named entries, with a single unique stop per entry
3. Need to cancel old/unfilled orders, and handle orders being stopped out
4. Need to identify as time progresses which orders are still alive so that I can apply different take-profit logic to each trade individually.
I need the take profit rules to remain open-ended, as this is my focus of my development.
Thanks very much,
Kel.

Comment