Could you please help me with a challenge?
Scenario background:
We have a strategy that uses multi-time frames of a single instrument (e.g. GBPUSD). This strategy executes very well during backtesting and optimisation in the Strategy Analyser.
The strategy is time dependent, looking to trade between certain hours.
I have a full subscription to Esignal and all necessary data is available.
I have code in our strategy that automatically tests to ensure that there are sufficient days to prime the inter-day indicator. I have copied it here:
[COLOR=blue][FONT="]protected[/FONT][/COLOR][COLOR=blue][FONT="]override[/FONT][/COLOR][COLOR=blue][FONT="]void[/FONT][/COLOR][COLOR=black][FONT="] Initialize()[/FONT][/COLOR]
[COLOR=black][FONT="] {[/FONT][/COLOR]
[COLOR=black][FONT="] ClearOutputWindow();[/FONT][/COLOR]
[COLOR=black][FONT="] Add(PeriodType.Minute, [/FONT][/COLOR][COLOR=purple][FONT="]1440[/FONT][/COLOR][COLOR=black][FONT="]);[/FONT][/COLOR]
[COLOR=black][FONT="] Add(PeriodType.Minute, [/FONT][/COLOR][COLOR=purple][FONT="]15[/FONT][/COLOR][COLOR=black][FONT="]);[/FONT][/COLOR]
[COLOR=black][FONT="] TraceOrders = [/FONT][/COLOR][COLOR=blue][FONT="]true[/FONT][/COLOR][COLOR=black][FONT="];[/FONT][/COLOR]
[COLOR=black][FONT="] CalculateOnBarClose = [/FONT][/COLOR][COLOR=blue][FONT="]true[/FONT][/COLOR][COLOR=black][FONT="];[/FONT][/COLOR]
[COLOR=black][FONT="] AccountSize = [/FONT][/COLOR][COLOR=purple][FONT="]10000[/FONT][/COLOR][COLOR=black][FONT="];[/FONT][/COLOR]
[COLOR=black][FONT="] }[/FONT][/COLOR]
[COLOR=gray][FONT="]///[/FONT][/COLOR][COLOR=gray][FONT="]<summary>[/FONT][/COLOR]
[COLOR=gray][FONT="]///[/FONT][/COLOR][COLOR=green][FONT="] Called on each bar update event.[/FONT][/COLOR]
[COLOR=gray][FONT="]///[/FONT][/COLOR][COLOR=gray][FONT="]</summary>[/FONT][/COLOR]
[COLOR=blue][FONT="]protected[/FONT][/COLOR][COLOR=blue][FONT="]override[/FONT][/COLOR][COLOR=blue][FONT="]void[/FONT][/COLOR][COLOR=black][FONT="] OnBarUpdate()[/FONT][/COLOR]
[COLOR=black][FONT="] {[/FONT][/COLOR]
[COLOR=black][FONT="] Print([/FONT][/COLOR][COLOR=maroon][FONT="]"@ line 98"[/FONT][/COLOR][COLOR=black][FONT="]);[/FONT][/COLOR]
[COLOR=blue][FONT="]if[/FONT][/COLOR][COLOR=black][FONT="] (BarsInProgress == [/FONT][/COLOR][COLOR=purple][FONT="]1[/FONT][/COLOR][COLOR=black][FONT="])[/FONT][/COLOR]
[COLOR=black][FONT="] {[/FONT][/COLOR]
[COLOR=green][FONT="]// Recalcuate ATR but do nothing else[/FONT][/COLOR]
[COLOR=black][FONT="] Print([/FONT][/COLOR][COLOR=maroon][FONT="]"@ line 89"[/FONT][/COLOR][COLOR=black][FONT="]);[/FONT][/COLOR]
[COLOR=blue][FONT="]if[/FONT][/COLOR][COLOR=black][FONT="] (CurrentBar < [/FONT][/COLOR][COLOR=purple][FONT="]14[/FONT][/COLOR][COLOR=black][FONT="]){[/FONT][/COLOR]
[COLOR=black][FONT="] Print([/FONT][/COLOR][COLOR=maroon][FONT="]"@ line 93"[/FONT][/COLOR][COLOR=black][FONT="]);[/FONT][/COLOR]
[COLOR=green][FONT="]//Print(BarsArray[1].Count);[/FONT][/COLOR]
[COLOR=blue][FONT="]return[/FONT][/COLOR][COLOR=black][FONT="];[/FONT][/COLOR]
[COLOR=black][FONT="] }[/FONT][/COLOR]
[COLOR=black][FONT="] dATR = ATR([/FONT][/COLOR][COLOR=purple][FONT="]14[/FONT][/COLOR][COLOR=black][FONT="])[[/FONT][/COLOR][COLOR=purple][FONT="]1[/FONT][/COLOR][COLOR=black][FONT="]];[/FONT][/COLOR]
[COLOR=black][FONT="] Print([/FONT][/COLOR][COLOR=maroon][FONT="]"Current dATR = "[/FONT][/COLOR][COLOR=black][FONT="]+dATR);[/FONT][/COLOR]
[COLOR=black][FONT="] trade_counter = [/FONT][/COLOR][COLOR=purple][FONT="]0[/FONT][/COLOR][COLOR=black][FONT="]; [/FONT][/COLOR][COLOR=green][FONT="]// Reset the trade counter to 0 as no trade taken today[/FONT][/COLOR]
[COLOR=black][FONT="] dEMA = EMA(Typical, [/FONT][/COLOR][COLOR=purple][FONT="]14[/FONT][/COLOR][COLOR=black][FONT="])[[/FONT][/COLOR][COLOR=purple][FONT="]1[/FONT][/COLOR][COLOR=black][FONT="]];[/FONT][/COLOR]
[COLOR=black][FONT="] }[/FONT][/COLOR]
The strategy does not execute in real time. No error messages are found in the log (Control Centre). Suggestions other than putting out large chucks of code would be greatly appreciated. There are now over a 1000 lines of code attached to this strategy in distributed classes.
Testing completed to date:
I have adapted the standard SampleMACrossOver to include some print statements looking for execution. This runs as one would expect, executing trades until it arrives at the most recent data.
I apply my strategy in the same way (Control Centre -> Strategies -> New Strategy).
Test scenario 1:
I set the required days to 1.
The inserted print statements for debugging purposes execute as expected. (PDF screen shots emailed to support [at] ninjatrader.com referring to this thread). It gets through the 14 days required to prime the EMA indicator. I have also put debugging Print statements in the onbarupdate() function to ensure it is running. It appears to be doing so.
Test scenario 2:
I set the required days to 40 to ensure trades are taken to validate the strategy is executing. However, no output is put into the output window. (See PDF)
Lesson learned (for myself and those coming across this post):
As part of your development / unit testing cycle make sure you always apply the strategy in “live mode” to ensure it works.
Thanks and regards,
Dan

Comment