PDA

View Full Version : Adding Timeframe removes all trades


ArjanV
04-23-2010, 03:18 AM
Hello All,

Just adding another timeframe to my strategy removes all my existing trades, without even doing anything with the added timeframe data.

I started with a simple strategy that buys on stochastics lows en sells on stochastics highs on a 1 minute chart. Very simple and works fine. I use a stop entry, then enter with 3 trades, use profittargets for the first two trades and a trailing stop for the last trade.

I clearly see all trades visualised in my 1 minute chart and these are confirmed by printing the the total trades value in the output window.

Now here is the strange thing: I would like to add a 5 minute timeframe to this strategy and only enter a trade when the stochastics in both timeframes point in the same direction. But just adding this 5 minute timeframe in the Initialize method, (so without doing anything with the data in this new barsarray), removes ALL of my existing trades! This is also confirmed in my output window saying my strategy has generated 0 trades, where previously there where more than a hundred.
Removing the line "Add(PeriodType.Minute, 5);" is enough to get the strategy working properly again.

What am I doing wrong? Would just adding a second timeframe mean that the conditions for a trade on the first timeframe (in array 0) change somehow?

I work in simulation mode, with a simulated data feed and with calculateonbarclose=true. I have this problem both in backtesting and in live simulation testing.

Thanks in advance for helping me out on this.

NinjaTrader_Bertrand
04-23-2010, 04:26 AM
Welcome to our forums ArjanV, if you're using the added series in the code you should ensure it's not accidentially used as you're not working in correct BarsInProgress context as far as the OnBarUpdate() calls go. Try this in it to not process any events for the added, secondary series -

if (BarsInProgress != 0) return;

http://www.ninjatrader-support.com/HelpGuideV6/MultiTimeFrameInstruments.html

ArjanV
04-23-2010, 04:45 AM
Thanks for the quick reply Bertrand,

Adding this code to the onbarupdate method doesn't change the outcome. I carefully checked the code and there are no commands which use the added timeframe. I also already tried to :

1- explicitly get the stochastics data from the primary(0) timeframe by adding the barsarray[0] code to this indicator.

2- Only use the code when the primary timeframe updates by adding it in a "if barsinprogess == 0 " section.

Both solutions and yours do not change the outcome. In the end it just depends on the add timeframe line being in the initialize method. When it's there,the code doesn't work, when I remove it, it works again.

Another strange thing is that when I change the second timeframe from 5 minutes to 1 minute (i.e. the same as the primary timeframe [0]) the strategy starts working again. So just using any other timeframe than the one used in the primary timeframe kills the strategy. I really have no clue as to what is going on.

NinjaTrader_Bertrand
04-23-2010, 04:48 AM
You're welcome, could please post the snippet you use? You can wrap code tags around it to make it easier readable.

Also: any errors in the log tab as this occurs on your end?

Thanks

ArjanV
04-23-2010, 05:29 AM
Bertrand,

No errors in the Log tab. I have attached the code snippet. If you need the complete code, let me know.

Hope this helps.

ArjanV
04-23-2010, 05:43 AM
By the way, I am using Ninjatrader 7. Maybe this matters somehow.

NinjaTrader_Bertrand
04-23-2010, 05:53 AM
ArjanV, thanks see nothing 'standing out' so if you send me full code to run to support at ninjatrader dot com Attn Bertrand I would appreciate it.

andreneoh
05-14-2010, 12:50 AM
Hi Ray / ArjanV

Was this issue resolved eventually? I seem to have run into the same exact problem

Thanks

NinjaTrader_Bertrand
05-14-2010, 04:09 AM
andreneoh, welcome to our forums here - which NT version are you working on as this issue surfaces? Would you mind posting a snippet of how you've structured you're code along with a brief description what exactly happens?

Thanks

andreneoh
05-14-2010, 07:34 AM
Using NT7 because of multi-timeframe support.

I'm trying to exit trades on a shorter timeframe after having entered on a longer timeframe. So far, all the NT help seems to suggest using "Add(PeriodType)" to cast a second time series array.

I have also explicitly made sure that the secondary array is referenced properly through the use of BarsArray[1] or Opens[1][1] for eg during the exits.

Although my code compiles without syntax errors, I run into the problem of "Add(PeriodType)" causing my strategy to not effect any trades at all.

Thanks

NinjaTrader_Bertrand
05-14-2010, 07:40 AM
andreneoh, multitime frame support was added for indicators in NT7, however 65 already supports this in a strategy environment.

For your entries and exits, are specifically submitting them to the correct BIP index?

For example for a market order -

EnterLong(int barsInProgressIndex, int quantity, string signalName)

http://www.ninjatrader.com/support/helpGuides/nt7/enterlong.htm

andreneoh
05-16-2010, 08:31 PM
For your entries and exits, are specifically submitting them to the correct BIP index?

I have tried to specifically cast the entry order to the primary bars , and the exit order to the secondary bars but no dice. is there another setting?

eg,
EnterShort(0, "Quantity", "EntryName");
ExitShort (1, "ExitName", "EntryName");

NinjaTrader_Bertrand
05-17-2010, 04:25 AM
No, that should be sufficient, you can check for example into the SampleMultiTime / MultiInstrument strategies we ship per default with NT.

Any errors in the log you spot?

What kind of time frame are you adding and which min bars required setting are you using?

andreneoh
05-27-2010, 08:05 AM
Finally solved the above-mentioned issue. Apparently all I have to do is to ensure that NT Gui.Chart is declared properly. Without this declaration, Add(PeriodType) does not work for some reason.

Thanks