I am really struggling with the attached reversion-to-the-mean strategy/framework and I'm hoping that some of you can shed some light on the scenario...
Note that the strategy (IorderFadeLegInTwice) is a simple and generic framework (not to mention buggy) so you will probably get killed if you trade it live as-is...
The whole point of this exercise is actually to gain a better understanding of what commands to put where/how/when/why in the context of "Advanced Order Handling" rules using iOrder objects. Creating some sort of reference "master logic flow chart" for Advanced Order Handling rules would be a great idea as well.
i.e. cancelling/resetting objects to null when/where to do these commands OnOrderUpdate(IOrder order) and OnExecution(IExecution execution) etc.
As for the strategy, basically it fades price action as it spikes away from a user-defined SMA. Once the 1st limit order is filled, a second limit order is automatically placed at a user defined number # of pips away from the first entry as a "2nd leg" limit entry.
If price moves to the other side of the SMA any unfilled/pending limit order is cancelled and the strategy waits for another price spike away from the mean (the user-defined SMA).
The desired outcome of course is for price to retrace to the mean (the user-defined SMA), where our Target(s) (exit orders for one or both orders) reside. The target(s) updates each bar, following the SMA.
I usually place the 1st and 2nd Stop orders 50-100 pips away as protection in a 'black swan' price surge, other than that the goal is to exit at the SMA every time (win or loss the SMA is the target/exit price level for 99% of all trades).
- Try running a backtest on the Strategy (using the default settings) on a 1 or 5 minute ES contract with fill type set to liberal, entries per direction set to 2 and exit on close set to false. (Note that for this iteration of the program minBarsSinceLosingTradeClosed and violentSpi****TriggerMktOrder are not being used.)
You will see that there are three issues:
1. In trades where the 'second leg' gets filled, the second leg almost always exits BEFORE the first entry......(???) This makes no sense to me, especially since I have options/settings set to FIFO. The Target (Exit Limit) orders should both reside at the exact same price level and get filled pretty much simultaneously, especially if price action goes THRU the level where they exit orders are supposed to be sitting.
2. The "Long/Short filters" module which is supposed to prevent sequential losing long/long/long or short/short/short orders, is not working. Supposed to work like this: If most recent trade was a Long and it was a "losing trade", then next trade MUST be a Short. (It worked perfectly in a previous iteration where there was only leg as opposed to the current two legged version).
3. Other than the issues described above, the Strategy usually works "just fine" for a couple dozen trades and then I get the dreaded "Error on calling 'OnExecution' method for strategy" error. Presumably, the "null reset" is causing issues but I just can't figure out why or where else to put the Null Reset commands.
As an aside, I have had a hard time understanding exactly how to implement "catch blocks" to debug this error using the sample at:
(http://www.ninjatrader.com/support/f...ead.php?t=9825)
However, even if I could get the catch blocks to work properly, it would not help me understand the flow of the logic when using Advanced Order Handling withing the context of a Managed strategy...
I intend to try the Unmanaged Approach in the future but, for now i was hoping that there are other aspiring "Advanced Order Handling" level programmers who would be willing to chip in and resolve/explain/augment what I have posted here.
I have put a LOT of work into this (my programming skills are actually quite weak - having gleaned what I could from the samples and reading the forum posts and watching videos)
For the record, I think that this forum is actually quite amazing and I'm very excited to see what NT8 will bring to the table.
Anyway, here's to all of us learning how to be better coders !

Comment